Skip to content

Commit 52c5d17

Browse files
committed
Update for new sqlparser API
1 parent 80a156b commit 52c5d17

File tree

15 files changed

+208
-64
lines changed

15 files changed

+208
-64
lines changed

datafusion/common/src/utils/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,10 @@ pub fn get_available_parallelism() -> usize {
887887

888888
#[cfg(test)]
889889
mod tests {
890+
use super::*;
890891
use crate::ScalarValue::Null;
891892
use arrow::array::Float64Array;
892-
893-
use super::*;
893+
use sqlparser::tokenizer::Span;
894894

895895
#[test]
896896
fn test_bisect_linear_left_and_right() -> Result<()> {
@@ -1118,6 +1118,7 @@ mod tests {
11181118
let expected_parsed = vec![Ident {
11191119
value: identifier.to_string(),
11201120
quote_style,
1121+
span: Span::empty(),
11211122
}];
11221123

11231124
assert_eq!(

datafusion/core/tests/user_defined/user_defined_scalar_functions.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ use arrow_array::{
2727
Array, ArrayRef, Float32Array, Float64Array, Int32Array, RecordBatch, StringArray,
2828
};
2929
use arrow_schema::{DataType, Field, Schema};
30-
use parking_lot::Mutex;
31-
use regex::Regex;
32-
use sqlparser::ast::Ident;
33-
3430
use datafusion::execution::context::{FunctionFactory, RegisterFunction, SessionState};
3531
use datafusion::prelude::*;
3632
use datafusion::{execution::registry::FunctionRegistry, test_util};
@@ -48,6 +44,10 @@ use datafusion_expr::{
4844
Volatility,
4945
};
5046
use datafusion_functions_nested::range::range_udf;
47+
use parking_lot::Mutex;
48+
use regex::Regex;
49+
use sqlparser::ast::Ident;
50+
use sqlparser::tokenizer::Span;
5151

5252
/// test that casting happens on udfs.
5353
/// c11 is f32, but `custom_sqrt` requires f64. Casting happens but the logical plan and
@@ -1187,6 +1187,7 @@ async fn create_scalar_function_from_sql_statement_postgres_syntax() -> Result<(
11871187
name: Some(Ident {
11881188
value: "name".into(),
11891189
quote_style: None,
1190+
span: Span::empty(),
11901191
}),
11911192
data_type: DataType::Utf8,
11921193
default_expr: None,
@@ -1196,6 +1197,7 @@ async fn create_scalar_function_from_sql_statement_postgres_syntax() -> Result<(
11961197
language: Some(Ident {
11971198
value: "plrust".into(),
11981199
quote_style: None,
1200+
span: Span::empty(),
11991201
}),
12001202
behavior: None,
12011203
function_body: Some(lit(body)),

datafusion/expr/src/expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ use sqlparser::ast::{
222222
/// // to 42 = 5 AND b = 6
223223
/// assert_eq!(rewritten.data, lit(42).eq(lit(5)).and(col("b").eq(lit(6))));
224224
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
225+
// TODO make the enum smaller with more boxing (looks like Wildcard is now bigger)
226+
#[allow(clippy::large_enum_variant)]
225227
pub enum Expr {
226228
/// An expression with a specific name.
227229
Alias(Alias),

datafusion/sql/src/expr/function.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ impl FunctionArgs {
169169
"Calling {name}: SEPARATOR not supported in function arguments: {sep}"
170170
)
171171
}
172+
FunctionArgumentClause::JsonNullClause(jn) => {
173+
return not_impl_err!(
174+
"Calling {name}: JSON NULL clause not supported in function arguments: {jn}"
175+
)
176+
}
172177
}
173178
}
174179

datafusion/sql/src/expr/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
565565
}
566566
not_impl_err!("AnyOp not supported by ExprPlanner: {binary_expr:?}")
567567
}
568-
SQLExpr::Wildcard => Ok(Expr::Wildcard {
568+
SQLExpr::Wildcard(_token) => Ok(Expr::Wildcard {
569569
qualifier: None,
570570
options: WildcardOptions::default(),
571571
}),
572-
SQLExpr::QualifiedWildcard(object_name) => Ok(Expr::Wildcard {
572+
SQLExpr::QualifiedWildcard(object_name, _token) => Ok(Expr::Wildcard {
573573
qualifier: Some(self.object_name_to_table_reference(object_name)?),
574574
options: WildcardOptions::default(),
575575
}),

datafusion/sql/src/parser.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
use std::collections::VecDeque;
2121
use std::fmt;
2222

23+
use sqlparser::tokenizer::TokenWithSpan;
2324
use sqlparser::{
2425
ast::{
2526
ColumnDef, ColumnOptionDef, Expr, ObjectName, OrderByExpr, Query,
2627
Statement as SQLStatement, TableConstraint, Value,
2728
},
2829
dialect::{keywords::Keyword, Dialect, GenericDialect},
2930
parser::{Parser, ParserError},
30-
tokenizer::{Token, TokenWithLocation, Tokenizer, Word},
31+
tokenizer::{Token, Tokenizer, Word},
3132
};
3233

3334
// Use `Parser::expected` instead, if possible
@@ -337,7 +338,7 @@ impl<'a> DFParser<'a> {
337338
fn expected<T>(
338339
&self,
339340
expected: &str,
340-
found: TokenWithLocation,
341+
found: TokenWithSpan,
341342
) -> Result<T, ParserError> {
342343
parser_err!(format!("Expected {expected}, found: {found}"))
343344
}
@@ -875,6 +876,7 @@ mod tests {
875876
use super::*;
876877
use sqlparser::ast::Expr::Identifier;
877878
use sqlparser::ast::{BinaryOperator, DataType, Expr, Ident};
879+
use sqlparser::tokenizer::Span;
878880

879881
fn expect_parse_ok(sql: &str, expected: Statement) -> Result<(), ParserError> {
880882
let statements = DFParser::parse_sql(sql)?;
@@ -910,6 +912,7 @@ mod tests {
910912
name: Ident {
911913
value: name.into(),
912914
quote_style: None,
915+
span: Span::empty(),
913916
},
914917
data_type,
915918
collation: None,
@@ -1218,6 +1221,7 @@ mod tests {
12181221
expr: Identifier(Ident {
12191222
value: "c1".to_owned(),
12201223
quote_style: None,
1224+
span: Span::empty(),
12211225
}),
12221226
asc,
12231227
nulls_first,
@@ -1249,6 +1253,7 @@ mod tests {
12491253
expr: Identifier(Ident {
12501254
value: "c1".to_owned(),
12511255
quote_style: None,
1256+
span: Span::empty(),
12521257
}),
12531258
asc: Some(true),
12541259
nulls_first: None,
@@ -1258,6 +1263,7 @@ mod tests {
12581263
expr: Identifier(Ident {
12591264
value: "c2".to_owned(),
12601265
quote_style: None,
1266+
span: Span::empty(),
12611267
}),
12621268
asc: Some(false),
12631269
nulls_first: Some(true),
@@ -1289,11 +1295,13 @@ mod tests {
12891295
left: Box::new(Identifier(Ident {
12901296
value: "c1".to_owned(),
12911297
quote_style: None,
1298+
span: Span::empty(),
12921299
})),
12931300
op: BinaryOperator::Minus,
12941301
right: Box::new(Identifier(Ident {
12951302
value: "c2".to_owned(),
12961303
quote_style: None,
1304+
span: Span::empty(),
12971305
})),
12981306
},
12991307
asc: Some(true),
@@ -1334,11 +1342,13 @@ mod tests {
13341342
left: Box::new(Identifier(Ident {
13351343
value: "c1".to_owned(),
13361344
quote_style: None,
1345+
span: Span::empty(),
13371346
})),
13381347
op: BinaryOperator::Minus,
13391348
right: Box::new(Identifier(Ident {
13401349
value: "c2".to_owned(),
13411350
quote_style: None,
1351+
span: Span::empty(),
13421352
})),
13431353
},
13441354
asc: Some(true),

datafusion/sql/src/planner.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
339339
plan: LogicalPlan,
340340
alias: TableAlias,
341341
) -> Result<LogicalPlan> {
342-
let plan = self.apply_expr_alias(plan, alias.columns)?;
342+
let idents = alias.columns.into_iter().map(|c| c.name).collect();
343+
let plan = self.apply_expr_alias(plan, idents)?;
343344

344345
LogicalPlanBuilder::from(plan)
345346
.alias(TableReference::bare(
@@ -542,7 +543,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
542543
| SQLDataType::Regclass
543544
| SQLDataType::Custom(_, _)
544545
| SQLDataType::Array(_)
545-
| SQLDataType::Enum(_)
546+
| SQLDataType::Enum(_, _)
546547
| SQLDataType::Set(_)
547548
| SQLDataType::MediumInt(_)
548549
| SQLDataType::UnsignedMediumInt(_)
@@ -586,6 +587,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
586587
| SQLDataType::Nullable(_)
587588
| SQLDataType::LowCardinality(_)
588589
| SQLDataType::Trigger
590+
// MySQL datatypes
591+
| SQLDataType::TinyBlob
592+
| SQLDataType::MediumBlob
593+
| SQLDataType::LongBlob
594+
| SQLDataType::TinyText
595+
| SQLDataType::MediumText
596+
| SQLDataType::LongText
597+
| SQLDataType::Bit(_)
598+
|SQLDataType::BitVarying(_)
589599
=> not_impl_err!(
590600
"Unsupported SQL type {sql_type:?}"
591601
),

datafusion/sql/src/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
655655
opt_rename,
656656
opt_replace: _opt_replace,
657657
opt_ilike: _opt_ilike,
658+
wildcard_token: _wildcard_token,
658659
} = options;
659660

660661
if opt_rename.is_some() {

0 commit comments

Comments
 (0)