Skip to content

Commit

Permalink
Minor: use upstream dialect_from_str (#6616)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Jun 9, 2023
1 parent 005ecdc commit 1af846b
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions datafusion/core/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use datafusion_sql::{
planner::ParserOptions,
ResolvedTableReference, TableReference,
};
use sqlparser::dialect::dialect_from_str;

use crate::physical_optimizer::coalesce_batches::CoalesceBatches;
use crate::physical_optimizer::repartition::Repartition;
Expand All @@ -97,11 +98,6 @@ use datafusion_sql::{
planner::{ContextProvider, SqlToRel},
};
use parquet::file::properties::WriterProperties;
use sqlparser::dialect::{
AnsiDialect, BigQueryDialect, ClickHouseDialect, Dialect, GenericDialect,
HiveDialect, MsSqlDialect, MySqlDialect, PostgreSqlDialect, RedshiftSqlDialect,
SQLiteDialect, SnowflakeDialect,
};
use url::Url;

use crate::catalog::information_schema::{InformationSchemaProvider, INFORMATION_SCHEMA};
Expand Down Expand Up @@ -1675,7 +1671,13 @@ impl SessionState {
sql: &str,
dialect: &str,
) -> Result<datafusion_sql::parser::Statement> {
let dialect = create_dialect_from_str(dialect)?;
let dialect = dialect_from_str(dialect).ok_or_else(|| {
DataFusionError::Plan(format!(
"Unsupported SQL dialect: {dialect}. Available dialects: \
Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, \
MsSQL, ClickHouse, BigQuery, Ansi."
))
})?;
let mut statements = DFParser::parse_sql_with_dialect(sql, dialect.as_ref())?;
if statements.len() > 1 {
return Err(DataFusionError::NotImplemented(
Expand Down Expand Up @@ -2071,28 +2073,6 @@ impl From<&SessionState> for TaskContext {
}
}

// TODO: remove when https://github.com/sqlparser-rs/sqlparser-rs/pull/848 is released
fn create_dialect_from_str(dialect_name: &str) -> Result<Box<dyn Dialect>> {
match dialect_name.to_lowercase().as_str() {
"generic" => Ok(Box::new(GenericDialect)),
"mysql" => Ok(Box::new(MySqlDialect {})),
"postgresql" | "postgres" => Ok(Box::new(PostgreSqlDialect {})),
"hive" => Ok(Box::new(HiveDialect {})),
"sqlite" => Ok(Box::new(SQLiteDialect {})),
"snowflake" => Ok(Box::new(SnowflakeDialect)),
"redshift" => Ok(Box::new(RedshiftSqlDialect {})),
"mssql" => Ok(Box::new(MsSqlDialect {})),
"clickhouse" => Ok(Box::new(ClickHouseDialect {})),
"bigquery" => Ok(Box::new(BigQueryDialect)),
"ansi" => Ok(Box::new(AnsiDialect {})),
_ => {
Err(DataFusionError::Internal(format!(
"Unsupported SQL dialect: {dialect_name}. Available dialects: Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, ClickHouse, BigQuery, Ansi."
)))
}
}
}

/// Default implementation of [SerializerRegistry] that throws unimplemented error
/// for all requests.
pub struct EmptySerializerRegistry;
Expand Down

0 comments on commit 1af846b

Please sign in to comment.