Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect column count used for aliased columns #191

Closed
ohaibbq opened this issue Mar 25, 2024 · 0 comments · Fixed by #205
Closed

Incorrect column count used for aliased columns #191

ohaibbq opened this issue Mar 25, 2024 · 0 comments · Fixed by #205

Comments

@ohaibbq
Copy link
Contributor

ohaibbq commented Mar 25, 2024

QueryStmtNode does not currently use the OutputColumnList() when formatting.

The ZetaSQL analyzer parses this query into the following AST:

WITH toks AS (SELECT true AS x, 1 AS y)
SELECT DISTINCT x, x as y FROM toks
QueryStmt
+-output_column_list=
| +-$distinct.x#5 AS x [BOOL]
| +-$distinct.x#5 AS y [BOOL]
+-query=
  +-WithScan
    +-parse_location=0-80
    +-column_list=[$distinct.x#5]
    +-with_entry_list=
    | +-WithEntry
    |   +-with_query_name="toks"
    |   +-with_subquery=
    |     +-ProjectScan
    |       +-parse_location=14-38
    |       +-column_list=toks.[x#1, y#2]
    |       +-expr_list=
    |       | +-x#1 := Literal(parse_location=21-25, type=BOOL, value=true)
    |       | +-y#2 := Literal(parse_location=32-33, type=INT64, value=1)
    |       +-input_scan=
    |         +-SingleRowScan
    +-query=
      +-AggregateScan
        +-column_list=[$distinct.x#5]
        +-input_scan=
        | +-WithRefScan(column_list=toks.[x#3, y#4], with_query_name="toks")
        +-group_by_list=
          +-x#5 := ColumnRef(type=BOOL, column=toks.x#3)

The analyzer simplifies the column selection to only include column x in the aggregate scan as it is the only column used upstream. We currently only use QueryStmtNode.Query() when formatting a QueryStmtNode, its OutputColumnList() is ignored.

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 a pull request may close this issue.

1 participant