dbt-extra 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/CHANGELOG.md +15 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/PKG-INFO +1 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/compatibility.md +1 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/development/testing.md +8 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/partial-optimization.md +14 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/production-workflow.md +1 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/__init__.py +1 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/inspection.py +1 -1
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/projections.py +34 -2
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/session.py +18 -2
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/optimizer_cases.py +24 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_function_docs.py +11 -1
- dbt_extra-0.2.3/tests/sql/test_projection_pruning.py +170 -0
- dbt_extra-0.2.3/tests/sql/test_rewrite_session.py +91 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_spark_optimization.py +32 -1
- dbt_extra-0.2.3/tests/workflows/test_inspection_comments.py +91 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/.gitignore +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/CONTRIBUTING.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/LICENSE +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/README.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/SECURITY.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/assets/dbt-extra-mark-dark.svg +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/assets/dbt-extra-mark-mono.svg +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/assets/dbt-extra-mark.svg +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/concepts.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/development/architecture.drawio +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/development/architecture.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/development/architecture.png +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/getting-started.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/catalog-round-trip.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/existing-dbt-project.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/five-step-demo.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/inspection-and-optimization.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/metadata-enrichment.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/guides/source-optimizer-safety.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/index.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/logo.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/catalogs.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/cli.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/configuration.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/python-api.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/README.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/athena.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/audit.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/bigquery.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/databricks.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/duckdb.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/fabric.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/function_sources.json +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/postgres.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/redshift.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/snowflake.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/spark.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/trino.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/reference/sql-functions/tsql.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/docs/troubleshooting.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/.gitignore +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/README.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/dbt_project.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/extra_project.yaml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/macros/hash_relation_attributes.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/macros/nonnegative.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/macros/round_money.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/macros/rounded_total.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/macros/schema.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/macros/unique_combination.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/brz/brz.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/brz/brz_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/brz/brz_orders.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/brz/brz_payments.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/brz/sources.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/capabilities/capabilities.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/capabilities/gld_customer_attribute_hash.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/capabilities/gld_customer_cohorts.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/capabilities/gld_join_counts.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/capabilities/gld_macro_arguments.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/customer_profile.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/customer_revenue.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/gld.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/gld_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/gld_daily_sales.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/gld_orders.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/gld_payment_method_summary.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/macro_revenue.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/README.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_customer_leaderboard.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_customer_lifetime_value.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_customer_order_ranking.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_distinct_paying_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_high_value_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_boolean_normalization.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_constants.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_customer_profile.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_join_simplification.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_predicates.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_projections.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_schema_projection.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_optimizer_shared_subqueries.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/gld_payment_union.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/gld/optimization/optimization.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/schema.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/customer_details.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/orders.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/slv.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/slv_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/slv_orders.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/slv_payments.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/models/slv/stg_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/profiles.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/seeds/LICENSE +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/seeds/README.md +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/seeds/demo_raw_orders.csv +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/seeds/raw_customers.csv +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/seeds/raw_orders.csv +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/seeds/raw_payments.csv +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/snapshots/slv/customer_history.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/tests/demo_revenue_reconciliation.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/examples/jaffle_shop/tests/jaffle_shop_reconciliation.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/pyproject.toml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/scripts/audit_sql_functions.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/scripts/benchmark_inspection.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/scripts/collect_sql_function_sources.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/scripts/demo_review.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/scripts/generate_sql_function_docs.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/scripts/smoke_distribution.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/__main__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/analyzer.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/column_demand.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/dependencies.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/expansion.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/lineage.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/results.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/analysis/type_inference.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/cli.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/config.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/enrichment.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/errors.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/files/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/files/changes.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/files/output.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/files/paths.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/files/yaml.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/artifacts.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/discovery.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/model_sql.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/project.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/properties.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/property_edits.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/references.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/relations.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/resources.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/schema_evidence.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/project/selectors.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/contract.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/csv.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/export.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/import_.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/json.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/shorthand.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/xlsx/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/xlsx/layout.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/xlsx/reader.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/xlsx/styles.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/review/xlsx/writer.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/aliases.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/dialects.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/edits.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/athena.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/bigquery.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/databricks.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/duckdb.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/fabric.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/models.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/postgres.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/redshift.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/registry.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/snowflake.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/spark.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/trino.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/functions/tsql.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/identifiers.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/models.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/parser.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/qualification.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/renderer.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/engine.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/expressions.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/pipeline.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/query_boundaries.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/regions.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/rewrites/structural.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/safety.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/scopes.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/templates/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/templates/config_format.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/templates/expansion.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/templates/interpreter.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/templates/macros.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/sql/templates/syntax.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/validation.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/src/dbt_extra/workflow_results.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/analysis/test_dependencies.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/conftest.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/files/test_changes.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/files/test_yaml.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_customer_leaderboard.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_customer_lifetime_value.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_customer_order_ranking.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_distinct_paying_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_high_value_customers.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_boolean_normalization.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_constants.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_customer_profile.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_join_simplification.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_predicates.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_projections.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_schema_projection.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_optimizer_shared_subqueries.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization/gld_payment_union.sql +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/fixtures/optimization_inputs.yml +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/helpers.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/project/test_dialect_resolution.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/project/test_resources.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/review/test_workbook.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/semantics.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/__init__.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/helpers.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_athena.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_audit.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_bigquery.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_boundaries.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_databricks.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_duckdb.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_effect_safety.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_fabric.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_generator_review.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_native_inference.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_native_type_rules.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_postgres.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_redshift.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_registry.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_snowflake.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_spark.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_trino.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/functions/test_tsql.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_config_format.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_dialects.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_generated_optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_inspection_readability.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_jinja.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_jinja_execution.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_macros.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_optimizer_semantics.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_parser.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_partial_optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_postgres_optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_shorthand.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_source_optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_static_jinja.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/sql/test_template_context.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/synthetic.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/test_architecture.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/test_branding.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/test_documentation.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/test_logo.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/test_yaml_style.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_dbt.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_function_enrichment.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_inspection_compilation.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_inspection_destinations.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_inspection_optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_inspection_output.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_inspection_rules.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_metadata.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_optimization_examples.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_optimization_options.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_optimizer_dbt_execution.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_project_resolution.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_results.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/tests/workflows/test_synthetic_optimization.py +0 -0
- {dbt_extra-0.2.2 → dbt_extra-0.2.3}/uv.lock +0 -0
|
@@ -8,6 +8,19 @@ changes receive a version and an ISO 8601 release date when released.
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.2.3] - 2026-11-06
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Allow SQLGlot comment reattachment during round-trip validation while retaining
|
|
16
|
+
output-name/order and exact candidate AST comment-count checks
|
|
17
|
+
([#1](https://github.com/billybillysss/dbt-extra/issues/1)). This does not
|
|
18
|
+
guarantee lossless serializer comment handling or execution equivalence.
|
|
19
|
+
- Allow inspection to prune otherwise-safe, unused projections with ordinary
|
|
20
|
+
prose comments, preserving those comments on the enclosing SELECT. Source
|
|
21
|
+
rewriting defaults, directive/hint protection and expression-safety checks
|
|
22
|
+
remain unchanged.
|
|
23
|
+
|
|
11
24
|
## [0.2.2] - 2026-11-06
|
|
12
25
|
|
|
13
26
|
### Added
|
|
@@ -201,7 +214,8 @@ Initial release of **dbt-extra**.
|
|
|
201
214
|
- PyPI trusted publishing after CI on `v*` tags or manual dispatch, with
|
|
202
215
|
release-tag/package-version verification for tag runs.
|
|
203
216
|
|
|
204
|
-
[Unreleased]: https://github.com/billybillysss/dbt-extra/compare/v0.2.
|
|
217
|
+
[Unreleased]: https://github.com/billybillysss/dbt-extra/compare/v0.2.3...HEAD
|
|
218
|
+
[0.2.3]: https://github.com/billybillysss/dbt-extra/compare/v0.2.2...v0.2.3
|
|
205
219
|
[0.2.2]: https://github.com/billybillysss/dbt-extra/compare/v0.2.1...v0.2.2
|
|
206
220
|
[0.2.1]: https://github.com/billybillysss/dbt-extra/compare/v0.2.0...v0.2.1
|
|
207
221
|
[0.2.0]: https://github.com/billybillysss/dbt-extra/compare/v0.1.0...v0.2.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: dbt-extra
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Understand, optimize, and review dbt SQL locally, with Excel/CSV editing and SQL/YAML change previews
|
|
5
5
|
Project-URL: Repository, https://github.com/billybillysss/dbt-extra
|
|
6
6
|
Project-URL: Documentation, https://github.com/billybillysss/dbt-extra/blob/HEAD/docs/index.md
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
| Surface | Current contract |
|
|
6
6
|
| --- | --- |
|
|
7
|
-
| Package | `dbt-extra`, version `0.2.
|
|
7
|
+
| Package | `dbt-extra`, version `0.2.3`; distributed through PyPI, pre-1.0. Executable `extra`, Python namespace `dbt_extra`. Pin and test upgrades. |
|
|
8
8
|
| Python | Metadata requires 3.11+. CI targets 3.11 and 3.13 on Linux, plus 3.13 on Windows. Other Python/platform combinations are not thereby certified. |
|
|
9
9
|
| SQLGlot | Runtime dependency is `>=30.29.0`; the local function-gap catalog is checked against 30.29.0. Dialect availability does not establish warehouse execution support. |
|
|
10
10
|
| Tool settings | Optional `extra_project.yaml`, `version: 2`; no transformation authoring schema. |
|
|
@@ -86,6 +86,13 @@ It exercises rule interactions in source and inspection paths; positive controls
|
|
|
86
86
|
assert that rules actually apply, not just that unchanged SQL still executes.
|
|
87
87
|
This is reproducible generated coverage, not exhaustive fuzzing or a proof.
|
|
88
88
|
|
|
89
|
+
`tests/sql/test_rewrite_session.py` separates candidate AST comment preservation
|
|
90
|
+
from serializer attachment/fidelity, including aliases and expanded CTEs.
|
|
91
|
+
`tests/sql/test_projection_pruning.py` covers inspection-only prose relocation,
|
|
92
|
+
directive/effect barriers and duplicate/NULL-aware results. The shared commented
|
|
93
|
+
projection cases also run in the opt-in Spark lane, in both ANSI modes; skipped
|
|
94
|
+
Spark tests are not execution evidence.
|
|
95
|
+
|
|
89
96
|
`tests/sql/test_jinja_execution.py` compares against real Jinja rather than using
|
|
90
97
|
the production interpreter on both sides. The opt-in real dbt test below builds
|
|
91
98
|
eight temporary models before and after applying optimizer changes, in both macro
|
|
@@ -137,7 +144,7 @@ remote execution coverage. A configured CI lane is not a claim that it has passe
|
|
|
137
144
|
```sh
|
|
138
145
|
uv build
|
|
139
146
|
uv venv .venv-package-smoke
|
|
140
|
-
uv pip install --python .venv-package-smoke dist/dbt_extra-0.2.
|
|
147
|
+
uv pip install --python .venv-package-smoke dist/dbt_extra-0.2.3-py3-none-any.whl
|
|
141
148
|
```
|
|
142
149
|
|
|
143
150
|
Run the following with **that environment's Python**, not `uv run` (which would
|
|
@@ -78,6 +78,20 @@ Final whole-query output and round-trip checks still apply. Programming errors
|
|
|
78
78
|
are not caught indiscriminately; unrecoverable parse, dependency-cycle and
|
|
79
79
|
fixed-point failures retain the existing error contract.
|
|
80
80
|
|
|
81
|
+
Comment validation compares exact text and duplicate counts between the original
|
|
82
|
+
and candidate ASTs. Round-trip validation separately compares comment-free SQL
|
|
83
|
+
renderings, allowing SQLGlot to reattach ordinary comments around aliases or CTEs
|
|
84
|
+
([issue #1](https://github.com/billybillysss/dbt-extra/issues/1)). These checks do
|
|
85
|
+
not prove execution equivalence or guarantee that rendering and reparsing retain
|
|
86
|
+
every candidate comment; serializer comment fidelity is a separate concern.
|
|
87
|
+
|
|
88
|
+
Inspection may prune an unused, otherwise-discardable projection carrying
|
|
89
|
+
ordinary prose comments, moving those comments to its enclosing SELECT. Live
|
|
90
|
+
projection comments retain their attachment. Unrecognized comment syntax,
|
|
91
|
+
directive-like comments and optimizer hints remain protected, as do fallible,
|
|
92
|
+
volatile and unknown evaluations. Source rewriting does not enable this comment
|
|
93
|
+
relocation policy; its existing comment-based safety roots remain unchanged.
|
|
94
|
+
|
|
81
95
|
Inspection issues carry `resource_id`, `reason` and transformation fields. Project
|
|
82
96
|
optimization includes an `outcomes` list in each model's report.
|
|
83
97
|
`optimize_source()` returns SQL and can populate an optional `outcomes` list; see
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Production adoption checklist
|
|
2
2
|
|
|
3
3
|
This is an adoption checklist, not a production-readiness certification. dbt-extra is
|
|
4
|
-
currently 0.2.
|
|
4
|
+
currently 0.2.3. Validate its behavior on your data, dialect, adapter and deployment
|
|
5
5
|
environment before using it for a production workload.
|
|
6
6
|
|
|
7
7
|
## Reproducible review
|
|
@@ -80,7 +80,7 @@ def inspect(project, name, columns=None, *, boundaries=(), expanded=True, optimi
|
|
|
80
80
|
raise RejectedCandidate(str(exc)) from exc
|
|
81
81
|
|
|
82
82
|
checkpoints.attempt("qualification", bind, provides=("bindings",))
|
|
83
|
-
checkpoints.attempt("projection_pruning", lambda t: prune_projections(t, dialect=dialect), requires=("bindings",))
|
|
83
|
+
checkpoints.attempt("projection_pruning", lambda t: prune_projections(t, dialect=dialect, relocate_comments=True), requires=("bindings",))
|
|
84
84
|
apply_structural_rules(checkpoints, dialect, inspection=True)
|
|
85
85
|
checkpoints.attempt("query_boundary_simplification", lambda t: simplify_query_boundaries(t, dialect), requires=("bindings",))
|
|
86
86
|
checkpoints.attempt("literal_simplification", lambda t: simplify_source_expressions(t, dialect))
|
|
@@ -5,6 +5,8 @@ moved. Synthetic ORDER references exist solely in the analysis copy: they make
|
|
|
5
5
|
observable evaluations and authored alias bindings roots of the dependency graph.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import re
|
|
9
|
+
|
|
8
10
|
from sqlglot import exp
|
|
9
11
|
from sqlglot.optimizer.pushdown_projections import projection_reachability
|
|
10
12
|
|
|
@@ -40,7 +42,29 @@ def prune_source_projections(authored, expanded, qualified, *, dialect=None):
|
|
|
40
42
|
return result
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
def
|
|
45
|
+
def _discardable_projection(projection, dialect, relocate_comments):
|
|
46
|
+
if discardable(projection, dialect):
|
|
47
|
+
return True
|
|
48
|
+
if not relocate_comments:
|
|
49
|
+
return False
|
|
50
|
+
comments = [comment for node in projection.walk() for comment in node.comments or []]
|
|
51
|
+
# This is a bounded prose policy, not a general directive parser. Unknown
|
|
52
|
+
# syntax remains a safety root, as do hint nodes and unsafe evaluations.
|
|
53
|
+
if not comments or any(
|
|
54
|
+
not re.fullmatch(r"[A-Za-z][A-Za-z0-9 \t\r\n(),.'/-]*", comment.strip())
|
|
55
|
+
or any(marker in comment.casefold() for marker in ("sqlglot", "noqa", "nosec", "nosemgrep"))
|
|
56
|
+
for comment in comments
|
|
57
|
+
):
|
|
58
|
+
return False
|
|
59
|
+
clean = projection.copy()
|
|
60
|
+
for node in clean.walk():
|
|
61
|
+
node.pop_comments()
|
|
62
|
+
return discardable(clean, dialect)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def prune_projections(tree, *, authored=None, dialect=None, relocate_comments=False):
|
|
66
|
+
"""Optionally relocate dead projection prose for inspection, never authored SQL."""
|
|
67
|
+
relocate_comments = relocate_comments and authored is None
|
|
44
68
|
analysis = tree.copy()
|
|
45
69
|
queries = list(analysis.find_all(exp.Select))
|
|
46
70
|
sources = list((authored or tree).find_all(exp.Select))
|
|
@@ -61,7 +85,9 @@ def prune_projections(tree, *, authored=None, dialect=None):
|
|
|
61
85
|
if not isinstance(projection.unalias(), exp.Column):
|
|
62
86
|
aliases.update(c.name.casefold() for c in projection.find_all(exp.Column) if not c.table)
|
|
63
87
|
keep = [p.output_name for p, original in zip(query.selects, source.selects)
|
|
64
|
-
|
|
88
|
+
if not _discardable_projection(p, dialect, relocate_comments)
|
|
89
|
+
or not _discardable_projection(original, dialect, relocate_comments)
|
|
90
|
+
or original.output_name.casefold() in aliases]
|
|
65
91
|
keep += [c.name for key in ("qualify", "having") if query.args.get(key)
|
|
66
92
|
for c in query.args[key].find_all(exp.Column) if not c.table and c.name in names]
|
|
67
93
|
clauses = [source.args.get(k) for k in ("group", "order")]
|
|
@@ -97,5 +123,11 @@ def prune_projections(tree, *, authored=None, dialect=None):
|
|
|
97
123
|
prefix = max(ordinals, default=0)
|
|
98
124
|
kept = [p for i, (p, live) in enumerate(zip(target.selects, roots)) if live or i < prefix]
|
|
99
125
|
if kept:
|
|
126
|
+
if relocate_comments:
|
|
127
|
+
kept_ids = {id(projection) for projection in kept}
|
|
128
|
+
comments = [comment for projection in target.selects if id(projection) not in kept_ids
|
|
129
|
+
for node in projection.walk() for comment in node.comments or []]
|
|
130
|
+
if comments:
|
|
131
|
+
target.add_comments(comments)
|
|
100
132
|
target.set("expressions", kept)
|
|
101
133
|
return tree
|
|
@@ -101,11 +101,27 @@ def outcome_text(item):
|
|
|
101
101
|
return message + (f" ({count} occurrences)" if count > 1 else "")
|
|
102
102
|
|
|
103
103
|
|
|
104
|
+
def _comments(tree):
|
|
105
|
+
return sorted(comment for node in tree.walk() for comment in node.comments or [])
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _sql_without_comments(tree, dialect):
|
|
109
|
+
tree = tree.copy()
|
|
110
|
+
for node in tree.walk():
|
|
111
|
+
node.pop_comments()
|
|
112
|
+
return sql(tree, dialect)
|
|
113
|
+
|
|
114
|
+
|
|
104
115
|
def validate_contract(before, after, dialect):
|
|
116
|
+
"""Check candidate comments separately from executable render stability.
|
|
117
|
+
|
|
118
|
+
Comment attachment can change on reparse. This is neither an execution
|
|
119
|
+
equivalence proof nor a guarantee of lossless serializer comment handling.
|
|
120
|
+
"""
|
|
105
121
|
if output_contract(before) != output_contract(after):
|
|
106
122
|
raise RejectedCandidate("output names or order changed")
|
|
107
|
-
if
|
|
123
|
+
if _comments(before) != _comments(after):
|
|
108
124
|
raise RejectedCandidate("SQL comments would be discarded")
|
|
109
125
|
reparsed = read_query(sql(after, dialect), "optimized SQL", dialect)
|
|
110
|
-
if
|
|
126
|
+
if _sql_without_comments(reparsed, dialect) != _sql_without_comments(after, dialect):
|
|
111
127
|
raise RejectedCandidate("SQL did not round-trip")
|
|
@@ -27,6 +27,30 @@ RULE_NAMES = {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
|
|
30
|
+
# Small public fixtures for prose-bearing projections; the flag requires a
|
|
31
|
+
# positive pruning result, or deliberately protects a cardinality/dependency root.
|
|
32
|
+
COMMENT_PROJECTION_QUERIES = {
|
|
33
|
+
"subquery": ("SELECT q.id FROM (SELECT t.id, t.unused /* legacy timing columns */ AS unused FROM t) q", True),
|
|
34
|
+
"distinct": ("SELECT q.id FROM (SELECT DISTINCT t.id, t.unused /* legacy timing columns */ AS unused FROM t) q", False),
|
|
35
|
+
"ordinal_group": ("SELECT q.x FROM (SELECT t.id, t.x, t.unused /* legacy timing columns */ AS unused "
|
|
36
|
+
"FROM t GROUP BY 1,2,3 ORDER BY 2,1) q", False),
|
|
37
|
+
"ordinal_order": ("SELECT q.id FROM (SELECT t.id, t.x /* legacy timing columns */ AS x "
|
|
38
|
+
"FROM t ORDER BY 2,1 LIMIT 3) q ORDER BY q.id NULLS LAST", False),
|
|
39
|
+
"alias_order": ("SELECT q.id FROM (SELECT t.id, t.x /* legacy timing columns */ AS x "
|
|
40
|
+
"FROM t ORDER BY x NULLS LAST, id NULLS LAST LIMIT 3) q ORDER BY q.id NULLS LAST", False),
|
|
41
|
+
"grouped": ("SELECT q.id, q.n FROM (SELECT t.id, COUNT(*) AS n, t.id /* legacy timing columns */ AS unused "
|
|
42
|
+
"FROM t GROUP BY t.id) q", True),
|
|
43
|
+
"global": ("SELECT q.k FROM (SELECT 1 AS k, COUNT(*) AS n, 2 /* legacy timing columns */ AS unused FROM t) q", True),
|
|
44
|
+
"left_fanout": ("SELECT q.id FROM (SELECT a.id, b.unused /* legacy timing columns */ AS unused "
|
|
45
|
+
"FROM t a LEFT JOIN t b ON a.id=b.id) q", True),
|
|
46
|
+
"single_cte": ("WITH s AS (SELECT t.id, t.unused /* legacy timing columns */ AS unused FROM t) SELECT s.id FROM s", True),
|
|
47
|
+
"shared_cte": ("WITH s AS (SELECT t.id, t.x, t.unused /* legacy timing columns */ AS unused FROM t) "
|
|
48
|
+
"SELECT s.id FROM s WHERE s.x>0 UNION ALL SELECT s.id FROM s WHERE s.x IS NULL", True),
|
|
49
|
+
"shared_live": ("WITH s AS (SELECT t.id, t.unused /* legacy timing columns */ AS unused FROM t) "
|
|
50
|
+
"SELECT s.id FROM s UNION ALL SELECT s.unused AS id FROM s", False),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
30
54
|
def assert_rule_exercised(rule, candidate, dialect, outcomes):
|
|
31
55
|
tree = parse_one(candidate, read=dialect)
|
|
32
56
|
if rule == "membership" and dialect not in {"duckdb", "spark"}:
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
import json
|
|
5
|
+
import re
|
|
5
6
|
import runpy
|
|
6
7
|
|
|
7
8
|
import pytest
|
|
@@ -81,7 +82,16 @@ def test_ownership_includes_unsupported_names_without_inheriting_related_catalog
|
|
|
81
82
|
|
|
82
83
|
def test_matrix_documentation_is_current_and_has_all_dialect_headers():
|
|
83
84
|
text = (GENERATOR["DOCS"] / "README.md").read_text(encoding="utf-8")
|
|
84
|
-
|
|
85
|
+
# Fresh-dependency package tests may use a newer SQLGlot than the snapshot.
|
|
86
|
+
# Ignore only its generation-version label, not changes to the inventory.
|
|
87
|
+
version = re.search(r"Generated against \*\*SQLGlot ([^*]+)\*\*", text)
|
|
88
|
+
assert version is not None
|
|
89
|
+
expected = text.replace(
|
|
90
|
+
version[0],
|
|
91
|
+
f"Generated against **SQLGlot {GENERATOR['sqlglot'].__version__}**",
|
|
92
|
+
1,
|
|
93
|
+
)
|
|
94
|
+
assert GENERATOR["document"]("README", text) == expected
|
|
85
95
|
block = text.split(GENERATOR["START"])[1]
|
|
86
96
|
assert "| SQL function |" in block
|
|
87
97
|
assert all(f"[{label}]({dialect}.md)" in block
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Inspection-only prose relocation must not expand expression safety proofs."""
|
|
2
|
+
|
|
3
|
+
from collections import Counter
|
|
4
|
+
|
|
5
|
+
import duckdb
|
|
6
|
+
import pytest
|
|
7
|
+
from sqlglot import exp, parse_one
|
|
8
|
+
|
|
9
|
+
from dbt_extra.sql.qualification import qualify_source
|
|
10
|
+
from dbt_extra.sql.rewrites.engine import optimize_source
|
|
11
|
+
from dbt_extra.sql.rewrites.projections import prune_projections, prune_source_projections
|
|
12
|
+
from dbt_extra.sql.rewrites.session import validate_contract
|
|
13
|
+
from tests.optimizer_cases import COMMENT_PROJECTION_QUERIES
|
|
14
|
+
from tests.semantics import assert_equivalent
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
SCHEMA = {"t": {"id": "INT", "x": "INT", "unused": "INT"}}
|
|
18
|
+
PROSE = " legacy timing columns (backward compat) "
|
|
19
|
+
QUERY = "SELECT q.id FROM (SELECT t.id AS id, t.unused AS unused FROM t) q"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def comments(tree):
|
|
23
|
+
return Counter(comment for node in tree.walk() for comment in node.comments or [])
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def inner(tree):
|
|
27
|
+
return tree.find(exp.Subquery).this
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def non_projection_structure(tree):
|
|
31
|
+
clean = tree.copy()
|
|
32
|
+
for node in clean.walk():
|
|
33
|
+
node.pop_comments()
|
|
34
|
+
for query in clean.find_all(exp.Select):
|
|
35
|
+
query.set("expressions", [exp.Literal.number(1)])
|
|
36
|
+
return clean
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.mark.parametrize("dialect", ["duckdb", "spark"])
|
|
40
|
+
def test_only_dead_projection_comments_move_with_duplicate_counts(dialect):
|
|
41
|
+
tree = parse_one(QUERY, read=dialect)
|
|
42
|
+
live, dead = inner(tree).selects
|
|
43
|
+
live.this.add_comments([" live column prose "])
|
|
44
|
+
dead.add_comments([PROSE])
|
|
45
|
+
dead.this.add_comments([PROSE])
|
|
46
|
+
before = tree.copy()
|
|
47
|
+
live_snapshot = live.dump()
|
|
48
|
+
result = prune_projections(tree, dialect=dialect, relocate_comments=True)
|
|
49
|
+
|
|
50
|
+
assert result is tree
|
|
51
|
+
assert inner(tree).selects == [live]
|
|
52
|
+
assert inner(tree).selects[0] is live
|
|
53
|
+
assert live.dump() == live_snapshot
|
|
54
|
+
assert inner(tree).comments == [PROSE, PROSE]
|
|
55
|
+
assert comments(tree) == comments(before)
|
|
56
|
+
assert non_projection_structure(tree) == non_projection_structure(before)
|
|
57
|
+
validate_contract(before, tree, dialect)
|
|
58
|
+
qualify_source(tree, SCHEMA, dialect)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@pytest.mark.parametrize("authored,relocate", [(False, False), (True, False), (True, True)])
|
|
62
|
+
def test_default_and_authored_policies_keep_commented_projections(authored, relocate):
|
|
63
|
+
tree = parse_one(QUERY)
|
|
64
|
+
inner(tree).selects[1].add_comments([PROSE])
|
|
65
|
+
original = tree.copy()
|
|
66
|
+
kwargs = {"authored": original} if authored else {}
|
|
67
|
+
prune_projections(tree, dialect="duckdb", relocate_comments=relocate, **kwargs)
|
|
68
|
+
assert tree.dump() == original.dump()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_source_rewriting_keeps_existing_comment_roots():
|
|
72
|
+
code = "SELECT q.id FROM (SELECT t.id, t.unused /* legacy timing columns */ AS unused FROM t) q"
|
|
73
|
+
authored = parse_one(code, read="duckdb")
|
|
74
|
+
qualified = qualify_source(authored, SCHEMA, "duckdb")
|
|
75
|
+
pruned = prune_source_projections(authored, authored, qualified, dialect="duckdb")
|
|
76
|
+
assert pruned.dump() == authored.dump()
|
|
77
|
+
candidate = parse_one(optimize_source(code, "duckdb", schema=SCHEMA), read="duckdb")
|
|
78
|
+
assert any(p.output_name == "unused" for q in candidate.find_all(exp.Select) for p in q.selects)
|
|
79
|
+
assert comments(candidate) == comments(authored)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.parametrize("dialect", ["duckdb", "spark"])
|
|
83
|
+
@pytest.mark.parametrize("expression", [
|
|
84
|
+
"CAST(t.x AS INT)", "unknown_udf(t.x)", "RAND()", "1 / t.unused", "COALESCE(t.x, 0)",
|
|
85
|
+
])
|
|
86
|
+
def test_prose_does_not_authorize_fallible_or_effectful_removal(dialect, expression):
|
|
87
|
+
tree = parse_one(f"SELECT q.id FROM (SELECT t.id AS id, {expression} AS risky FROM t) q", read=dialect)
|
|
88
|
+
inner(tree).selects[1].add_comments([PROSE])
|
|
89
|
+
original = tree.copy()
|
|
90
|
+
prune_projections(tree, dialect=dialect, relocate_comments=True)
|
|
91
|
+
assert tree.dump() == original.dump()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.mark.parametrize("comment", [
|
|
95
|
+
"+ BROADCAST(t)", "! engine directive", "TODO: preserve", "sqlglot", "SQLGLOT meta",
|
|
96
|
+
"noqa", "NoSeC review", "nosemgrep", "", "123 prose", "prose_with_underscores", "prose = value",
|
|
97
|
+
])
|
|
98
|
+
def test_unfamiliar_and_directive_like_comments_stay_attached(comment):
|
|
99
|
+
tree = parse_one(QUERY)
|
|
100
|
+
inner(tree).selects[1].add_comments([comment])
|
|
101
|
+
original = tree.copy()
|
|
102
|
+
prune_projections(tree, dialect="spark", relocate_comments=True)
|
|
103
|
+
assert tree.dump() == original.dump()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_mixed_prose_and_directive_comments_protect_entire_projection():
|
|
107
|
+
tree = parse_one(QUERY)
|
|
108
|
+
inner(tree).selects[1].add_comments([PROSE])
|
|
109
|
+
inner(tree).selects[1].this.add_comments(["noqa"])
|
|
110
|
+
original = tree.copy()
|
|
111
|
+
prune_projections(tree, dialect="spark", relocate_comments=True)
|
|
112
|
+
assert tree.dump() == original.dump()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_optimizer_hint_ast_is_not_removed_or_relocated():
|
|
116
|
+
tree = parse_one("SELECT q.id FROM (SELECT /*+ BROADCAST(t) */ t.id AS id, t.unused AS unused FROM t) q", read="spark")
|
|
117
|
+
hint = tree.find(exp.Hint)
|
|
118
|
+
assert hint is not None
|
|
119
|
+
snapshot = hint.dump()
|
|
120
|
+
inner(tree).selects[1].add_comments([PROSE])
|
|
121
|
+
prune_projections(tree, dialect="spark", relocate_comments=True)
|
|
122
|
+
assert tree.find(exp.Hint) is hint
|
|
123
|
+
assert hint.dump() == snapshot
|
|
124
|
+
assert [p.output_name for p in inner(tree).selects] == ["id"]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@pytest.mark.parametrize("code,required", [
|
|
128
|
+
("SELECT q.id FROM (SELECT t.id, t.x AS x, x + 1 AS used FROM t) q", "x"),
|
|
129
|
+
("SELECT q.id FROM (SELECT t.id, COUNT(*) AS n FROM t GROUP BY t.id HAVING n > 1) q", "n"),
|
|
130
|
+
("SELECT q.id FROM (SELECT t.id, ROW_NUMBER() OVER (ORDER BY t.x) AS rn FROM t QUALIFY rn=1) q", "rn"),
|
|
131
|
+
("SELECT q.id FROM (SELECT t.id, t.x FROM t ORDER BY x LIMIT 2) q", "x"),
|
|
132
|
+
])
|
|
133
|
+
def test_dependency_roots_still_decide_liveness(code, required):
|
|
134
|
+
tree = parse_one(code, read="duckdb")
|
|
135
|
+
inner(tree).selects[1].add_comments([PROSE])
|
|
136
|
+
before = tree.copy()
|
|
137
|
+
prune_projections(tree, dialect="duckdb", relocate_comments=True)
|
|
138
|
+
assert required in [p.output_name for p in inner(tree).selects]
|
|
139
|
+
assert comments(tree) == comments(before)
|
|
140
|
+
assert non_projection_structure(tree) == non_projection_structure(before)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def test_pruning_never_leaves_an_empty_select():
|
|
144
|
+
tree = parse_one("SELECT 1 AS k FROM (SELECT t.unused AS unused FROM t) q")
|
|
145
|
+
inner(tree).selects[0].add_comments([PROSE])
|
|
146
|
+
before = tree.copy()
|
|
147
|
+
prune_projections(tree, dialect="duckdb", relocate_comments=True)
|
|
148
|
+
assert all(q.selects for q in tree.find_all(exp.Select))
|
|
149
|
+
assert comments(tree) == comments(before)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@pytest.mark.parametrize("empty", [False, True])
|
|
153
|
+
@pytest.mark.parametrize("case", COMMENT_PROJECTION_QUERIES)
|
|
154
|
+
def test_commented_projection_result_semantics(case, empty):
|
|
155
|
+
code, removed = COMMENT_PROJECTION_QUERIES[case]
|
|
156
|
+
before = parse_one(code, read="duckdb")
|
|
157
|
+
qualify_source(before, SCHEMA, "duckdb")
|
|
158
|
+
candidate = prune_projections(before.copy(), dialect="duckdb", relocate_comments=True)
|
|
159
|
+
validate_contract(before, candidate, "duckdb")
|
|
160
|
+
qualify_source(candidate, SCHEMA, "duckdb")
|
|
161
|
+
assert comments(candidate) == comments(before)
|
|
162
|
+
assert non_projection_structure(candidate) == non_projection_structure(before)
|
|
163
|
+
old_count = sum(len(q.selects) for q in before.find_all(exp.Select))
|
|
164
|
+
new_count = sum(len(q.selects) for q in candidate.find_all(exp.Select))
|
|
165
|
+
assert (new_count < old_count) == removed
|
|
166
|
+
with duckdb.connect() as connection:
|
|
167
|
+
connection.execute("CREATE TABLE t(id INT, x INT, unused INT)")
|
|
168
|
+
if not empty:
|
|
169
|
+
connection.execute("INSERT INTO t VALUES (1,2,NULL),(1,2,NULL),(1,3,4),(2,NULL,5),(NULL,6,6)")
|
|
170
|
+
assert_equivalent(connection, code, candidate.sql(dialect="duckdb"))
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Candidate comment preservation is separate from serializer comment fidelity."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from sqlglot import exp, parse_one
|
|
5
|
+
|
|
6
|
+
from dbt_extra.sql.renderer import sql
|
|
7
|
+
from dbt_extra.sql.rewrites import session
|
|
8
|
+
from dbt_extra.sql.rewrites.session import RejectedCandidate, validate_contract
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.parametrize("dialect", ["spark", "duckdb"])
|
|
12
|
+
@pytest.mark.parametrize("cte", [False, True])
|
|
13
|
+
def test_comment_reattachment_round_trips_without_mutating_inputs(dialect, cte):
|
|
14
|
+
code = "SELECT t.id AS id FROM t"
|
|
15
|
+
if cte:
|
|
16
|
+
code = f"WITH expanded AS ({code}) SELECT id FROM expanded"
|
|
17
|
+
before = parse_one(code, read=dialect)
|
|
18
|
+
projection = list(before.find_all(exp.Select))[-1].selects[0]
|
|
19
|
+
projection.add_comments([" legacy timing columns (backward compat) "])
|
|
20
|
+
after = before.copy()
|
|
21
|
+
projection = list(after.find_all(exp.Select))[-1].selects[0]
|
|
22
|
+
projection.this.add_comments(projection.pop_comments())
|
|
23
|
+
snapshots = [tree.dump() for tree in (before, after)]
|
|
24
|
+
rendered = [sql(tree, dialect) for tree in (before, after)]
|
|
25
|
+
|
|
26
|
+
# Exercise the actual parser/generator attachment instability, not just an
|
|
27
|
+
# equality check on two already-normalized renderings.
|
|
28
|
+
assert sql(parse_one(rendered[1], read=dialect), dialect) != rendered[1]
|
|
29
|
+
validate_contract(before, after, dialect)
|
|
30
|
+
assert [tree.dump() for tree in (before, after)] == snapshots
|
|
31
|
+
assert [sql(tree, dialect) for tree in (before, after)] == rendered
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_comment_moves_from_root_select_to_expanded_cte_on_reparse():
|
|
35
|
+
before = parse_one("WITH expanded AS (SELECT id FROM t) SELECT id FROM expanded", read="spark")
|
|
36
|
+
before.add_comments([" expanded from upstream "])
|
|
37
|
+
after = before.copy()
|
|
38
|
+
snapshot = after.dump()
|
|
39
|
+
reparsed = parse_one(sql(after, "spark"), read="spark")
|
|
40
|
+
assert before.comments and not reparsed.comments
|
|
41
|
+
assert reparsed.find(exp.CTE).comments == before.comments
|
|
42
|
+
assert sql(reparsed, "spark") != sql(after, "spark")
|
|
43
|
+
validate_contract(before, after, "spark")
|
|
44
|
+
assert after.dump() == snapshot
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_serializer_comment_loss_is_not_a_candidate_comment_loss_check():
|
|
48
|
+
before = parse_one("WITH expanded AS (SELECT id FROM t) SELECT id FROM expanded", read="spark")
|
|
49
|
+
before.find(exp.CTE).this.add_comments([" expanded from upstream "])
|
|
50
|
+
after = before.copy()
|
|
51
|
+
snapshot = after.dump()
|
|
52
|
+
reparsed = parse_one(sql(after, "spark"), read="spark")
|
|
53
|
+
assert not any(n.comments for n in reparsed.walk())
|
|
54
|
+
# Deliberate boundary: candidate comments match, although SQLGlot loses a
|
|
55
|
+
# nested SELECT comment during rendering/reparsing (a separate upstream bug).
|
|
56
|
+
validate_contract(before, after, "spark")
|
|
57
|
+
assert before.dump() == snapshot == after.dump()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.mark.parametrize("candidate", ["SELECT a AS renamed, b FROM t", "SELECT b, a FROM t"])
|
|
61
|
+
def test_output_names_and_order_still_rejected(candidate):
|
|
62
|
+
with pytest.raises(RejectedCandidate, match="output names or order changed"):
|
|
63
|
+
validate_contract(parse_one("SELECT a, b FROM t"), parse_one(candidate), "spark")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.parametrize("before_count,after_count", [(1, 0), (2, 1), (1, 2)])
|
|
67
|
+
def test_comment_multiset_changes_still_rejected(before_count, after_count):
|
|
68
|
+
before = parse_one("SELECT a FROM t")
|
|
69
|
+
after = before.copy()
|
|
70
|
+
# Separate nodes ensure duplicate occurrences are not parser-normalized.
|
|
71
|
+
for node in list(before.walk())[:before_count]:
|
|
72
|
+
node.add_comments([" same prose "])
|
|
73
|
+
for node in list(after.walk())[:after_count]:
|
|
74
|
+
node.add_comments([" same prose "])
|
|
75
|
+
with pytest.raises(RejectedCandidate, match="SQL comments would be discarded"):
|
|
76
|
+
validate_contract(before, after, "spark")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_changed_comment_text_still_rejected():
|
|
80
|
+
before, after = parse_one("SELECT a FROM t"), parse_one("SELECT a FROM t")
|
|
81
|
+
before.add_comments([" original prose "])
|
|
82
|
+
after.add_comments([" changed prose "])
|
|
83
|
+
with pytest.raises(RejectedCandidate, match="SQL comments would be discarded"):
|
|
84
|
+
validate_contract(before, after, "spark")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_executable_round_trip_instability_still_rejected(monkeypatch):
|
|
88
|
+
before = parse_one("SELECT a FROM t WHERE a > 0")
|
|
89
|
+
monkeypatch.setattr(session, "read_query", lambda *args: parse_one("SELECT a FROM t WHERE a > 1"))
|
|
90
|
+
with pytest.raises(RejectedCandidate, match="SQL did not round-trip"):
|
|
91
|
+
validate_contract(before, before.copy(), "spark")
|
|
@@ -8,8 +8,10 @@ from sqlglot import exp, parse_one
|
|
|
8
8
|
|
|
9
9
|
from dbt_extra.inspection import inspect
|
|
10
10
|
from dbt_extra.sql.rewrites.engine import optimize_source
|
|
11
|
+
from dbt_extra.sql.rewrites.projections import prune_projections
|
|
12
|
+
from dbt_extra.sql.rewrites.session import validate_contract
|
|
11
13
|
from tests.helpers import project, put
|
|
12
|
-
from tests.optimizer_cases import RULE_QUERIES, RULE_SCHEMA, assert_rule_exercised
|
|
14
|
+
from tests.optimizer_cases import COMMENT_PROJECTION_QUERIES, RULE_QUERIES, RULE_SCHEMA, assert_rule_exercised
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
@pytest.fixture(scope="module")
|
|
@@ -132,6 +134,35 @@ def test_spark_executes_certified_null_check_pruning(native, spark, function, mo
|
|
|
132
134
|
assert_spark_equivalent(spark, code, candidate, ordered=True)
|
|
133
135
|
|
|
134
136
|
|
|
137
|
+
@pytest.mark.parametrize("case", COMMENT_PROJECTION_QUERIES)
|
|
138
|
+
@pytest.mark.parametrize("empty", [False, True])
|
|
139
|
+
@pytest.mark.parametrize("ansi", [False, True])
|
|
140
|
+
@pytest.mark.parametrize("mode", ["projection", "inspection"])
|
|
141
|
+
def test_spark_commented_projection_semantics(native, spark, case, empty, ansi, mode):
|
|
142
|
+
spark.conf.set("spark.sql.ansi.enabled", str(ansi).lower())
|
|
143
|
+
spark.sql("CREATE OR REPLACE TEMP VIEW t AS SELECT * FROM VALUES "
|
|
144
|
+
"(1,2,CAST(NULL AS INT)),(1,2,NULL),(1,3,4),(2,NULL,5),(NULL,6,6) AS v(id,x,unused) "
|
|
145
|
+
+ ("WHERE FALSE" if empty else ""))
|
|
146
|
+
code, removed = COMMENT_PROJECTION_QUERIES[case]
|
|
147
|
+
original = parse_one(code, read="spark")
|
|
148
|
+
if mode == "projection":
|
|
149
|
+
tree = prune_projections(original.copy(), dialect="spark", relocate_comments=True)
|
|
150
|
+
validate_contract(original, tree, "spark")
|
|
151
|
+
before_count = sum(len(q.selects) for q in original.find_all(exp.Select))
|
|
152
|
+
after_count = sum(len(q.selects) for q in tree.find_all(exp.Select))
|
|
153
|
+
assert (after_count < before_count) == removed
|
|
154
|
+
else:
|
|
155
|
+
put(native, "models/commented.sql", code)
|
|
156
|
+
p = project(native)
|
|
157
|
+
p.dialect = "spark"
|
|
158
|
+
tree, _, outcomes = inspect(p, "commented", compiled=False)
|
|
159
|
+
if case in {"subquery", "single_cte", "shared_cte", "left_fanout"}:
|
|
160
|
+
assert any(o["rule"] == "projection_pruning" and o["status"] == "applied" for o in outcomes)
|
|
161
|
+
assert Counter(c for n in tree.walk() for c in n.comments or []) == Counter(
|
|
162
|
+
c for n in original.walk() for c in n.comments or [])
|
|
163
|
+
assert_spark_equivalent(spark, code, tree.sql(dialect="spark"), ordered=bool(original.args.get("order")))
|
|
164
|
+
|
|
165
|
+
|
|
135
166
|
@pytest.mark.parametrize("ansi", [False, True])
|
|
136
167
|
@pytest.mark.parametrize("reverse", [False, True])
|
|
137
168
|
@pytest.mark.parametrize("invalid", [False, True])
|