@@ -46,18 +46,19 @@ use datafusion_expr::{
4646 cast, col, Analyze , CreateCatalog , CreateCatalogSchema ,
4747 CreateExternalTable as PlanCreateExternalTable , CreateFunction , CreateFunctionBody ,
4848 CreateMemoryTable , CreateView , DescribeTable , DmlStatement , DropCatalogSchema ,
49- DropFunction , DropTable , DropView , EmptyRelation , Explain , ExprSchemable , Filter ,
50- LogicalPlan , LogicalPlanBuilder , OperateFunctionArg , PlanType , Prepare , SetVariable ,
51- Statement as PlanStatement , ToStringifiedPlan , TransactionAccessMode ,
49+ DropFunction , DropTable , DropView , EmptyRelation , Explain , Expr , ExprSchemable ,
50+ Filter , LogicalPlan , LogicalPlanBuilder , OperateFunctionArg , PlanType , Prepare ,
51+ SetVariable , Statement as PlanStatement , ToStringifiedPlan , TransactionAccessMode ,
5252 TransactionConclusion , TransactionEnd , TransactionIsolationLevel , TransactionStart ,
5353 Volatility , WriteOp ,
5454} ;
5555use sqlparser:: ast;
5656use sqlparser:: ast:: {
57- Assignment , ColumnDef , CreateTableOptions , Delete , DescribeAlias , Expr as SQLExpr ,
58- Expr , FromTable , Ident , Insert , ObjectName , ObjectType , OneOrManyWithParens , Query ,
59- SchemaName , SetExpr , ShowCreateObject , ShowStatementFilter , Statement ,
60- TableConstraint , TableFactor , TableWithJoins , TransactionMode , UnaryOperator , Value ,
57+ Assignment , AssignmentTarget , ColumnDef , CreateTable , CreateTableOptions , Delete ,
58+ DescribeAlias , Expr as SQLExpr , FromTable , Ident , Insert , ObjectName , ObjectType ,
59+ OneOrManyWithParens , Query , SchemaName , SetExpr , ShowCreateObject ,
60+ ShowStatementFilter , Statement , TableConstraint , TableFactor , TableWithJoins ,
61+ TransactionMode , UnaryOperator , Value ,
6162} ;
6263use sqlparser:: parser:: ParserError :: ParserError ;
6364
@@ -240,7 +241,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
240241 value,
241242 } => self . set_variable_to_plan ( local, hivevar, & variables, value) ,
242243
243- Statement :: CreateTable {
244+ Statement :: CreateTable ( CreateTable {
244245 query,
245246 name,
246247 columns,
@@ -250,7 +251,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
250251 if_not_exists,
251252 or_replace,
252253 ..
253- } if table_properties. is_empty ( ) && with_options. is_empty ( ) => {
254+ } ) if table_properties. is_empty ( ) && with_options. is_empty ( ) => {
254255 // Merge inline constraints and existing constraints
255256 let mut all_constraints = constraints;
256257 let inline_constraints = calc_inline_constraints_from_columns ( & columns) ;
@@ -954,7 +955,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
954955 order_exprs : Vec < LexOrdering > ,
955956 schema : & DFSchemaRef ,
956957 planner_context : & mut PlannerContext ,
957- ) -> Result < Vec < Vec < datafusion_expr :: Expr > > > {
958+ ) -> Result < Vec < Vec < Expr > > > {
958959 // Ask user to provide a schema if schema is empty.
959960 if !order_exprs. is_empty ( ) && schema. fields ( ) . is_empty ( ) {
960961 return plan_err ! (
@@ -1159,7 +1160,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
11591160 local : bool ,
11601161 hivevar : bool ,
11611162 variables : & OneOrManyWithParens < ObjectName > ,
1162- value : Vec < Expr > ,
1163+ value : Vec < SQLExpr > ,
11631164 ) -> Result < LogicalPlan > {
11641165 if local {
11651166 return not_impl_err ! ( "LOCAL is not supported" ) ;
@@ -1218,7 +1219,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12181219 fn delete_to_plan (
12191220 & self ,
12201221 table_name : ObjectName ,
1221- predicate_expr : Option < Expr > ,
1222+ predicate_expr : Option < SQLExpr > ,
12221223 ) -> Result < LogicalPlan > {
12231224 // Do a table lookup to verify the table exists
12241225 let table_ref = self . object_name_to_table_reference ( table_name. clone ( ) ) ?;
@@ -1264,7 +1265,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12641265 table : TableWithJoins ,
12651266 assignments : Vec < Assignment > ,
12661267 from : Option < TableWithJoins > ,
1267- predicate_expr : Option < Expr > ,
1268+ predicate_expr : Option < SQLExpr > ,
12681269 ) -> Result < LogicalPlan > {
12691270 let ( table_name, table_alias) = match & table. relation {
12701271 TableFactor :: Table { name, alias, .. } => ( name. clone ( ) , alias. clone ( ) ) ,
@@ -1284,16 +1285,20 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12841285 let mut assign_map = assignments
12851286 . iter ( )
12861287 . map ( |assign| {
1287- let col_name: & Ident = assign
1288- . id
1288+ let cols = match & assign. target {
1289+ AssignmentTarget :: ColumnName ( cols) => cols,
1290+ _ => plan_err ! ( "Tuples are not supported" ) ?,
1291+ } ;
1292+ let col_name: & Ident = cols
1293+ . 0
12891294 . iter ( )
12901295 . last ( )
12911296 . ok_or_else ( || plan_datafusion_err ! ( "Empty column id" ) ) ?;
12921297 // Validate that the assignment target column exists
12931298 table_schema. field_with_unqualified_name ( & col_name. value ) ?;
12941299 Ok ( ( col_name. value . clone ( ) , assign. value . clone ( ) ) )
12951300 } )
1296- . collect :: < Result < HashMap < String , Expr > > > ( ) ?;
1301+ . collect :: < Result < HashMap < String , SQLExpr > > > ( ) ?;
12971302
12981303 // Build scan, join with from table if it exists.
12991304 let mut input_tables = vec ! [ table] ;
@@ -1332,8 +1337,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13321337 & mut planner_context,
13331338 ) ?;
13341339 // Update placeholder's datatype to the type of the target column
1335- if let datafusion_expr:: Expr :: Placeholder ( placeholder) = & mut expr
1336- {
1340+ if let Expr :: Placeholder ( placeholder) = & mut expr {
13371341 placeholder. data_type = placeholder
13381342 . data_type
13391343 . take ( )
@@ -1345,14 +1349,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13451349 None => {
13461350 // If the target table has an alias, use it to qualify the column name
13471351 if let Some ( alias) = & table_alias {
1348- datafusion_expr :: Expr :: Column ( Column :: new (
1352+ Expr :: Column ( Column :: new (
13491353 Some ( self . normalizer . normalize ( alias. name . clone ( ) ) ) ,
13501354 field. name ( ) ,
13511355 ) )
13521356 } else {
1353- datafusion_expr:: Expr :: Column ( Column :: from ( (
1354- qualifier, field,
1355- ) ) )
1357+ Expr :: Column ( Column :: from ( ( qualifier, field) ) )
13561358 }
13571359 }
13581360 } ;
@@ -1427,7 +1429,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
14271429 if let SetExpr :: Values ( ast:: Values { rows, .. } ) = ( * source. body ) . clone ( ) {
14281430 for row in rows. iter ( ) {
14291431 for ( idx, val) in row. iter ( ) . enumerate ( ) {
1430- if let ast :: Expr :: Value ( Value :: Placeholder ( name) ) = val {
1432+ if let SQLExpr :: Value ( Value :: Placeholder ( name) ) = val {
14311433 let name =
14321434 name. replace ( '$' , "" ) . parse :: < usize > ( ) . map_err ( |_| {
14331435 plan_datafusion_err ! ( "Can't parse placeholder: {name}" )
@@ -1460,23 +1462,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
14601462 . map ( |( i, value_index) | {
14611463 let target_field = table_schema. field ( i) ;
14621464 let expr = match value_index {
1463- Some ( v) => datafusion_expr :: Expr :: Column ( Column :: from (
1464- source. schema ( ) . qualified_field ( v) ,
1465- ) )
1466- . cast_to ( target_field . data_type ( ) , source . schema ( ) ) ? ,
1465+ Some ( v) => {
1466+ Expr :: Column ( Column :: from ( source. schema ( ) . qualified_field ( v) ) )
1467+ . cast_to ( target_field . data_type ( ) , source . schema ( ) ) ?
1468+ }
14671469 // The value is not specified. Fill in the default value for the column.
14681470 None => table_source
14691471 . get_column_default ( target_field. name ( ) )
14701472 . cloned ( )
14711473 . unwrap_or_else ( || {
14721474 // If there is no default for the column, then the default is NULL
1473- datafusion_expr :: Expr :: Literal ( ScalarValue :: Null )
1475+ Expr :: Literal ( ScalarValue :: Null )
14741476 } )
14751477 . cast_to ( target_field. data_type ( ) , & DFSchema :: empty ( ) ) ?,
14761478 } ;
14771479 Ok ( expr. alias ( target_field. name ( ) ) )
14781480 } )
1479- . collect :: < Result < Vec < datafusion_expr :: Expr > > > ( ) ?;
1481+ . collect :: < Result < Vec < Expr > > > ( ) ?;
14801482 let source = project ( source, exprs) ?;
14811483
14821484 let op = if overwrite {
0 commit comments