mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-12 06:52:02 +00:00
Add support for DuckDB struct literal syntax (#1194)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
4472789171
commit
e747c9c2af
3 changed files with 158 additions and 0 deletions
|
@ -347,6 +347,23 @@ impl fmt::Display for StructField {
|
|||
}
|
||||
}
|
||||
|
||||
/// A dictionary field within a dictionary.
|
||||
///
|
||||
/// [duckdb]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct DictionaryField {
|
||||
pub key: Ident,
|
||||
pub value: Box<Expr>,
|
||||
}
|
||||
|
||||
impl fmt::Display for DictionaryField {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}: {}", self.key, self.value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Options for `CAST` / `TRY_CAST`
|
||||
/// BigQuery: <https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#formatting_syntax>
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
|
@ -687,6 +704,14 @@ pub enum Expr {
|
|||
expr: Box<Expr>,
|
||||
name: Ident,
|
||||
},
|
||||
/// `DuckDB` specific `Struct` literal expression [1]
|
||||
///
|
||||
/// Syntax:
|
||||
/// ```sql
|
||||
/// syntax: {'field_name': expr1[, ... ]}
|
||||
/// ```
|
||||
/// [1]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
|
||||
Dictionary(Vec<DictionaryField>),
|
||||
/// An array index expression e.g. `(ARRAY[1, 2])[1]` or `(current_schemas(FALSE))[1]`
|
||||
ArrayIndex {
|
||||
obj: Box<Expr>,
|
||||
|
@ -1146,6 +1171,9 @@ impl fmt::Display for Expr {
|
|||
Expr::Named { expr, name } => {
|
||||
write!(f, "{} AS {}", expr, name)
|
||||
}
|
||||
Expr::Dictionary(fields) => {
|
||||
write!(f, "{{{}}}", display_comma_separated(fields))
|
||||
}
|
||||
Expr::ArrayIndex { obj, indexes } => {
|
||||
write!(f, "{obj}")?;
|
||||
for i in indexes {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue