@@ -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:: {
@@ -384,7 +383,7 @@ impl SessionState {
384383 pub fn sql_to_statement (
385384 & self ,
386385 sql : & str ,
387- dialect : & str ,
386+ dialect : & Dialect ,
388387 ) -> datafusion_common:: Result < Statement > {
389388 let dialect = dialect_from_str ( dialect) . ok_or_else ( || {
390389 plan_datafusion_err ! (
@@ -421,7 +420,7 @@ impl SessionState {
421420 pub fn sql_to_expr (
422421 & self ,
423422 sql : & str ,
424- dialect : & str ,
423+ dialect : & Dialect ,
425424 ) -> datafusion_common:: Result < SQLExpr > {
426425 self . sql_to_expr_with_alias ( sql, dialect) . map ( |x| x. expr )
427426 }
@@ -433,7 +432,7 @@ impl SessionState {
433432 pub fn sql_to_expr_with_alias (
434433 & self ,
435434 sql : & str ,
436- dialect : & str ,
435+ dialect : & Dialect ,
437436 ) -> datafusion_common:: Result < SQLExprWithAlias > {
438437 let dialect = dialect_from_str ( dialect) . ok_or_else ( || {
439438 plan_datafusion_err ! (
@@ -537,8 +536,8 @@ impl SessionState {
537536 & self ,
538537 sql : & str ,
539538 ) -> datafusion_common:: Result < LogicalPlan > {
540- let dialect = self . config . options ( ) . sql_parser . dialect . as_str ( ) ;
541- let statement = self . sql_to_statement ( sql, dialect) ?;
539+ let dialect = self . config . options ( ) . sql_parser . dialect ;
540+ let statement = self . sql_to_statement ( sql, & dialect) ?;
542541 let plan = self . statement_to_plan ( statement) . await ?;
543542 Ok ( plan)
544543 }
@@ -552,9 +551,9 @@ impl SessionState {
552551 sql : & str ,
553552 df_schema : & DFSchema ,
554553 ) -> datafusion_common:: Result < Expr > {
555- let dialect = self . config . options ( ) . sql_parser . dialect . as_str ( ) ;
554+ let dialect = self . config . options ( ) . sql_parser . dialect ;
556555
557- let sql_expr = self . sql_to_expr_with_alias ( sql, dialect) ?;
556+ let sql_expr = self . sql_to_expr_with_alias ( sql, & dialect) ?;
558557
559558 let provider = SessionContextProvider {
560559 state : self ,
@@ -2082,6 +2081,7 @@ mod tests {
20822081 use arrow:: array:: { ArrayRef , Int32Array , RecordBatch , StringArray } ;
20832082 use arrow:: datatypes:: { DataType , Field , Schema } ;
20842083 use datafusion_catalog:: MemoryCatalogProviderList ;
2084+ use datafusion_common:: config:: Dialect ;
20852085 use datafusion_common:: DFSchema ;
20862086 use datafusion_common:: Result ;
20872087 use datafusion_execution:: config:: SessionConfig ;
@@ -2107,8 +2107,8 @@ mod tests {
21072107 let sql = "[1,2,3]" ;
21082108 let schema = Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , true ) ] ) ;
21092109 let df_schema = DFSchema :: try_from ( schema) ?;
2110- let dialect = state. config . options ( ) . sql_parser . dialect . as_str ( ) ;
2111- let sql_expr = state. sql_to_expr ( sql, dialect) ?;
2110+ let dialect = state. config . options ( ) . sql_parser . dialect ;
2111+ let sql_expr = state. sql_to_expr ( sql, & dialect) ?;
21122112
21132113 let query = SqlToRel :: new_with_options ( & provider, state. get_parser_options ( ) ) ;
21142114 query. sql_to_expr ( sql_expr, & df_schema, & mut PlannerContext :: new ( ) )
@@ -2266,7 +2266,8 @@ mod tests {
22662266 }
22672267
22682268 let state = & context_provider. state ;
2269- let statement = state. sql_to_statement ( "select count(*) from t" , "mysql" ) ?;
2269+ let statement =
2270+ state. sql_to_statement ( "select count(*) from t" , & Dialect :: MySQL ) ?;
22702271 let plan = SqlToRel :: new ( & context_provider) . statement_to_plan ( statement) ?;
22712272 state. create_physical_plan ( & plan) . await
22722273 }
0 commit comments