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

Aberta
#2,804 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
42/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
rust, sql
Domínio
compilers

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Rust
Estrelas
3.5k
Forks
805
Merge médio
2d 3h
PRs com merge (30d)
116

Preparar o ambiente

  • Sem Dockerfile nem arquivo Docker Compose
  • Tem um modelo de pull request
  • Sem guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de apache/datafusion-sqlparser-rs

Todas as issues de apache/datafusion-sqlparser-rs

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.