Skip to content

Commit 89784c1

Browse files
committed
fix(syntax): keep the span of a keyword alias on an ASOF JOIN table
A keyword such as OFFSET or LIMIT used as the alias of an ASOF JOIN table, before MATCH_CONDITION, became an identifier with no span, so a located parse could not point at it. A located parse now gives it the alias token's span. Other parses still leave it without one, as polyglot does, so the exact comparison with polyglot is unchanged.
1 parent ce1ce7a commit 89784c1

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎crates/sqlquack-syntax/src/parser/_helpers/queries/joins.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,15 @@ impl Parser {
227227
.map(|t| t.text.eq_ignore_ascii_case("MATCH_CONDITION"))
228228
== Some(true)
229229
{
230-
let alias_name = self.advance_text()?;
230+
let alias_span = self.peek().span;
231+
let alias = Identifier::new(self.advance_text()?);
231232
Expression::Alias(Box::new(Alias {
232233
this: table,
233-
alias: Identifier::new(alias_name),
234+
alias: if self.config.record_node_spans {
235+
alias.with_span(alias_span)
236+
} else {
237+
alias
238+
},
234239
column_aliases: Vec::new(),
235240
alias_explicit_as: false,
236241
alias_keyword: None,

‎crates/sqlquack-syntax/tests/parser/test_located.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ fn given_a_located_parse_when_reading_a_node_then_its_span_covers_its_source() {
6666
pointer: "/0/select/from/expressions/0",
6767
expected_text: Ok("(SELECT id FROM recent) AS r"),
6868
},
69+
LocatedTestCase {
70+
description: "a keyword alias of an ASOF JOIN table covers its name",
71+
sql: "SELECT * FROM x ASOF JOIN y OFFSET MATCH_CONDITION (x.t >= OFFSET.t)",
72+
pointer: "/0/select/joins/0/this/alias/alias",
73+
expected_text: Ok("OFFSET"),
74+
},
6975
];
7076

7177
for test_case in test_cases {

0 commit comments

Comments
 (0)