Skip to content

Commit 6b64dba

Browse files
ayman-sigmaclaude
andcommitted
Fix compilation errors and update tests after upstream sync
- Add missing `pos` field to State initializer in tokenizer hint parsing - Remove spurious `sample` reference that leaked into PassThroughQuery Display - Add `sample` AfterTableAlias check back to Derived Display - Add missing doc comments to sigma types (InExpr, PassThroughQuery, TokenWithRange) required by upstream's new #![forbid(missing_docs)] - Remove unfulfilled #![expect(clippy::unnecessary_unwrap)] from lib.rs - Add has_colon: true to JsonPath initializers in Snowflake-style colon-path tests - Update Databricks a:['b'] test to use new ColonBracket AST node (upstream change) - Exclude DatabricksDialect from parse_array_subscript test since Databricks uses `:` for JSON paths, conflicting with array slice syntax arr[1:2] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ce320d0 commit 6b64dba

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

src/ast/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,11 @@ pub enum Expr {
934934
/// XXX not valid SQL syntax, this is a hack needed to support parameter substitution
935935
/// `[ NOT ] IN <in_expr>`
936936
InExpr {
937+
/// Left-hand expression to test for membership.
937938
expr: Box<Expr>,
939+
/// The expression providing the candidate values (used for parameter substitution).
938940
in_expr: Box<Expr>,
941+
/// `true` when the `NOT` modifier is present.
939942
negated: bool,
940943
},
941944
/// `[ NOT ] IN UNNEST(array_expression)`

src/ast/query.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,9 @@ pub enum TableFactor {
14951495
/// A pass-through query string that is not parsed.
14961496
/// This is useful while building/rewriting queries with a known valid SQL string and to avoid parsing it.
14971497
PassThroughQuery {
1498+
/// The raw SQL query string to pass through without parsing.
14981499
query: String,
1500+
/// Optional alias for the pass-through query.
14991501
alias: Option<TableAlias>,
15001502
},
15011503
/// `TABLE(<expr>)[ AS <alias> ]`
@@ -2259,16 +2261,16 @@ impl fmt::Display for TableFactor {
22592261
if let Some(alias) = alias {
22602262
write!(f, " {alias}")?;
22612263
}
2264+
if let Some(TableSampleKind::AfterTableAlias(sample)) = sample {
2265+
write!(f, " {sample}")?;
2266+
}
22622267
Ok(())
22632268
}
22642269
TableFactor::PassThroughQuery { query, alias } => {
22652270
write!(f, "({query})")?;
22662271
if let Some(alias) = alias {
22672272
write!(f, " {alias}")?;
22682273
}
2269-
if let Some(TableSampleKind::AfterTableAlias(sample)) = sample {
2270-
write!(f, " {sample}")?;
2271-
}
22722274
Ok(())
22732275
}
22742276
TableFactor::Function {

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@
153153
// Splitting complex nodes (expressions, statements, types) into separate types
154154
// would bloat the API and hide intent. Extra memory is a worthwhile tradeoff.
155155
#![allow(clippy::large_enum_variant)]
156-
// TODO: Fix and remove this.
157-
#![expect(clippy::unnecessary_unwrap)]
158156
#![forbid(clippy::unreachable)]
159157
#![forbid(missing_docs)]
160158

src/tokenizer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,18 @@ impl fmt::Display for TokenWithSpan {
788788
}
789789
}
790790

791+
/// A token together with its byte-offset range in the source string.
791792
pub struct TokenWithRange {
793+
/// The token.
792794
pub token: Token,
795+
/// The byte offset of the start of the token in the source string.
793796
pub start: usize,
797+
/// The byte offset of the end of the token in the source string.
794798
pub end: usize,
795799
}
796800

797801
impl TokenWithRange {
802+
/// Creates a new [`TokenWithRange`] with the given token and byte-offset range.
798803
pub fn new(token: Token, start: usize, end: usize) -> Self {
799804
Self { token, start, end }
800805
}
@@ -957,6 +962,7 @@ impl<'a> Tokenizer<'a> {
957962
Ok(twl.into_iter().map(|t| t.token).collect())
958963
}
959964

965+
/// Tokenize the statement and produce a vector of tokens with their byte-offset ranges.
960966
pub fn tokenize_with_range(&mut self) -> Result<Vec<TokenWithRange>, TokenizerError> {
961967
let mut tokens = Vec::<TokenWithRange>::new();
962968
let mut state = State {
@@ -1057,6 +1063,7 @@ impl<'a> Tokenizer<'a> {
10571063
// Create a state for tracking position within the hint
10581064
let mut state = State {
10591065
peekable: hint_content.chars().peekable(),
1066+
pos: 0,
10601067
line: span.start.line,
10611068
col: span.start.column,
10621069
};

tests/sqlparser_common.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18647,6 +18647,7 @@ fn parse_semi_structured_data_traversal() {
1864718647
SelectItem::UnnamedExpr(Expr::JsonAccess {
1864818648
value: Box::new(Expr::Identifier(Ident::new("a"))),
1864918649
path: JsonPath {
18650+
has_colon: true,
1865018651
path: vec![JsonPathElem::Dot {
1865118652
key: "b".to_owned(),
1865218653
quoted: false
@@ -18663,6 +18664,7 @@ fn parse_semi_structured_data_traversal() {
1866318664
SelectItem::UnnamedExpr(Expr::JsonAccess {
1866418665
value: Box::new(Expr::Identifier(Ident::new("a"))),
1866518666
path: JsonPath {
18667+
has_colon: true,
1866618668
path: vec![JsonPathElem::Dot {
1866718669
key: "my long object key name".to_owned(),
1866818670
quoted: true
@@ -18682,6 +18684,7 @@ fn parse_semi_structured_data_traversal() {
1868218684
SelectItem::UnnamedExpr(Expr::JsonAccess {
1868318685
value: Box::new(Expr::Identifier(Ident::new("a"))),
1868418686
path: JsonPath {
18687+
has_colon: true,
1868518688
path: vec![JsonPathElem::Dot {
1868618689
key: "select".to_owned(),
1868718690
quoted: false
@@ -18691,6 +18694,7 @@ fn parse_semi_structured_data_traversal() {
1869118694
SelectItem::UnnamedExpr(Expr::JsonAccess {
1869218695
value: Box::new(Expr::Identifier(Ident::new("a"))),
1869318696
path: JsonPath {
18697+
has_colon: true,
1869418698
path: vec![JsonPathElem::Dot {
1869518699
key: "from".to_owned(),
1869618700
quoted: false
@@ -18709,6 +18713,7 @@ fn parse_semi_structured_data_traversal() {
1870918713
vec![SelectItem::UnnamedExpr(Expr::JsonAccess {
1871018714
value: Box::new(Expr::Identifier(Ident::new("a"))),
1871118715
path: JsonPath {
18716+
has_colon: true,
1871218717
path: vec![
1871318718
JsonPathElem::Dot {
1871418719
key: "foo".to_owned(),
@@ -18736,6 +18741,7 @@ fn parse_semi_structured_data_traversal() {
1873618741
vec![SelectItem::UnnamedExpr(Expr::JsonAccess {
1873718742
value: Box::new(Expr::Identifier(Ident::new("a"))),
1873818743
path: JsonPath {
18744+
has_colon: true,
1873918745
path: vec![
1874018746
JsonPathElem::Dot {
1874118747
key: "foo".to_owned(),
@@ -18762,6 +18768,9 @@ fn parse_array_subscript() {
1876218768
|| d.is::<SnowflakeDialect>()
1876318769
|| d.is::<SQLiteDialect>()
1876418770
|| d.is::<RedshiftSqlDialect>()
18771+
// Databricks uses `:` for JSON path access (high precedence), which conflicts
18772+
// with array slice syntax `arr[1:2]`.
18773+
|| d.is::<DatabricksDialect>()
1876518774
});
1876618775

1876718776
dialects.verified_stmt("SELECT arr[1]");

tests/sqlparser_databricks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,16 +718,16 @@ fn parse_semi_structured_data_traversal() {
718718
select.projection[0]
719719
);
720720

721-
// asterisk for arrays
721+
// colon bracket notation: a:['b'].c
722722
let sql = "SELECT a:['b'].c FROM t";
723723
let select = databricks().verified_only_select(sql);
724724
assert_eq!(
725725
SelectItem::UnnamedExpr(Expr::JsonAccess {
726726
value: Box::new(Expr::Identifier(Ident::new("a"))),
727727
path: JsonPath {
728-
has_colon: true,
728+
has_colon: false,
729729
path: vec![
730-
JsonPathElem::Bracket {
730+
JsonPathElem::ColonBracket {
731731
key: Expr::value(Value::SingleQuotedString("b".to_owned())),
732732
},
733733
JsonPathElem::Dot {

0 commit comments

Comments
 (0)