Skip to content

Fix various type inference issues#1986

Merged
shangyian merged 2 commits intoDataJunction:mainfrom
shangyian:complex-type-inf
Apr 10, 2026
Merged

Fix various type inference issues#1986
shangyian merged 2 commits intoDataJunction:mainfrom
shangyian:complex-type-inf

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

@shangyian shangyian commented Apr 10, 2026

Summary

This PR fixes two sources of false-positive invalid column validation errors.

Lambda parameters incorrectly flagged as invalid columns

PR #1961 added surfacing of invalid column errors during node validation. However, lambda parameter identifiers (e.g. c in c -> c.name = 'foo') are valid namespaces within their lambda body but were not included in local_aliases, causing them to be surfaced as unresolved column errors.

The fix is to collect all lambda parameter names from query_ast.find_all(ast.Lambda) and add them to local aliases before filtering.

(VALUES ...) AS alias(cols) generates false errors

(VALUES (1, 2)) AS v(a, b) is parsed by AliasedQueryContext, which was discarding the explicit column aliases (a, b) (the second return value of visit(tableAlias) was assigned to _). This caused two bugs:

  1. The inner Query's InlineTable columns stayed as auto-generated col1/col2, so add_ref_column returned False for v.a / v.b, which lead to a false invalid column error.
  2. Query compilation crashed with AttributeError: 'InlineTable' object has no attribute 'from_' because it assumed self.select is always a SelectExpression.

The fix:

  • AliasedQueryContext now captures col_aliases and renames InlineTable._columns to the explicit aliases when present.
  • Query compilation short-circuits when self.select is an inline table, exposing its columns directly.

Test Plan

Added a number of tests, including:

  • test_metric_with_lambda_parameters_is_valid
  • test_lateral_view_alias_not_flagged_as_invalid_column
  • test_unnest_alias_not_flagged_as_invalid_column
  • test_values_clause_alias_not_flagged_as_invalid_column
  • test_correlated_subquery_outer_alias_not_flagged_as_invalid_column
  • test_values_clause_explicit_column_aliases (AST-level unit test)

Deployment Plan

…iew, unnest, values clause, correlated subqueries
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 10, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 03dfce4
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/69d8c117e91f8b0008bc289c

@shangyian shangyian changed the title Fix type inference issues and add tests for: lambda params, lateral v… Fix various type inference issues Apr 10, 2026
@shangyian shangyian marked this pull request as ready for review April 10, 2026 09:40
@shangyian shangyian merged commit 561090e into DataJunction:main Apr 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant