Skip to content

move primitive dialect configuration into a struct #1431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/dialect/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::dialect::Dialect;
use crate::dialect::{Dialect, DialectFlags};

/// A [`Dialect`] for [ANSI SQL](https://en.wikipedia.org/wiki/SQL:2011).
#[derive(Debug)]
pub struct AnsiDialect {}
#[derive(Debug, Default)]
pub struct AnsiDialect;

impl Dialect for AnsiDialect {
fn flags(&self) -> DialectFlags {
DialectFlags {
require_interval_qualifier: true,
..Default::default()
}
}

fn is_identifier_start(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase()
}

fn is_identifier_part(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '_'
}

fn require_interval_qualifier(&self) -> bool {
true
}
}
56 changes: 21 additions & 35 deletions src/dialect/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::dialect::Dialect;
use crate::dialect::{Dialect, DialectFlags};

/// A [`Dialect`] for [Google Bigquery](https://cloud.google.com/bigquery/)
#[derive(Debug, Default)]
pub struct BigQueryDialect;

impl Dialect for BigQueryDialect {
fn flags(&self) -> DialectFlags {
DialectFlags {
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals
supports_triple_quoted_string: true,
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#first_value
supports_window_function_null_treatment_arg: true,
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#escape_sequences
supports_string_literal_backslash_escape: true,
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls#ref_named_window
supports_window_clause_named_window_reference: true,
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#set
supports_parenthesized_set_variables: true,
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#select_except
supports_select_wildcard_except: true,
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#interval_type
require_interval_qualifier: true,
..Default::default()
}
}

// See https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#identifiers
fn is_delimited_identifier_start(&self, ch: char) -> bool {
ch == '`'
Expand All @@ -33,38 +53,4 @@ impl Dialect for BigQueryDialect {
fn is_identifier_part(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '_'
}

/// See [doc](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals)
fn supports_triple_quoted_string(&self) -> bool {
true
}

/// See [doc](https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#first_value)
fn supports_window_function_null_treatment_arg(&self) -> bool {
true
}

// See https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#escape_sequences
fn supports_string_literal_backslash_escape(&self) -> bool {
true
}

/// See [doc](https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls#ref_named_window)
fn supports_window_clause_named_window_reference(&self) -> bool {
true
}

/// See [doc](https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#set)
fn supports_parenthesized_set_variables(&self) -> bool {
true
}

// See https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#select_except
fn supports_select_wildcard_except(&self) -> bool {
true
}

fn require_interval_qualifier(&self) -> bool {
true
}
}
31 changes: 12 additions & 19 deletions src/dialect/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::dialect::Dialect;
use crate::dialect::{Dialect, DialectFlags};

// A [`Dialect`] for [ClickHouse](https://clickhouse.com/).
#[derive(Debug)]
pub struct ClickHouseDialect {}
#[derive(Debug, Default)]
pub struct ClickHouseDialect;

impl Dialect for ClickHouseDialect {
fn flags(&self) -> DialectFlags {
DialectFlags {
supports_string_literal_backslash_escape: true,
supports_select_wildcard_except: true,
describe_requires_table_keyword: true,
require_interval_qualifier: true,
..Default::default()
}
}
fn is_identifier_start(&self, ch: char) -> bool {
// See https://clickhouse.com/docs/en/sql-reference/syntax/#syntax-identifiers
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_'
Expand All @@ -25,20 +34,4 @@ impl Dialect for ClickHouseDialect {
fn is_identifier_part(&self, ch: char) -> bool {
self.is_identifier_start(ch) || ch.is_ascii_digit()
}

fn supports_string_literal_backslash_escape(&self) -> bool {
true
}

fn supports_select_wildcard_except(&self) -> bool {
true
}

fn describe_requires_table_keyword(&self) -> bool {
true
}

fn require_interval_qualifier(&self) -> bool {
true
}
}
38 changes: 14 additions & 24 deletions src/dialect/databricks.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
use crate::dialect::Dialect;
use crate::dialect::{Dialect, DialectFlags};

/// A [`Dialect`] for [Databricks SQL](https://www.databricks.com/)
///
/// See <https://docs.databricks.com/en/sql/language-manual/index.html>.
#[derive(Debug, Default)]
pub struct DatabricksDialect;

/// see <https://docs.databricks.com/en/sql/language-manual/sql-ref-identifiers.html>
impl Dialect for DatabricksDialect {
// see https://docs.databricks.com/en/sql/language-manual/sql-ref-identifiers.html
fn flags(&self) -> DialectFlags {
DialectFlags {
supports_filter_during_aggregation: true,
// https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html
supports_group_by_expr: true,
supports_lambda_functions: true,
// https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html#syntax
supports_select_wildcard_except: true,
require_interval_qualifier: true,
..Default::default()
}
}

fn is_delimited_identifier_start(&self, ch: char) -> bool {
matches!(ch, '`')
Expand All @@ -20,26 +32,4 @@ impl Dialect for DatabricksDialect {
fn is_identifier_part(&self, ch: char) -> bool {
matches!(ch, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_')
}

fn supports_filter_during_aggregation(&self) -> bool {
true
}

// https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html
fn supports_group_by_expr(&self) -> bool {
true
}

fn supports_lambda_functions(&self) -> bool {
true
}

// https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html#syntax
fn supports_select_wildcard_except(&self) -> bool {
true
}

fn require_interval_qualifier(&self) -> bool {
true
}
}
46 changes: 17 additions & 29 deletions src/dialect/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::dialect::Dialect;
use crate::dialect::{Dialect, DialectFlags};

/// A [`Dialect`] for [DuckDB](https://duckdb.org/)
#[derive(Debug, Default)]
pub struct DuckDbDialect;

// In most cases the redshift dialect is identical to [`PostgresSqlDialect`].
impl Dialect for DuckDbDialect {
fn supports_trailing_commas(&self) -> bool {
true
fn flags(&self) -> DialectFlags {
DialectFlags {
supports_trailing_commas: true,
supports_filter_during_aggregation: true,
supports_group_by_expr: true,
supports_named_fn_args_with_eq_operator: true,
// DuckDB uses this syntax for `STRUCT`s.
//
// https://duckdb.org/docs/sql/data_types/struct.html#creating-structs
supports_dictionary_syntax: true,
// DuckDB uses this syntax for `MAP`s.
//
// https://duckdb.org/docs/sql/data_types/map.html#creating-maps
support_map_literal_syntax: true,
..Default::default()
}
}

fn is_identifier_start(&self, ch: char) -> bool {
Expand All @@ -29,30 +43,4 @@ impl Dialect for DuckDbDialect {
fn is_identifier_part(&self, ch: char) -> bool {
ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_'
}

fn supports_filter_during_aggregation(&self) -> bool {
true
}

fn supports_group_by_expr(&self) -> bool {
true
}

fn supports_named_fn_args_with_eq_operator(&self) -> bool {
true
}

// DuckDB uses this syntax for `STRUCT`s.
//
// https://duckdb.org/docs/sql/data_types/struct.html#creating-structs
fn supports_dictionary_syntax(&self) -> bool {
true
}

// DuckDB uses this syntax for `MAP`s.
//
// https://duckdb.org/docs/sql/data_types/map.html#creating-maps
fn support_map_literal_syntax(&self) -> bool {
true
}
}
77 changes: 20 additions & 57 deletions src/dialect/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::dialect::Dialect;
use crate::dialect::{Dialect, DialectFlags};

/// A permissive, general purpose [`Dialect`], which parses a wide variety of SQL
/// statements, from many different dialects.
#[derive(Debug, Default)]
pub struct GenericDialect;

impl Dialect for GenericDialect {
fn flags(&self) -> DialectFlags {
DialectFlags {
supports_unicode_string_literal: true,
supports_group_by_expr: true,
supports_connect_by: true,
supports_match_recognize: true,
supports_start_transaction_modifier: true,
supports_window_function_null_treatment_arg: true,
supports_dictionary_syntax: true,
supports_window_clause_named_window_reference: true,
supports_parenthesized_set_variables: true,
supports_select_wildcard_except: true,
support_map_literal_syntax: true,
allow_extract_custom: true,
allow_extract_single_quotes: true,
supports_create_index_with_clause: true,
..Default::default()
}
}
fn is_delimited_identifier_start(&self, ch: char) -> bool {
ch == '"' || ch == '`'
}
Expand All @@ -34,60 +53,4 @@ impl Dialect for GenericDialect {
|| ch == '#'
|| ch == '_'
}

fn supports_unicode_string_literal(&self) -> bool {
true
}

fn supports_group_by_expr(&self) -> bool {
true
}

fn supports_connect_by(&self) -> bool {
true
}

fn supports_match_recognize(&self) -> bool {
true
}

fn supports_start_transaction_modifier(&self) -> bool {
true
}

fn supports_window_function_null_treatment_arg(&self) -> bool {
true
}

fn supports_dictionary_syntax(&self) -> bool {
true
}

fn supports_window_clause_named_window_reference(&self) -> bool {
true
}

fn supports_parenthesized_set_variables(&self) -> bool {
true
}

fn supports_select_wildcard_except(&self) -> bool {
true
}

fn support_map_literal_syntax(&self) -> bool {
true
}

fn allow_extract_custom(&self) -> bool {
true
}

fn allow_extract_single_quotes(&self) -> bool {
true
}

fn supports_create_index_with_clause(&self) -> bool {
true
}
}
Loading
Loading