Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ pub enum DataType {
LongText,
/// String with optional length.
String(Option<u64>),
/// A data type with an explicit collation, as supported by Databricks.
Collate(Box<DataType>, ObjectName),
/// A fixed-length string e.g [ClickHouse][1].
///
/// [1]: https://clickhouse.com/docs/en/sql-reference/data-types/fixedstring
Expand Down Expand Up @@ -708,6 +710,9 @@ impl fmt::Display for DataType {
DataType::MediumText => write!(f, "MEDIUMTEXT"),
DataType::LongText => write!(f, "LONGTEXT"),
DataType::String(size) => format_type_with_optional_length(f, "STRING", size, false),
DataType::Collate(data_type, collation) => {
write!(f, "{data_type} COLLATE {collation}")
}
DataType::Bytea => write!(f, "BYTEA"),
DataType::Bit(size) => format_type_with_optional_length(f, "BIT", size, false),
DataType::BitVarying(size) => {
Expand Down
36 changes: 36 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ use crate::display_utils::{DisplayCommaSeparated, Indent, NewLine, SpaceOrNewlin
use crate::keywords::Keyword;
use crate::tokenizer::{Span, Token};

/// Databricks view schema adaptation mode.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum ViewSchemaMode {
/// Reject queries whose schema no longer matches the view definition.
Binding,
/// Apply safe casts to preserve the view schema.
Compensation,
/// Adapt the view schema to changes in the query result.
Evolution,
}

impl fmt::Display for ViewSchemaMode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match self {
Self::Binding => "BINDING",
Self::Compensation => "COMPENSATION",
Self::Evolution => "EVOLUTION",
})
}
}

/// Index column type.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -4380,6 +4403,10 @@ pub struct CreateView {
pub or_alter: bool,
/// The `OR REPLACE` clause is used to re-create the view if it already exists.
pub or_replace: bool,
/// Databricks `OR REFRESH` clause for materialized views.
pub or_refresh: bool,
/// Databricks view schema adaptation mode.
pub schema_mode: Option<ViewSchemaMode>,
/// if true, has MATERIALIZED view modifier
pub materialized: bool,
/// Snowflake: SECURE view modifier
Expand Down Expand Up @@ -4434,6 +4461,9 @@ impl fmt::Display for CreateView {
or_alter = if self.or_alter { "OR ALTER " } else { "" },
or_replace = if self.or_replace { "OR REPLACE " } else { "" },
)?;
if self.or_refresh {
f.write_str("OR REFRESH ")?;
}
if let Some(ref params) = self.params {
params.fmt(f)?;
}
Expand Down Expand Up @@ -4474,6 +4504,12 @@ impl fmt::Display for CreateView {
if let Some(ref comment) = self.comment {
write!(f, " COMMENT = '{}'", escape_single_quote_string(comment))?;
}
if matches!(self.options, CreateTableOptions::TableProperties(_)) {
write!(f, " {}", self.options)?;
}
if let Some(schema_mode) = &self.schema_mode {
write!(f, " WITH SCHEMA {schema_mode}")?;
}
if !self.cluster_by.is_empty() {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub use self::ddl::{
ReplicaIdentity, TagsColumnOption, TextSearchObjectType, TriggerObjectKind, Truncate,
UserDefinedTypeCompositeAttributeDef, UserDefinedTypeInternalLength,
UserDefinedTypeRangeOption, UserDefinedTypeRepresentation, UserDefinedTypeSqlDefinitionOption,
UserDefinedTypeStorage, ViewColumnDef, WithData,
UserDefinedTypeStorage, ViewColumnDef, ViewSchemaMode, WithData,
};
pub use self::dml::{
Delete, Insert, Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr,
Expand Down
32 changes: 32 additions & 0 deletions src/dialect/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ impl Dialect for DatabricksDialect {
true
}

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

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

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

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

fn supports_map_literal_with_angle_brackets(&self) -> bool {
true
}
Expand All @@ -122,6 +138,22 @@ impl Dialect for DatabricksDialect {
true
}

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

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

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

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

fn supports_select_wildcard_replace(&self) -> bool {
true
}
Expand Down
45 changes: 45 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,51 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if `CREATE VIEW` accepts `COMMENT '<text>'` without an
/// equals sign.
fn supports_create_view_comment_without_equals(&self) -> bool {
false
}

/// Returns true if this dialect supports typed column definitions in
/// `CREATE VIEW`, followed by ordinary column options.
///
/// Example:
/// ```sql
/// CREATE MATERIALIZED VIEW v (id BIGINT COMMENT 'identifier') AS SELECT 1;
/// ```
fn supports_typed_view_columns(&self) -> bool {
false
}

/// Returns true if `CREATE VIEW` accepts a `TBLPROPERTIES` clause.
fn supports_create_view_table_properties(&self) -> bool {
false
}

/// Returns true if the dialect supports `CREATE OR REFRESH` for
/// materialized views and streaming tables.
fn supports_create_or_refresh(&self) -> bool {
false
}

/// Returns true if `TABLE` queries accept names with more than two parts.
fn supports_multipart_table_query_name(&self) -> bool {
false
}

/// Returns true if views accept `WITH SCHEMA BINDING`, `WITH SCHEMA
/// COMPENSATION`, or `WITH SCHEMA EVOLUTION` before `AS`.
fn supports_create_view_schema_mode(&self) -> bool {
false
}

/// Returns true if a data type can carry a collation, including inside a
/// nested type such as `MAP<STRING COLLATE UTF8_BINARY, STRING>`.
fn supports_data_type_collation(&self) -> bool {
false
}

/// Returns true if this dialect supports the `ARRAY` type without
/// specifying an element type.
///
Expand Down
2 changes: 2 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ define_keywords!(
COMMITTED,
COMMUTATOR,
COMPATIBLE,
COMPENSATION,
COMPRESS,
COMPRESSION,
COMPUPDATE,
Expand Down Expand Up @@ -392,6 +393,7 @@ define_keywords!(
EVEN,
EVENT,
EVERY,
EVOLUTION,
EVOLVE,
EXCEPT,
EXCEPTION,
Expand Down
Loading
Loading