|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | 2 | // SPDX-FileCopyrightText: Copyright The Lance Authors |
3 | 3 |
|
4 | | -//! SQL dialect support for the DataFusion unparser. |
| 4 | +//! Spark SQL dialect for the DataFusion unparser. |
5 | 5 | //! |
6 | 6 | //! This module provides a Spark SQL dialect built using DataFusion's |
7 | | -//! [`CustomDialectBuilder`], and a helper to build an [`Unparser`] for any |
8 | | -//! supported [`SqlDialect`]. |
| 7 | +//! [`CustomDialectBuilder`]. |
9 | 8 | //! |
10 | 9 | //! Key Spark SQL differences from standard SQL: |
11 | 10 | //! - Backtick (`` ` ``) identifier quoting |
|
18 | 17 |
|
19 | 18 | use datafusion_sql::unparser::dialect::{ |
20 | 19 | CharacterLengthStyle, CustomDialect, CustomDialectBuilder, DateFieldExtractStyle, |
21 | | - DefaultDialect, MySqlDialect, PostgreSqlDialect, SqliteDialect, |
22 | 20 | }; |
23 | | -use datafusion_sql::unparser::Unparser; |
24 | 21 | use datafusion_sql::sqlparser::ast::{self, Ident, ObjectName, TimezoneInfo}; |
25 | 22 |
|
26 | | -use crate::query::SqlDialect; |
27 | | - |
28 | 23 | /// Build a Spark SQL dialect using DataFusion's `CustomDialectBuilder`. |
29 | 24 | pub fn build_spark_dialect() -> CustomDialect { |
30 | 25 | CustomDialectBuilder::new() |
@@ -56,40 +51,6 @@ pub fn build_spark_dialect() -> CustomDialect { |
56 | 51 | .build() |
57 | 52 | } |
58 | 53 |
|
59 | | -/// Wrapper to hold the concrete dialect type and provide an `Unparser` reference. |
60 | | -pub enum DialectUnparser { |
61 | | - Default(DefaultDialect), |
62 | | - Spark(CustomDialect), |
63 | | - PostgreSql(PostgreSqlDialect), |
64 | | - MySql(MySqlDialect), |
65 | | - Sqlite(SqliteDialect), |
66 | | -} |
67 | | - |
68 | | -impl DialectUnparser { |
69 | | - pub fn as_unparser(&self) -> Unparser<'_> { |
70 | | - match self { |
71 | | - DialectUnparser::Default(d) => Unparser::new(d), |
72 | | - DialectUnparser::Spark(d) => Unparser::new(d), |
73 | | - DialectUnparser::PostgreSql(d) => Unparser::new(d), |
74 | | - DialectUnparser::MySql(d) => Unparser::new(d), |
75 | | - DialectUnparser::Sqlite(d) => Unparser::new(d), |
76 | | - } |
77 | | - } |
78 | | -} |
79 | | - |
80 | | -impl SqlDialect { |
81 | | - /// Create a `DialectUnparser` configured for this dialect. |
82 | | - pub fn unparser(&self) -> DialectUnparser { |
83 | | - match self { |
84 | | - SqlDialect::Default => DialectUnparser::Default(DefaultDialect {}), |
85 | | - SqlDialect::Spark => DialectUnparser::Spark(build_spark_dialect()), |
86 | | - SqlDialect::PostgreSql => DialectUnparser::PostgreSql(PostgreSqlDialect {}), |
87 | | - SqlDialect::MySql => DialectUnparser::MySql(MySqlDialect {}), |
88 | | - SqlDialect::Sqlite => DialectUnparser::Sqlite(SqliteDialect {}), |
89 | | - } |
90 | | - } |
91 | | -} |
92 | | - |
93 | 54 | #[cfg(test)] |
94 | 55 | mod tests { |
95 | 56 | use super::*; |
|
0 commit comments