Skip to content

Commit 71d502b

Browse files
committed
graph, store: Update sqlparser to latest version
1 parent 0b03de0 commit 71d502b

File tree

8 files changed

+179
-51
lines changed

8 files changed

+179
-51
lines changed

Cargo.lock

Lines changed: 47 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ serde_json = { version = "1.0", features = ["arbitrary_precision"] }
8282
serde_regex = "1.1.0"
8383
serde_yaml = "0.9.21"
8484
slog = { version = "2.7.0", features = ["release_max_level_trace", "max_level_trace"] }
85-
sqlparser = { version = "0.46.0", features = ["visitor"] }
85+
sqlparser = { version = "0.59.0", features = ["visitor"] }
8686
strum = { version = "0.26", features = ["derive"] }
8787
syn = { version = "2.0.106", features = ["full"] }
8888
test-store = { path = "./store/test-store" }

graph/src/schema/input/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,8 +3090,10 @@ type Gravatar @entity {
30903090
} else {
30913091
let msgs: Vec<_> = errs.iter().map(|err| err.to_string()).collect();
30923092
panic!(
3093-
"{file_name} failed but not with the expected error `{msg}`: {errs:?} {msgs:?}",
3094-
)
3093+
"{file_name} failed but not with the expected error `{msg}`: \n\
3094+
actual: {errs:?}\n\
3095+
or {msgs:?}",
3096+
)
30953097
}
30963098
}
30973099
(true, Ok(_)) => {

graph/src/schema/input/sqlexpr.rs

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait ExprVisitor {
3737
fn visit_ident(&mut self, ident: &mut p::Ident) -> Result<(), ()>;
3838
/// Visit a function name. Must return `Err` if the function is not
3939
/// allowed
40-
fn visit_func_name(&mut self, func: &mut p::Ident) -> Result<(), ()>;
40+
fn visit_func_name(&mut self, func: &mut p::ObjectNamePart) -> Result<(), ()>;
4141
/// Called when we encounter a construct that is not supported like a
4242
/// subquery
4343
fn not_supported(&mut self, msg: String);
@@ -112,17 +112,16 @@ impl<'a> VisitExpr<'a> {
112112
Case {
113113
operand,
114114
conditions,
115-
results,
116115
else_result,
116+
case_token: _,
117+
end_token: _,
117118
} => {
118119
if let Some(operand) = operand {
119120
self.visit_expr(operand)?;
120121
}
121122
for condition in conditions {
122-
self.visit_expr(condition)?;
123-
}
124-
for result in results {
125-
self.visit_expr(result)?;
123+
self.visit_expr(&mut condition.condition)?;
124+
self.visit_expr(&mut condition.result)?;
126125
}
127126
if let Some(else_result) = else_result {
128127
self.visit_expr(else_result)?;
@@ -152,7 +151,6 @@ impl<'a> VisitExpr<'a> {
152151
}
153152
CompoundIdentifier(_) => self.nope("CompoundIdentifier"),
154153
JsonAccess { .. } => self.nope("JsonAccess"),
155-
CompositeAccess { .. } => self.nope("CompositeAccess"),
156154
IsUnknown(_) => self.nope("IsUnknown"),
157155
IsNotUnknown(_) => self.nope("IsNotUnknown"),
158156
InList { .. } => self.nope("InList"),
@@ -175,9 +173,7 @@ impl<'a> VisitExpr<'a> {
175173
Trim { .. } => self.nope("Trim"),
176174
Overlay { .. } => self.nope("Overlay"),
177175
Collate { .. } => self.nope("Collate"),
178-
IntroducedString { .. } => self.nope("IntroducedString"),
179176
TypedString { .. } => self.nope("TypedString"),
180-
MapAccess { .. } => self.nope("MapAccess"),
181177
Exists { .. } => self.nope("Exists"),
182178
Subquery(_) => self.nope("Subquery"),
183179
GroupingSets(_) => self.nope("GroupingSets"),
@@ -186,32 +182,41 @@ impl<'a> VisitExpr<'a> {
186182
Tuple(_) => self.nope("Tuple"),
187183
Struct { .. } => self.nope("Struct"),
188184
Named { .. } => self.nope("Named"),
189-
ArrayIndex { .. } => self.nope("ArrayIndex"),
190185
Array(_) => self.nope("Array"),
191186
Interval(_) => self.nope("Interval"),
192187
MatchAgainst { .. } => self.nope("MatchAgainst"),
193-
Wildcard => self.nope("Wildcard"),
194-
QualifiedWildcard(_) => self.nope("QualifiedWildcard"),
188+
Wildcard(_) => self.nope("Wildcard"),
189+
QualifiedWildcard(_, _) => self.nope("QualifiedWildcard"),
195190
Dictionary(_) => self.nope("Dictionary"),
196191
OuterJoin(_) => self.nope("OuterJoin"),
197192
Prior(_) => self.nope("Prior"),
193+
CompoundFieldAccess { .. } => self.nope("CompoundFieldAccess"),
194+
IsNormalized { .. } => self.nope("IsNormalized"),
195+
Prefixed { .. } => self.nope("Prefixed"),
196+
Map(_) => self.nope("Map"),
197+
Lambda(_) => self.nope("Lambda"),
198+
MemberOf(_) => self.nope("MemberOf"),
198199
}
199200
}
200201

201202
fn visit_func(&mut self, func: &mut p::Function) -> Result<(), ()> {
202203
let p::Function {
203204
name,
205+
parameters,
204206
args: pargs,
205207
filter,
206208
null_treatment,
207209
over,
208210
within_group,
211+
uses_odbc_syntax,
209212
} = func;
210213

211214
if filter.is_some()
212215
|| null_treatment.is_some()
213216
|| over.is_some()
214217
|| !within_group.is_empty()
218+
|| *uses_odbc_syntax
219+
|| !matches!(parameters, p::FunctionArguments::None)
215220
{
216221
return self.illegal_function(format!("call to {name} uses an illegal feature"));
217222
}
@@ -259,6 +264,15 @@ impl<'a> VisitExpr<'a> {
259264
));
260265
}
261266
},
267+
ExprNamed {
268+
name: expr_name,
269+
arg: _,
270+
operator: _,
271+
} => {
272+
return self.illegal_function(format!(
273+
"call to {name} uses illegal ExprNamed {expr_name}"
274+
));
275+
}
262276
};
263277
}
264278
}
@@ -304,7 +318,27 @@ impl<'a> VisitExpr<'a> {
304318
| AtQuestion
305319
| Question
306320
| QuestionAnd
307-
| QuestionPipe => self.not_supported(format!("binary operator {op} is not supported")),
321+
| QuestionPipe
322+
| Match
323+
| Regexp
324+
| Overlaps
325+
| DoubleHash
326+
| LtDashGt
327+
| AndLt
328+
| AndGt
329+
| LtLtPipe
330+
| PipeGtGt
331+
| AndLtPipe
332+
| PipeAndGt
333+
| LtCaret
334+
| GtCaret
335+
| QuestionHash
336+
| QuestionDash
337+
| QuestionDashPipe
338+
| QuestionDoublePipe
339+
| At
340+
| TildeEq
341+
| Assignment => self.not_supported(format!("binary operator {op} is not supported")),
308342
}
309343
}
310344

@@ -313,7 +347,9 @@ impl<'a> VisitExpr<'a> {
313347
match op {
314348
Plus | Minus | Not => Ok(()),
315349
PGBitwiseNot | PGSquareRoot | PGCubeRoot | PGPostfixFactorial | PGPrefixFactorial
316-
| PGAbs => self.not_supported(format!("unary operator {op} is not supported")),
350+
| PGAbs | BangNot | Hash | AtDashAt | DoubleAt | QuestionDash | QuestionPipe => {
351+
self.not_supported(format!("unary operator {op} is not supported"))
352+
}
317353
}
318354
}
319355
}
@@ -346,8 +382,19 @@ impl<F: CheckIdentFn> ExprVisitor for Validator<F> {
346382
}
347383
}
348384

349-
fn visit_func_name(&mut self, func: &mut p::Ident) -> Result<(), ()> {
350-
let p::Ident { value, quote_style } = &func;
385+
fn visit_func_name(&mut self, func: &mut p::ObjectNamePart) -> Result<(), ()> {
386+
let func = match func {
387+
p::ObjectNamePart::Identifier(ident) => ident,
388+
p::ObjectNamePart::Function(p::ObjectNamePartFunction { name, args: _ }) => {
389+
self.not_supported(format!("function {name} is an object naming function"));
390+
return Err(());
391+
}
392+
};
393+
let p::Ident {
394+
value,
395+
quote_style,
396+
span: _,
397+
} = &func;
351398
let whitelisted = match quote_style {
352399
Some(_) => FN_WHITELIST.contains(&value.as_str()),
353400
None => FN_WHITELIST

graph/src/schema/test_schemas/ts_expr_syntax_err.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fail: ExprParseError("sql parser error: Expected an expression:, found: EOF")
1+
# fail: ExprParseError("sql parser error: Expected: an expression, found: EOF"
22
type Data @entity(timeseries: true) {
33
id: Int8!
44
timestamp: Timestamp!

store/postgres/src/relational/rollup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn rewrite<'a>(table: &'a Table, expr: &str) -> Result<(String, Vec<&'a str>), S
105105
}
106106
}
107107

108-
fn visit_func_name(&mut self, _func: &mut p::Ident) -> Result<(), ()> {
108+
fn visit_func_name(&mut self, _func: &mut p::ObjectNamePart) -> Result<(), ()> {
109109
Ok(())
110110
}
111111

store/postgres/src/sql/parser_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from (select "id", "timestamp", "pool", "token_0", "token_1", "sender", "recipient", "origin", "amount_0", "amount_1", "amount_usd", "sqrt_price_x96", "tick", "log_index"
4949
from "sgd0815"."swap" where block$ <= 2147483647) as sm,
5050
unnest(sm.amounts_out, sm.tokens_out) as smo (amount, token)) as tp
51-
join tokens as t on t.address = tp.token
51+
inner join tokens as t on t.address = tp.token
5252
group by tp.date, t.symbol, t.decimals
5353
order by tp.date desc, amount desc
5454
- name: pg_sleep forbidden

0 commit comments

Comments
 (0)