Table version clause (`AT(...)`, `FOR SYSTEM_TIME AS OF`, `VERSION AS OF`) is displayed after the alias and doesn't reparse

未关闭
#2,804 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust, sql
领域
compilers

调研方向

The parse order is in parse_table_factor, where maybe_parse_table_version runs before maybe_parse_table_alias. The write order is in the TableFactor::Table arm of Display, which emits alias, index hints and WITH (...) before the version. Read the dialect trait methods and the existing version tests first, then check PR #2486 for overlap. Done means a round-trip check passes for the Snowflake, MsSql, Databricks and BigQuery inputs, with the position chosen per dialect.

由索引模型根据 Issue 内容生成。

描述

BigQuery Databricks Prolific Author Snowflake SQL Server

The parser reads the version clause before the alias and table hints, but Display writes it after them, so the output doesn't parse:

Snowflake:  SELECT * FROM my_table AT(OFFSET => -60*5) AS T WHERE T.flag = 'valid'
  -> displays as: SELECT * FROM my_table AS T AT(OFFSET => -60 * 5) WHERE T.flag = 'valid'
  -> reparse: Expected: identifier, found: ( at Line: 1, Column: 31

MsSql:      SELECT * FROM t FOR SYSTEM_TIME AS OF '2014-01-01' AS x WITH (NOLOCK)
  -> displays as: SELECT * FROM t AS x WITH (NOLOCK) FOR SYSTEM_TIME AS OF '2014-01-01'
  -> reparse: Expected: one of UPDATE or SHARE, found: SYSTEM_TIME at Line: 1, Column: 40

Databricks: SELECT * FROM events VERSION AS OF 123 AS e
  -> displays as: SELECT * FROM events AS e VERSION AS OF 123
  -> reparse: Expected: end of statement, found: VERSION at Line: 1, Column: 27

The Snowflake input is the example from https://docs.snowflake.com/en/sql-reference/constructs/at-before. SQL Server documents table_or_view_name [ FOR SYSTEM_TIME <system_time> ] [ [ AS ] table_alias ] ... [ WITH ( <table_hint> ... ) ] (https://learn.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql), and Databricks puts the temporal spec in table_name, before table_alias (https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-table-reference).

BigQuery documents the opposite order, table_name [ as_alias ] [ FOR SYSTEM_TIME AS OF ... ] (https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#from_clause), and with BigQueryDialect SELECT * FROM t AS x FOR SYSTEM_TIME AS OF '2020-01-01' is rejected (Expected: one of UPDATE or SHARE, found: SYSTEM_TIME), while the other order parses and displays as the rejected form. So the right position seems to be dialect dependent.

Parser: maybe_parse_table_version runs before maybe_parse_table_alias in parse_table_factor. Display: the TableFactor::Table arm writes alias, index hints, WITH (...), then the version. The open PR #2486 mentions this in passing and leaves it for a separate change.

Tested on main ce12f1f6 (also 0.63.0; on 0.58.0 the Databricks input is a parse error).

Found with a property-based fuzzer (round trip check); I used AI assistance for triage and verified every case above.

主要语言
Rust
星标
3.5k
派生
805
平均合并
2 天 3 小时
30 天内合并 PR
116

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-sqlparser-rs 的其他 Issue

查看 apache/datafusion-sqlparser-rs 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。