@@ -75,6 +75,7 @@ use datafusion_sql::{
75
75
planner:: ParserOptions ,
76
76
ResolvedTableReference , TableReference ,
77
77
} ;
78
+ use sqlparser:: dialect:: dialect_from_str;
78
79
79
80
use crate :: physical_optimizer:: coalesce_batches:: CoalesceBatches ;
80
81
use crate :: physical_optimizer:: repartition:: Repartition ;
@@ -97,11 +98,6 @@ use datafusion_sql::{
97
98
planner:: { ContextProvider , SqlToRel } ,
98
99
} ;
99
100
use parquet:: file:: properties:: WriterProperties ;
100
- use sqlparser:: dialect:: {
101
- AnsiDialect , BigQueryDialect , ClickHouseDialect , Dialect , GenericDialect ,
102
- HiveDialect , MsSqlDialect , MySqlDialect , PostgreSqlDialect , RedshiftSqlDialect ,
103
- SQLiteDialect , SnowflakeDialect ,
104
- } ;
105
101
use url:: Url ;
106
102
107
103
use crate :: catalog:: information_schema:: { InformationSchemaProvider , INFORMATION_SCHEMA } ;
@@ -1675,7 +1671,13 @@ impl SessionState {
1675
1671
sql : & str ,
1676
1672
dialect : & str ,
1677
1673
) -> 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
+ } ) ?;
1679
1681
let mut statements = DFParser :: parse_sql_with_dialect ( sql, dialect. as_ref ( ) ) ?;
1680
1682
if statements. len ( ) > 1 {
1681
1683
return Err ( DataFusionError :: NotImplemented (
@@ -2071,28 +2073,6 @@ impl From<&SessionState> for TaskContext {
2071
2073
}
2072
2074
}
2073
2075
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
-
2096
2076
/// Default implementation of [SerializerRegistry] that throws unimplemented error
2097
2077
/// for all requests.
2098
2078
pub struct EmptySerializerRegistry ;
0 commit comments