@@ -30,15 +30,14 @@ use crate::datasource::provider_as_source;
3030use crate :: execution:: context:: { EmptySerializerRegistry , FunctionFactory , QueryPlanner } ;
3131use crate :: execution:: SessionStateDefaults ;
3232use crate :: physical_planner:: { DefaultPhysicalPlanner , PhysicalPlanner } ;
33+ use arrow:: datatypes:: DataType ;
3334use datafusion_catalog:: information_schema:: {
3435 InformationSchemaProvider , INFORMATION_SCHEMA ,
3536} ;
36-
37- use arrow:: datatypes:: DataType ;
3837use datafusion_catalog:: MemoryCatalogProviderList ;
3938use datafusion_catalog:: { TableFunction , TableFunctionImpl } ;
4039use datafusion_common:: alias:: AliasGenerator ;
41- use datafusion_common:: config:: { ConfigExtension , ConfigOptions , TableOptions } ;
40+ use datafusion_common:: config:: { ConfigExtension , ConfigOptions , Dialect , TableOptions } ;
4241use datafusion_common:: display:: { PlanType , StringifiedPlan , ToStringifiedPlan } ;
4342use datafusion_common:: tree_node:: TreeNode ;
4443use datafusion_common:: {
@@ -374,7 +373,7 @@ impl SessionState {
374373 pub fn sql_to_statement (
375374 & self ,
376375 sql : & str ,
377- dialect : & str ,
376+ dialect : & Dialect ,
378377 ) -> datafusion_common:: Result < Statement > {
379378 let dialect = dialect_from_str ( dialect) . ok_or_else ( || {
380379 plan_datafusion_err ! (
@@ -411,7 +410,7 @@ impl SessionState {
411410 pub fn sql_to_expr (
412411 & self ,
413412 sql : & str ,
414- dialect : & str ,
413+ dialect : & Dialect ,
415414 ) -> datafusion_common:: Result < SQLExpr > {
416415 self . sql_to_expr_with_alias ( sql, dialect) . map ( |x| x. expr )
417416 }
@@ -423,7 +422,7 @@ impl SessionState {
423422 pub fn sql_to_expr_with_alias (
424423 & self ,
425424 sql : & str ,
426- dialect : & str ,
425+ dialect : & Dialect ,
427426 ) -> datafusion_common:: Result < SQLExprWithAlias > {
428427 let dialect = dialect_from_str ( dialect) . ok_or_else ( || {
429428 plan_datafusion_err ! (
@@ -527,8 +526,8 @@ impl SessionState {
527526 & self ,
528527 sql : & str ,
529528 ) -> datafusion_common:: Result < LogicalPlan > {
530- let dialect = self . config . options ( ) . sql_parser . dialect . as_str ( ) ;
531- let statement = self . sql_to_statement ( sql, dialect) ?;
529+ let dialect = self . config . options ( ) . sql_parser . dialect ;
530+ let statement = self . sql_to_statement ( sql, & dialect) ?;
532531 let plan = self . statement_to_plan ( statement) . await ?;
533532 Ok ( plan)
534533 }
@@ -542,9 +541,9 @@ impl SessionState {
542541 sql : & str ,
543542 df_schema : & DFSchema ,
544543 ) -> datafusion_common:: Result < Expr > {
545- let dialect = self . config . options ( ) . sql_parser . dialect . as_str ( ) ;
544+ let dialect = self . config . options ( ) . sql_parser . dialect ;
546545
547- let sql_expr = self . sql_to_expr_with_alias ( sql, dialect) ?;
546+ let sql_expr = self . sql_to_expr_with_alias ( sql, & dialect) ?;
548547
549548 let provider = SessionContextProvider {
550549 state : self ,
@@ -2034,6 +2033,7 @@ mod tests {
20342033 use arrow:: array:: { ArrayRef , Int32Array , RecordBatch , StringArray } ;
20352034 use arrow:: datatypes:: { DataType , Field , Schema } ;
20362035 use datafusion_catalog:: MemoryCatalogProviderList ;
2036+ use datafusion_common:: config:: Dialect ;
20372037 use datafusion_common:: DFSchema ;
20382038 use datafusion_common:: Result ;
20392039 use datafusion_execution:: config:: SessionConfig ;
@@ -2059,8 +2059,8 @@ mod tests {
20592059 let sql = "[1,2,3]" ;
20602060 let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , true ) ] ) ;
20612061 let df_schema = DFSchema :: try_from ( schema) ?;
2062- let dialect = state. config . options ( ) . sql_parser . dialect . as_str ( ) ;
2063- let sql_expr = state. sql_to_expr ( sql, dialect) ?;
2062+ let dialect = state. config . options ( ) . sql_parser . dialect ;
2063+ let sql_expr = state. sql_to_expr ( sql, & dialect) ?;
20642064
20652065 let query = SqlToRel :: new_with_options ( & provider, state. get_parser_options ( ) ) ;
20662066 query. sql_to_expr ( sql_expr, & df_schema, & mut PlannerContext :: new ( ) )
@@ -2218,7 +2218,8 @@ mod tests {
22182218 }
22192219
22202220 let state = & context_provider. state ;
2221- let statement = state. sql_to_statement ( "select count(*) from t" , "mysql" ) ?;
2221+ let statement =
2222+ state. sql_to_statement ( "select count(*) from t" , & Dialect :: MySQL ) ?;
22222223 let plan = SqlToRel :: new ( & context_provider) . statement_to_plan ( statement) ?;
22232224 state. create_physical_plan ( & plan) . await
22242225 }
0 commit comments