gopidesupavan opened a new pull request, #62793: URL: https://github.com/apache/airflow/pull/62793
closes: https://github.com/apache/airflow/issues/62734 Add a new operator for cross-system schema drift detection powered by LLM reasoning to the common.ai provider. LLMSchemaCompareOperator introspects schemas from multiple data sources (databases via DbApiHook, object storage via DataFusionEngine) and uses an LLM to identify mismatches that would break data loading. The LLM handles complex cross-system type mapping that simple equality checks miss (e.g., varchar(255) vs string, timestamp vs timestamptz). ``` from airflow.sdk import dag import datetime @dag def example_llm_schema_compare(): @task.llm_schema_compare( db_conn_ids=["postgres_default"], table_names=["customers", "secondory_customers"], llm_conn_id="llm_conn_id", model_id="google-gla:gemini-2.5-pro", ) def compare_postgres_customer_tables(ds=None): return "Identify schema mismatches that would break data loading between systems" compare_postgres_customer_tables() example_llm_schema_compare() ``` An example output view: ``` { "summary": "The schemas are not compatible. The target table 'secondory_customers' is missing the 'postal_code' column, and the 'address' column has a restrictive VARCHAR(255) type which can cause data truncation from the source TEXT type. Several other VARCHAR columns have different lengths but are compatible.", "compatible": false, "mismatches": [ { "column": "postal_code", "source": "customers", "target": "secondory_customers", "severity": "critical", "description": "The column 'postal_code' is missing in the target table 'secondory_customers'.", "source_type": "VARCHAR(20)", "target_type": "Column not found", "migration_query": "ALTER TABLE secondory_customers ADD COLUMN postal_code VARCHAR(20);", "suggested_action": "Add the 'postal_code' column to the target table." }, { "column": "address", "source": "customers", "target": "secondory_customers", "severity": "critical", "description": "The 'address' column type in the target is VARCHAR(255), which is more restrictive than the source type TEXT and can lead to data truncation.", "source_type": "TEXT", "target_type": "VARCHAR(255)", "migration_query": "ALTER TABLE secondory_customers ALTER COLUMN address TYPE TEXT;", "suggested_action": "Change the data type of the 'address' column in the target table to TEXT to match the source." }, { "column": "customer_name", "source": "customers", "target": "secondory_customers", "severity": "info", "description": "The VARCHAR length for 'customer_name' differs, but the target type is larger, so it is compatible.", "source_type": "VARCHAR(100)", "target_type": "VARCHAR(255)", "migration_query": "Provide migration query", "suggested_action": "No action required, but for consistency you may want to align the varchar lengths." }, { "column": "contact_name", "source": "customers", "target": "secondory_customers", "severity": "info", "description": "The VARCHAR length for 'contact_name' differs, but the target type is larger, so it is compatible.", "source_type": "VARCHAR(100)", "target_type": "VARCHAR(255)", "migration_query": "Provide migration query", "suggested_action": "No action required, but for consistency you may want to align the varchar lengths." }, { "column": "city", "source": "customers", "target": "secondory_customers", "severity": "info", "description": "The VARCHAR length for 'city' differs, but the target type is larger, so it is compatible.", "source_type": "VARCHAR(50)", "target_type": "VARCHAR(100)", "migration_query": "Provide migration query", "suggested_action": "No action required, but for consistency you may want to align the varchar lengths." }, { "column": "country", "source": "customers", "target": "secondory_customers", "severity": "info", "description": "The VARCHAR length for 'country' differs, but the target type is larger, so it is compatible.", "source_type": "VARCHAR(50)", "target_type": "VARCHAR(100)", "migration_query": "Provide migration query", "suggested_action": "No action required, but for consistency you may want to align the varchar lengths." } ] } ``` <!-- SPDX-License-Identifier: Apache-2.0 https://www.apache.org/licenses/LICENSE-2.0 --> <!-- Thank you for contributing! Please provide above a brief description of the changes made in this pull request. Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/ Please make sure that your code changes are covered with tests. And in case of new features or big changes remember to adjust the documentation. Feel free to ping (in general) for the review if you do not see reaction for a few days (72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications. In case of an existing issue, reference it using one of the following: * closes: #ISSUE * related: #ISSUE --> --- ##### Was generative AI tooling used to co-author this PR? <!-- If generative AI tooling has been used in the process of authoring this PR, please change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by". --> - [ ] Yes (please specify the tool below) <!-- Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) --> --- * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged. * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed. * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x). * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). -- 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]
