Skip to content

Commit 6fec91e

Browse files
committed
Update for new sqlparser API
1 parent cff5bbd commit 6fec91e

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
@@ -593,11 +593,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
593593
}
594594
not_impl_err!("AnyOp not supported by ExprPlanner: {binary_expr:?}")
595595
}
596-
SQLExpr::Wildcard => Ok(Expr::Wildcard {
596+
SQLExpr::Wildcard(_token) => Ok(Expr::Wildcard {
597597
qualifier: None,
598598
options: WildcardOptions::default(),
599599
}),
600-
SQLExpr::QualifiedWildcard(object_name) => Ok(Expr::Wildcard {
600+
SQLExpr::QualifiedWildcard(object_name, _token) => Ok(Expr::Wildcard {
601601
qualifier: Some(self.object_name_to_table_reference(object_name)?),
602602
options: WildcardOptions::default(),
603603
}),

datafusion/sql/src/parser.rs

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

2323
use sqlparser::ast::ExprWithAlias;
24+
use sqlparser::tokenizer::TokenWithSpan;
2425
use sqlparser::{
2526
ast::{
2627
ColumnDef, ColumnOptionDef, ObjectName, OrderByExpr, Query,
2728
Statement as SQLStatement, TableConstraint, Value,
2829
},
2930
dialect::{keywords::Keyword, Dialect, GenericDialect},
3031
parser::{Parser, ParserError},
31-
tokenizer::{Token, TokenWithLocation, Tokenizer, Word},
32+
tokenizer::{Token, Tokenizer, Word},
3233
};
3334

3435
// Use `Parser::expected` instead, if possible
@@ -338,7 +339,7 @@ impl<'a> DFParser<'a> {
338339
fn expected<T>(
339340
&self,
340341
expected: &str,
341-
found: TokenWithLocation,
342+
found: TokenWithSpan,
342343
) -> Result<T, ParserError> {
343344
parser_err!(format!("Expected {expected}, found: {found}"))
344345
}
@@ -876,6 +877,7 @@ mod tests {
876877
use super::*;
877878
use sqlparser::ast::Expr::Identifier;
878879
use sqlparser::ast::{BinaryOperator, DataType, Expr, Ident};
880+
use sqlparser::tokenizer::Span;
879881

880882
fn expect_parse_ok(sql: &str, expected: Statement) -> Result<(), ParserError> {
881883
let statements = DFParser::parse_sql(sql)?;
@@ -911,6 +913,7 @@ mod tests {
911913
name: Ident {
912914
value: name.into(),
913915
quote_style: None,
916+
span: Span::empty(),
914917
},
915918
data_type,
916919
collation: None,
@@ -1219,6 +1222,7 @@ mod tests {
12191222
expr: Identifier(Ident {
12201223
value: "c1".to_owned(),
12211224
quote_style: None,
1225+
span: Span::empty(),
12221226
}),
12231227
asc,
12241228
nulls_first,
@@ -1250,6 +1254,7 @@ mod tests {
12501254
expr: Identifier(Ident {
12511255
value: "c1".to_owned(),
12521256
quote_style: None,
1257+
span: Span::empty(),
12531258
}),
12541259
asc: Some(true),
12551260
nulls_first: None,
@@ -1259,6 +1264,7 @@ mod tests {
12591264
expr: Identifier(Ident {
12601265
value: "c2".to_owned(),
12611266
quote_style: None,
1267+
span: Span::empty(),
12621268
}),
12631269
asc: Some(false),
12641270
nulls_first: Some(true),
@@ -1290,11 +1296,13 @@ mod tests {
12901296
left: Box::new(Identifier(Ident {
12911297
value: "c1".to_owned(),
12921298
quote_style: None,
1299+
span: Span::empty(),
12931300
})),
12941301
op: BinaryOperator::Minus,
12951302
right: Box::new(Identifier(Ident {
12961303
value: "c2".to_owned(),
12971304
quote_style: None,
1305+
span: Span::empty(),
12981306
})),
12991307
},
13001308
asc: Some(true),
@@ -1335,11 +1343,13 @@ mod tests {
13351343
left: Box::new(Identifier(Ident {
13361344
value: "c1".to_owned(),
13371345
quote_style: None,
1346+
span: Span::empty(),
13381347
})),
13391348
op: BinaryOperator::Minus,
13401349
right: Box::new(Identifier(Ident {
13411350
value: "c2".to_owned(),
13421351
quote_style: None,
1352+
span: Span::empty(),
13431353
})),
13441354
},
13451355
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)