Skip to content

Commit 68c41d3

Browse files
committed
Merge branch 'main' into sql-pipe-operator-part1
2 parents e4ef3cf + 81d8909 commit 68c41d3

31 files changed

+4000
-1129
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ $ cargo run --features json_example --example cli FILENAME.sql [--dialectname]
156156
## Users
157157

158158
This parser is currently being used by the [DataFusion] query engine, [LocustDB],
159-
[Ballista], [GlueSQL], [Opteryx], [Polars], [PRQL], [Qrlew], [JumpWire], and [ParadeDB].
159+
[Ballista], [GlueSQL], [Opteryx], [Polars], [PRQL], [Qrlew], [JumpWire], [ParadeDB], [CipherStash Proxy],
160+
and [GreptimeDB].
160161

161162
If your project is using sqlparser-rs feel free to make a PR to add it
162163
to this list.
@@ -275,3 +276,5 @@ licensed as above, without any additional terms or conditions.
275276
[sql-standard]: https://en.wikipedia.org/wiki/ISO/IEC_9075
276277
[`Dialect`]: https://docs.rs/sqlparser/latest/sqlparser/dialect/trait.Dialect.html
277278
[`GenericDialect`]: https://docs.rs/sqlparser/latest/sqlparser/dialect/struct.GenericDialect.html
279+
[CipherStash Proxy]: https://github.com/cipherstash/proxy
280+
[GreptimeDB]: https://github.com/GreptimeTeam/greptimedb

src/ast/data_type.rs

Lines changed: 219 additions & 177 deletions
Large diffs are not rendered by default.

src/ast/ddl.rs

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,18 @@ pub enum AlterTableOperation {
151151
},
152152
/// `DROP PRIMARY KEY`
153153
///
154-
/// Note: this is a MySQL-specific operation.
154+
/// Note: this is a [MySQL]-specific operation.
155+
///
156+
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
155157
DropPrimaryKey,
158+
/// `DROP FOREIGN KEY <fk_symbol>`
159+
///
160+
/// Note: this is a [MySQL]-specific operation.
161+
///
162+
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
163+
DropForeignKey {
164+
name: Ident,
165+
},
156166
/// `ENABLE ALWAYS RULE rewrite_rule_name`
157167
///
158168
/// Note: this is a PostgreSQL-specific operation.
@@ -278,6 +288,16 @@ pub enum AlterTableOperation {
278288
equals: bool,
279289
algorithm: AlterTableAlgorithm,
280290
},
291+
292+
/// `LOCK [=] { DEFAULT | NONE | SHARED | EXCLUSIVE }`
293+
///
294+
/// [MySQL]-specific table alter lock.
295+
///
296+
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
297+
Lock {
298+
equals: bool,
299+
lock: AlterTableLock,
300+
},
281301
/// `AUTO_INCREMENT [=] <value>`
282302
///
283303
/// [MySQL]-specific table option for raising current auto increment value.
@@ -356,6 +376,30 @@ impl fmt::Display for AlterTableAlgorithm {
356376
}
357377
}
358378

379+
/// [MySQL] `ALTER TABLE` lock.
380+
///
381+
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
382+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
383+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
384+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
385+
pub enum AlterTableLock {
386+
Default,
387+
None,
388+
Shared,
389+
Exclusive,
390+
}
391+
392+
impl fmt::Display for AlterTableLock {
393+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
394+
f.write_str(match self {
395+
Self::Default => "DEFAULT",
396+
Self::None => "NONE",
397+
Self::Shared => "SHARED",
398+
Self::Exclusive => "EXCLUSIVE",
399+
})
400+
}
401+
}
402+
359403
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
360404
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
361405
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -530,6 +574,7 @@ impl fmt::Display for AlterTableOperation {
530574
)
531575
}
532576
AlterTableOperation::DropPrimaryKey => write!(f, "DROP PRIMARY KEY"),
577+
AlterTableOperation::DropForeignKey { name } => write!(f, "DROP FOREIGN KEY {name}"),
533578
AlterTableOperation::DropColumn {
534579
column_name,
535580
if_exists,
@@ -681,6 +726,9 @@ impl fmt::Display for AlterTableOperation {
681726
value
682727
)
683728
}
729+
AlterTableOperation::Lock { equals, lock } => {
730+
write!(f, "LOCK {}{}", if *equals { "= " } else { "" }, lock)
731+
}
684732
}
685733
}
686734
}
@@ -820,7 +868,7 @@ impl fmt::Display for AlterColumnOperation {
820868
AlterColumnOperation::SetDefault { value } => {
821869
write!(f, "SET DEFAULT {value}")
822870
}
823-
AlterColumnOperation::DropDefault {} => {
871+
AlterColumnOperation::DropDefault => {
824872
write!(f, "DROP DEFAULT")
825873
}
826874
AlterColumnOperation::SetDataType { data_type, using } => {
@@ -1228,9 +1276,9 @@ impl fmt::Display for IndexOption {
12281276
}
12291277
}
12301278

1231-
/// [Postgres] unique index nulls handling option: `[ NULLS [ NOT ] DISTINCT ]`
1279+
/// [PostgreSQL] unique index nulls handling option: `[ NULLS [ NOT ] DISTINCT ]`
12321280
///
1233-
/// [Postgres]: https://www.postgresql.org/docs/17/sql-altertable.html
1281+
/// [PostgreSQL]: https://www.postgresql.org/docs/17/sql-altertable.html
12341282
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12351283
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12361284
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -2127,15 +2175,15 @@ pub struct CreateFunction {
21272175
///
21282176
/// IMMUTABLE | STABLE | VOLATILE
21292177
///
2130-
/// [Postgres](https://www.postgresql.org/docs/current/sql-createfunction.html)
2178+
/// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createfunction.html)
21312179
pub behavior: Option<FunctionBehavior>,
21322180
/// CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
21332181
///
2134-
/// [Postgres](https://www.postgresql.org/docs/current/sql-createfunction.html)
2182+
/// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createfunction.html)
21352183
pub called_on_null: Option<FunctionCalledOnNull>,
21362184
/// PARALLEL { UNSAFE | RESTRICTED | SAFE }
21372185
///
2138-
/// [Postgres](https://www.postgresql.org/docs/current/sql-createfunction.html)
2186+
/// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createfunction.html)
21392187
pub parallel: Option<FunctionParallel>,
21402188
/// USING ... (Hive only)
21412189
pub using: Option<CreateFunctionUsing>,

src/ast/dml.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ pub struct CreateTable {
182182
/// BigQuery: Table options list.
183183
/// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
184184
pub options: Option<Vec<SqlOption>>,
185+
/// Postgres `INHERITs` clause, which contains the list of tables from which
186+
/// the new table inherits.
187+
/// <https://www.postgresql.org/docs/current/ddl-inherit.html>
188+
/// <https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-INHERITS>
189+
pub inherits: Option<Vec<ObjectName>>,
185190
/// SQLite "STRICT" clause.
186191
/// if the "STRICT" table-option keyword is added to the end, after the closing ")",
187192
/// then strict typing rules apply to that table.
@@ -405,6 +410,9 @@ impl Display for CreateTable {
405410
if let Some(order_by) = &self.order_by {
406411
write!(f, " ORDER BY {}", order_by)?;
407412
}
413+
if let Some(inherits) = &self.inherits {
414+
write!(f, " INHERITS ({})", display_comma_separated(inherits))?;
415+
}
408416
if let Some(partition_by) = self.partition_by.as_ref() {
409417
write!(f, " PARTITION BY {partition_by}")?;
410418
}

src/ast/helpers/stmt_create_table.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub struct CreateTableBuilder {
9797
pub cluster_by: Option<WrappedCollection<Vec<Ident>>>,
9898
pub clustered_by: Option<ClusteredBy>,
9999
pub options: Option<Vec<SqlOption>>,
100+
pub inherits: Option<Vec<ObjectName>>,
100101
pub strict: bool,
101102
pub copy_grants: bool,
102103
pub enable_schema_evolution: Option<bool>,
@@ -151,6 +152,7 @@ impl CreateTableBuilder {
151152
cluster_by: None,
152153
clustered_by: None,
153154
options: None,
155+
inherits: None,
154156
strict: false,
155157
copy_grants: false,
156158
enable_schema_evolution: None,
@@ -331,6 +333,11 @@ impl CreateTableBuilder {
331333
self
332334
}
333335

336+
pub fn inherits(mut self, inherits: Option<Vec<ObjectName>>) -> Self {
337+
self.inherits = inherits;
338+
self
339+
}
340+
334341
pub fn strict(mut self, strict: bool) -> Self {
335342
self.strict = strict;
336343
self
@@ -451,6 +458,7 @@ impl CreateTableBuilder {
451458
cluster_by: self.cluster_by,
452459
clustered_by: self.clustered_by,
453460
options: self.options,
461+
inherits: self.inherits,
454462
strict: self.strict,
455463
copy_grants: self.copy_grants,
456464
enable_schema_evolution: self.enable_schema_evolution,
@@ -512,6 +520,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
512520
cluster_by,
513521
clustered_by,
514522
options,
523+
inherits,
515524
strict,
516525
copy_grants,
517526
enable_schema_evolution,
@@ -560,6 +569,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
560569
cluster_by,
561570
clustered_by,
562571
options,
572+
inherits,
563573
strict,
564574
iceberg,
565575
copy_grants,
@@ -591,6 +601,7 @@ pub(crate) struct CreateTableConfiguration {
591601
pub partition_by: Option<Box<Expr>>,
592602
pub cluster_by: Option<WrappedCollection<Vec<Ident>>>,
593603
pub options: Option<Vec<SqlOption>>,
604+
pub inherits: Option<Vec<ObjectName>>,
594605
}
595606

596607
#[cfg(test)]

src/ast/helpers/stmt_data_loading.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use core::fmt;
2929
use serde::{Deserialize, Serialize};
3030

3131
use crate::ast::helpers::key_value_options::KeyValueOptions;
32-
use crate::ast::{Ident, ObjectName};
32+
use crate::ast::{Ident, ObjectName, SelectItem};
3333
#[cfg(feature = "visitor")]
3434
use sqlparser_derive::{Visit, VisitMut};
3535

@@ -44,6 +44,25 @@ pub struct StageParamsObject {
4444
pub credentials: KeyValueOptions,
4545
}
4646

47+
/// This enum enables support for both standard SQL select item expressions
48+
/// and Snowflake-specific ones for data loading.
49+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
50+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
51+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
52+
pub enum StageLoadSelectItemKind {
53+
SelectItem(SelectItem),
54+
StageLoadSelectItem(StageLoadSelectItem),
55+
}
56+
57+
impl fmt::Display for StageLoadSelectItemKind {
58+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59+
match &self {
60+
StageLoadSelectItemKind::SelectItem(item) => write!(f, "{item}"),
61+
StageLoadSelectItemKind::StageLoadSelectItem(item) => write!(f, "{item}"),
62+
}
63+
}
64+
}
65+
4766
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
4867
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4968
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]

0 commit comments

Comments
 (0)