kaxil commented on code in PR #73466:
URL: https://github.com/apache/airflow/pull/73466#discussion_r4065001772


##########
providers/common/sql/src/airflow/providers/common/sql/datafusion/engine.py:
##########
@@ -205,7 +205,12 @@ def _remove_none_values(params: dict[str, Any]) -> 
dict[str, Any]:
         """Filter out None values from the dictionary."""
         return {k: v for k, v in params.items() if v is not None}
 
-    def get_schema(self, table_name: str):
-        """Get the schema of a table."""
-        schema = str(self.session_context.table(table_name).schema())
-        return schema
+    def get_schema(self, table_name: str) -> list[dict[str, str]]:

Review Comment:
   The string return shipped already, in common-sql 2.0.3 and 2.1.1, and 
released common.ai 0.9.0 interpolates it straight into the prompt (`f"Columns: 
{object_storage_schema}"` in llm_sql.py:217 of that tag) with no upper bound on 
common-sql. The `# use next version` marker fixes the forward direction, but 
someone who upgrades only common-sql lands on `Columns: [{'name': 'cust_id', 
'type': 'Int64'}, ...]` in the system prompt and nothing warns them. Would you 
rather add `get_columns()` and deprecate `get_schema()`, keeping this additive? 
Otherwise it has to go out in a common-sql major, not a minor, and the 
changelog note is the only signal.



##########
providers/common/ai/tests/unit/common/ai/toolsets/test_datafusion.py:
##########
@@ -55,15 +55,8 @@ def _make_mock_engine(
     mock.session_context.catalog().schema().table_names.return_value = 
list(tables.keys())
     mock.session_context.table_exist.side_effect = lambda name: name in tables
 
-    fields = schema_fields or [("id", "Int64"), ("amount", "Float64")]
-    arrow_fields = []
-    for name, ftype in fields:
-        field = MagicMock()
-        field.name = name
-        field.type = ftype
-        arrow_fields.append(field)
-    for tname in tables:
-        mock.session_context.table(tname).schema.return_value = arrow_fields
+    fields = [{"name": n, "type": t} for n, t in schema_fields or [("id", 
"Int64"), ("amount", "Float64")]]
+    mock.get_schema.return_value = fields

Review Comment:
   `_make_mock_engine` builds a bare `MagicMock()`, so this stubs `get_schema` 
on an unspecced mock exactly when the toolset starts depending on that method's 
contract. Rename or resignature `DataFusionEngine.get_schema` and every test in 
this file stays green. `MagicMock(spec=DataFusionEngine)`, the way 
`_make_mock_datasource_config` right above already does it?



-- 
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