Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions dcs_core/integrations/databases/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,28 @@ def fetch_rows(
return rows, list(column_names)
else:
return rows, None

def fetch_sample_values_from_database(
self,
table_name: str,
column_names: list[str],
limit: int = 5,
) -> List[Tuple]:
"""
Fetch sample rows for specific columns from the given table.

:param table_name: The name of the table.
:param column_names: List of column names to fetch.
:param limit: Number of rows to fetch.
:return: List of row tuples.
"""
table_name = self.qualified_table_name(table_name)

if not column_names:
raise ValueError("At least one column name must be provided")

columns = ", ".join([self.quote_column(col) for col in column_names])
query = f"SELECT {columns} FROM {table_name} LIMIT {limit}"
result = self.connection.execute(text(query))
rows = result.fetchall()
return rows
15 changes: 15 additions & 0 deletions dcs_core/integrations/databases/sybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,21 @@ def fetch_rows(
else:
return rows, None

def fetch_sample_values_from_database(
self,
table_name: str,
column_names: list[str],
limit: int = 5,
) -> Tuple[List, Optional[List[str]]]:
table_name = self.qualified_table_name(table_name)
columns = ", ".join([self.quote_column(col) for col in column_names])
query = f"SELECT TOP {limit} {columns} FROM {table_name}"

cursor = self.connection.cursor()
cursor.execute(query)
rows = cursor.fetchmany(limit)
return rows

def convert_regex_to_sybase_pattern(self, regex_pattern: str) -> str:
"""
Convert a regex pattern into a Sybase-compatible LIKE pattern.
Expand Down
Loading