Skip to content

Add DataFusionEngine.get_table_schema() and deprecate get_schema() - #73466

Merged
kaxil merged 2 commits into
apache:mainfrom
SZL741023:refactor_datafusion_engine_get_schema
Dec 1, 2026
Merged

kaxil merged 2 commits into
apache:mainfrom
SZL741023:refactor_datafusion_engine_get_schema

Conversation

@SZL741023

@SZL741023 SZL741023 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

DataFusionEngine.get_schema() returns a pre-formatted string. An agent's get_schema tool call needs JSON, so DataFusionToolset bypassed the engine and read the session context directly (a TODO left in #62850).

The two schema paths in common.ai also disagreed: the database-hook path produced comma-joined name type pairs, while the object-storage path embedded a raw Arrow schema repr, so one prompt could describe two tables in two different shapes.

What changed

  • New DataFusionEngine.get_table_schema() returns list[dict[str, str]] with name and type keys, the same name and shape as DbApiHook.get_table_schema() and IcebergHook.get_table_schema(). get_schema() keeps returning the Arrow schema string and now emits AirflowProviderDeprecationWarning.
  • LLMSQLQueryOperator and LLMSchemaCompareOperator format both schema paths with one shared helper.
  • DataFusionToolset.get_schema reads the columns through the engine instead of walking the session context itself, and hands them straight to build_schema_result(). This clears the TODO AIP-99: Add DataFusionToolset #62850 left behind; the tool's own behaviour, including the name_contains filter and the bounded summary, is unchanged.
  • Existing common.ai tests that mocked get_schema() with strings now mock get_table_schema(), and their prompt-text assertions expect the name type, ... format.

Backward compatibility

No breaking change. Released common.ai versions call get_schema() and interpolate the string into the prompt, so get_schema() keeps its return type and only warns. The common.sql changelog notes the deprecation. The common-sql bound in common.ai is marked # use next version, because common.ai now calls get_table_schema().

Tests

Run locally after rebasing on main:

  • pytest for common.ai operators/, toolsets/, utils/: 1962 passed, 5 skipped
  • pytest for common.sql datafusion/: 129 passed
  • prek run --from-ref upstream/main --stage pre-commit: 64 passed, 1 could not run: check-dependency-lower-bounds needs tomllib, and its cached hook env here is still Python 3.10. Run directly under 3.11 against both changed pyproject.toml files it reports no issues.
  • prek run mypy-providers --from-ref upstream/main: no issues found

Selective checks select the broader provider test suite; that is left to CI.

related: #62850


Was generative AI tooling used to co-author this PR?
  • Yes, Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

@boring-cyborg

boring-cyborg Bot commented Sep 21, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@henry3260
henry3260 self-requested a review September 21, 2026 17:07
@shahar1
shahar1 requested a review from kaxil September 23, 2026 20:16
@SZL741023
SZL741023 force-pushed the refactor_datafusion_engine_get_schema branch from 4eadfe1 to 9e1d908 Compare October 13, 2026 15:18
@kaxil
kaxil force-pushed the refactor_datafusion_engine_get_schema branch 2 times, most recently from 53f95b9 to f54933c Compare October 16, 2026 01:25
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Dec 1, 2026
get_schema() returned a pre-formatted string. An agent's get_schema tool
call needs JSON, so the DataFusion toolset bypassed the engine and read
the session context directly.

The two schema paths in common.ai also disagreed. The database hook
path produced comma-joined "name type" pairs. The object-storage path
produced a raw Arrow schema repr. One prompt could therefore describe
two tables in two different shapes.

Column metadata now matches DbApiHook.get_table_schema(), which
callers already know how to format. Direct callers of get_schema() must
now format the result themselves; the common.sql changelog shows how.

Signed-off-by: Neil Lin <kuang741023@gmail.com>
@kaxil
kaxil force-pushed the refactor_datafusion_engine_get_schema branch from f54933c to 72fb484 Compare December 1, 2026 00:26
@kaxil
kaxil enabled auto-merge (squash) December 1, 2026 01:16
get_schema() returning a list instead of a string broke callers that
upgrade common-sql alone: released common.ai versions interpolate the
string straight into the prompt. get_schema() keeps its string return
and warns, and the structured column metadata moves to a new
get_table_schema(), the name DbApiHook and IcebergHook already use for
the same list[dict[str, str]] shape.

Also spec the toolset's mock engine on DataFusionEngine and split the
long schema-compare f-string.
@kaxil kaxil removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Dec 1, 2026
@kaxil kaxil changed the title Return structured column metadata from DataFusionEngine.get_schema() Add DataFusionEngine.get_table_schema() and deprecate get_schema() Dec 1, 2026
@kaxil
kaxil merged commit 0443cc4 into apache:main Dec 1, 2026
206 of 208 checks passed
@boring-cyborg

boring-cyborg Bot commented Dec 1, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants