@@ -75,6 +75,7 @@ use datafusion_sql::{
7575 planner:: ParserOptions ,
7676 ResolvedTableReference , TableReference ,
7777} ;
78+ use sqlparser:: dialect:: dialect_from_str;
7879
7980use crate :: physical_optimizer:: coalesce_batches:: CoalesceBatches ;
8081use crate :: physical_optimizer:: repartition:: Repartition ;
@@ -97,11 +98,6 @@ use datafusion_sql::{
9798 planner:: { ContextProvider , SqlToRel } ,
9899} ;
99100use parquet:: file:: properties:: WriterProperties ;
100- use sqlparser:: dialect:: {
101- AnsiDialect , BigQueryDialect , ClickHouseDialect , Dialect , GenericDialect ,
102- HiveDialect , MsSqlDialect , MySqlDialect , PostgreSqlDialect , RedshiftSqlDialect ,
103- SQLiteDialect , SnowflakeDialect ,
104- } ;
105101use url:: Url ;
106102
107103use crate :: catalog:: information_schema:: { InformationSchemaProvider , INFORMATION_SCHEMA } ;
@@ -1675,7 +1671,13 @@ impl SessionState {
16751671 sql : & str ,
16761672 dialect : & str ,
16771673 ) -> Result < datafusion_sql:: parser:: Statement > {
1678- let dialect = create_dialect_from_str ( dialect) ?;
1674+ let dialect = dialect_from_str ( dialect) . ok_or_else ( || {
1675+ DataFusionError :: Plan ( format ! (
1676+ "Unsupported SQL dialect: {dialect}. Available dialects: \
1677+ Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
1678+ MsSQL, ClickHouse, BigQuery, Ansi."
1679+ ) )
1680+ } ) ?;
16791681 let mut statements = DFParser :: parse_sql_with_dialect ( sql, dialect. as_ref ( ) ) ?;
16801682 if statements. len ( ) > 1 {
16811683 return Err ( DataFusionError :: NotImplemented (
@@ -2071,28 +2073,6 @@ impl From<&SessionState> for TaskContext {
20712073 }
20722074}
20732075
2074- // TODO: remove when https://github.com/sqlparser-rs/sqlparser-rs/pull/848 is released
2075- fn create_dialect_from_str ( dialect_name : & str ) -> Result < Box < dyn Dialect > > {
2076- match dialect_name. to_lowercase ( ) . as_str ( ) {
2077- "generic" => Ok ( Box :: new ( GenericDialect ) ) ,
2078- "mysql" => Ok ( Box :: new ( MySqlDialect { } ) ) ,
2079- "postgresql" | "postgres" => Ok ( Box :: new ( PostgreSqlDialect { } ) ) ,
2080- "hive" => Ok ( Box :: new ( HiveDialect { } ) ) ,
2081- "sqlite" => Ok ( Box :: new ( SQLiteDialect { } ) ) ,
2082- "snowflake" => Ok ( Box :: new ( SnowflakeDialect ) ) ,
2083- "redshift" => Ok ( Box :: new ( RedshiftSqlDialect { } ) ) ,
2084- "mssql" => Ok ( Box :: new ( MsSqlDialect { } ) ) ,
2085- "clickhouse" => Ok ( Box :: new ( ClickHouseDialect { } ) ) ,
2086- "bigquery" => Ok ( Box :: new ( BigQueryDialect ) ) ,
2087- "ansi" => Ok ( Box :: new ( AnsiDialect { } ) ) ,
2088- _ => {
2089- Err ( DataFusionError :: Internal ( format ! (
2090- "Unsupported SQL dialect: {dialect_name}. Available dialects: Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, ClickHouse, BigQuery, Ansi."
2091- ) ) )
2092- }
2093- }
2094- }
2095-
20962076/// Default implementation of [SerializerRegistry] that throws unimplemented error
20972077/// for all requests.
20982078pub struct EmptySerializerRegistry ;
0 commit comments