From a10d0ffcfd06d54cc12df132bb5368eac2577f4d Mon Sep 17 00:00:00 2001 From: Anshuman Tiwari Date: Fri, 26 Sep 2025 14:25:57 +0530 Subject: [PATCH 1/2] feat: add fetch_sample_values_from_database method --- dcs_core/integrations/databases/postgres.py | 25 +++++++++++++++++++++ dcs_core/integrations/databases/sybase.py | 15 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/dcs_core/integrations/databases/postgres.py b/dcs_core/integrations/databases/postgres.py index 2ba72b62..f096af26 100644 --- a/dcs_core/integrations/databases/postgres.py +++ b/dcs_core/integrations/databases/postgres.py @@ -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 diff --git a/dcs_core/integrations/databases/sybase.py b/dcs_core/integrations/databases/sybase.py index 1868a5c6..9fe2be2f 100644 --- a/dcs_core/integrations/databases/sybase.py +++ b/dcs_core/integrations/databases/sybase.py @@ -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. From 6a20b56495dbd945dc4e8d4d94d18af7dfe6a097 Mon Sep 17 00:00:00 2001 From: Anshuman Tiwari Date: Fri, 26 Sep 2025 14:38:39 +0530 Subject: [PATCH 2/2] fix: update fetch_rows method to enforce column name requirement and adjust return type --- dcs_core/integrations/databases/sybase.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dcs_core/integrations/databases/sybase.py b/dcs_core/integrations/databases/sybase.py index 9fe2be2f..7cf2aca5 100644 --- a/dcs_core/integrations/databases/sybase.py +++ b/dcs_core/integrations/databases/sybase.py @@ -608,11 +608,12 @@ def fetch_sample_values_from_database( table_name: str, column_names: list[str], limit: int = 5, - ) -> Tuple[List, Optional[List[str]]]: + ) -> list[Tuple]: 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 TOP {limit} {columns} FROM {table_name}" - cursor = self.connection.cursor() cursor.execute(query) rows = cursor.fetchmany(limit)