gopidesupavan commented on code in PR #64183:
URL: https://github.com/apache/airflow/pull/64183#discussion_r2983911753


##########
providers/common/sql/src/airflow/providers/common/sql/datafusion/engine.py:
##########
@@ -101,11 +101,22 @@ def _register_data_source_format(self, datasource_config: 
DataSourceConfig):
             datasource_config.table_name,
         )
 
-    def execute_query(self, query: str) -> dict[str, list[Any]]:
+    def execute_query(self, query: str, max_rows: int | None = None) -> 
dict[str, list[Any]]:
         """Execute a query and return the result as a dictionary."""
         try:
             self.log.info("Executing query: %s", query)
             df = self.session_context.sql(query)
+
+            if max_rows is not None:
+                row_count = df.count()
+                if row_count > max_rows:
+                    self.log.warning(
+                        "Query returned %s rows, exceeding max_rows (%s). 
Returning first %s rows.",
+                        row_count,
+                        max_rows,
+                        max_rows,
+                    )
+                df = df.limit(max_rows)
             return df.to_pydict()
         except Exception as e:
             raise QueryExecutionException(f"Error while executing query: {e}")

Review Comment:
   yeah good one :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to