Skip to content

validate_with_schema rejects columns from VALUES sources #471

Description

@kvlonge

Summary

validate_with_schema() does not expose VALUES columns to the enclosing query. It rejects both the default column1 names and explicit column aliases.

Reproduction

pip install polyglot-sql==0.12.1
import polyglot_sql

schema = {"tables": [{"name": "orders", "columns": [{"name": "total", "type": "INT"}]}]}

for sql in (
    "WITH inventory AS (SELECT column1 AS product_id FROM VALUES (1)) "
    "SELECT product_id FROM inventory",
    "SELECT inventory_rows.product_id FROM VALUES (1) AS inventory_rows(product_id)",
):
    result = polyglot_sql.validate_with_schema(sql, schema, dialect="snowflake")
    print(result.valid, [(error.code, error.message) for error in result.errors])

Actual

False [('E201', "Unknown column 'column1' (not found in any referenced table)")]
False [('E222', "Unknown table or alias 'inventory_rows' referenced by column 'product_id'")]

Expected

Both queries are valid. A VALUES source provides column1..columnN by default, or its declared column aliases, under its table alias.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions