You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2023/06/09 17:41:02 UTC
[arrow-datafusion] branch main updated: Minor: use upstream `dialect_from_str` (#6616)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 1af846bd8d Minor: use upstream `dialect_from_str` (#6616)
1af846bd8d is described below
commit 1af846bd8de387ce7a6e61a2008917a7610b9a7b
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Fri Jun 9 13:40:56 2023 -0400
Minor: use upstream `dialect_from_str` (#6616)
---
datafusion/core/src/execution/context.rs | 36 +++++++-------------------------
1 file changed, 8 insertions(+), 28 deletions(-)
diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs
index 22e6ca42ee..6b81a39691 100644
--- a/datafusion/core/src/execution/context.rs
+++ b/datafusion/core/src/execution/context.rs
@@ -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;
@@ -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};
@@ -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(
@@ -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;