Skip to content

Commit f16ee64

Browse files
committed
Merge branch 'main' of github.com:hansott/datafusion-sqlparser-rs into escape-literals
* 'main' of github.com:hansott/datafusion-sqlparser-rs: National strings: check if dialect supports backslash escape (apache#1672) Add support for Create Iceberg Table statement for Snowflake parser (apache#1664) Add support for Snowflake account privileges (apache#1666) Update rat_exclude_file.txt (apache#1670) Update verson to 0.54.0 and update changelog (apache#1668) Add support for Snowflake AT/BEFORE (apache#1667) Add support for qualified column names in JOIN ... USING (apache#1663) Add support for `IS [NOT] [form] NORMALIZED` (apache#1655) fix parsing of `INSERT INTO ... SELECT ... RETURNING ` (apache#1661) Add support for Snowflake column aliases that use SQL keywords (apache#1632)
2 parents 2588a2e + 4f71542 commit f16ee64

23 files changed

+1555
-171
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
-->
1919

2020
# Changelog
21-
All notable changes to this project will be documented in this file.
21+
All notable changes to this project will be documented in one of the linked
22+
files.
2223

2324
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
25+
2426
Given that the parser produces a typed AST, any changes to the AST will
2527
technically be breaking and thus will result in a `0.(N+1)` version.
2628

2729

2830
- Unreleased: Check https://github.com/sqlparser-rs/sqlparser-rs/commits/main for undocumented changes.
31+
- `0.54.0`: [changelog/0.54.0.md](changelog/0.54.0.md)
32+
- `0.53.0`: [changelog/0.53.0.md](changelog/0.53.0.md)
2933
- `0.52.0`: [changelog/0.52.0.md](changelog/0.52.0.md)
3034
- `0.51.0` and earlier: [changelog/0.51.0-pre.md](changelog/0.51.0-pre.md)

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[package]
1919
name = "sqlparser"
2020
description = "Extensible SQL Lexer and Parser with support for ANSI SQL:2011"
21-
version = "0.53.0"
21+
version = "0.54.0"
2222
authors = ["Apache DataFusion <dev@datafusion.apache.org>"]
2323
homepage = "https://github.com/apache/datafusion-sqlparser-rs"
2424
documentation = "https://docs.rs/sqlparser/"

changelog/0.54.0.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# sqlparser-rs 0.54.0 Changelog
21+
22+
This release consists of 57 commits from 24 contributors. See credits at the end of this changelog for more information.
23+
24+
**Implemented enhancements:**
25+
26+
- feat: support `INSERT INTO [TABLE] FUNCTION` of Clickhouse [#1633](https://github.com/apache/datafusion-sqlparser-rs/pull/1633) (byte-sourcerer)
27+
28+
**Other:**
29+
30+
- Run cargo fmt on `derive` crate [#1595](https://github.com/apache/datafusion-sqlparser-rs/pull/1595) (alamb)
31+
- Add Apache license header to spans.rs [#1594](https://github.com/apache/datafusion-sqlparser-rs/pull/1594) (alamb)
32+
- Add support for BigQuery `ANY TYPE` data type [#1602](https://github.com/apache/datafusion-sqlparser-rs/pull/1602) (MartinSahlen)
33+
- Add support for TABLESAMPLE [#1580](https://github.com/apache/datafusion-sqlparser-rs/pull/1580) (yoavcloud)
34+
- Redshift: Fix parsing for quoted numbered columns [#1576](https://github.com/apache/datafusion-sqlparser-rs/pull/1576) (7phs)
35+
- Add the alter table ON COMMIT option to Snowflake [#1606](https://github.com/apache/datafusion-sqlparser-rs/pull/1606) (yoavcloud)
36+
- Support parsing `EXPLAIN ESTIMATE` of Clickhouse [#1605](https://github.com/apache/datafusion-sqlparser-rs/pull/1605) (byte-sourcerer)
37+
- Fix BigQuery hyphenated ObjectName with numbers [#1598](https://github.com/apache/datafusion-sqlparser-rs/pull/1598) (ayman-sigma)
38+
- Fix test compilation issue [#1609](https://github.com/apache/datafusion-sqlparser-rs/pull/1609) (iffyio)
39+
- Allow foreign table constraint without columns [#1608](https://github.com/apache/datafusion-sqlparser-rs/pull/1608) (ramnivas)
40+
- Support optional table for `ANALYZE` statement [#1599](https://github.com/apache/datafusion-sqlparser-rs/pull/1599) (yuyang-ok)
41+
- Support DOUBLE data types with precision for Mysql [#1611](https://github.com/apache/datafusion-sqlparser-rs/pull/1611) (artorias1024)
42+
- Add `#[recursive]` [#1522](https://github.com/apache/datafusion-sqlparser-rs/pull/1522) (blaginin)
43+
- Support arbitrary composite access expressions [#1600](https://github.com/apache/datafusion-sqlparser-rs/pull/1600) (ayman-sigma)
44+
- Consolidate `MapAccess`, and `Subscript` into `CompoundExpr` to handle the complex field access chain [#1551](https://github.com/apache/datafusion-sqlparser-rs/pull/1551) (goldmedal)
45+
- Handle empty projection in Postgres SELECT statements [#1613](https://github.com/apache/datafusion-sqlparser-rs/pull/1613) (tobyhede)
46+
- Merge composite and compound expr test cases [#1615](https://github.com/apache/datafusion-sqlparser-rs/pull/1615) (iffyio)
47+
- Support Snowflake Update-From-Select [#1604](https://github.com/apache/datafusion-sqlparser-rs/pull/1604) (yuval-illumex)
48+
- Improve parsing performance by reducing token cloning [#1587](https://github.com/apache/datafusion-sqlparser-rs/pull/1587) (davisp)
49+
- Improve Parser documentation [#1617](https://github.com/apache/datafusion-sqlparser-rs/pull/1617) (alamb)
50+
- Add support for DROP EXTENSION [#1610](https://github.com/apache/datafusion-sqlparser-rs/pull/1610) (ramnivas)
51+
- Refactor advancing token to avoid duplication, avoid borrow checker issues [#1618](https://github.com/apache/datafusion-sqlparser-rs/pull/1618) (alamb)
52+
- Fix the parsing result for the special double number [#1621](https://github.com/apache/datafusion-sqlparser-rs/pull/1621) (goldmedal)
53+
- SQLite: Allow dollar signs in placeholder names [#1620](https://github.com/apache/datafusion-sqlparser-rs/pull/1620) (hansott)
54+
- Improve error for an unexpected token after DROP [#1623](https://github.com/apache/datafusion-sqlparser-rs/pull/1623) (ramnivas)
55+
- Fix `sqlparser_bench` benchmark compilation [#1625](https://github.com/apache/datafusion-sqlparser-rs/pull/1625) (alamb)
56+
- Improve parsing speed by avoiding some clones in parse_identifier [#1624](https://github.com/apache/datafusion-sqlparser-rs/pull/1624) (alamb)
57+
- Simplify `parse_keyword_apis` more [#1626](https://github.com/apache/datafusion-sqlparser-rs/pull/1626) (alamb)
58+
- Test benchmarks and Improve benchmark README.md [#1627](https://github.com/apache/datafusion-sqlparser-rs/pull/1627) (alamb)
59+
- Add support for MYSQL's `RENAME TABLE` [#1616](https://github.com/apache/datafusion-sqlparser-rs/pull/1616) (wugeer)
60+
- Correctly tokenize nested comments [#1629](https://github.com/apache/datafusion-sqlparser-rs/pull/1629) (hansott)
61+
- Add support for USE SECONDARY ROLE (vs. ROLES) [#1637](https://github.com/apache/datafusion-sqlparser-rs/pull/1637) (yoavcloud)
62+
- Add support for various Snowflake grantees [#1640](https://github.com/apache/datafusion-sqlparser-rs/pull/1640) (yoavcloud)
63+
- Add support for the SQL OVERLAPS predicate [#1638](https://github.com/apache/datafusion-sqlparser-rs/pull/1638) (yoavcloud)
64+
- Add support for Snowflake LIST and REMOVE [#1639](https://github.com/apache/datafusion-sqlparser-rs/pull/1639) (yoavcloud)
65+
- Add support for MySQL's INSERT INTO ... SET syntax [#1641](https://github.com/apache/datafusion-sqlparser-rs/pull/1641) (yoavcloud)
66+
- Start new line if \r in Postgres dialect [#1647](https://github.com/apache/datafusion-sqlparser-rs/pull/1647) (hansott)
67+
- Support pluralized time units [#1630](https://github.com/apache/datafusion-sqlparser-rs/pull/1630) (wugeer)
68+
- Replace `ReferentialAction` enum in `DROP` statements [#1648](https://github.com/apache/datafusion-sqlparser-rs/pull/1648) (stepancheg)
69+
- Add support for MS-SQL BEGIN/END TRY/CATCH [#1649](https://github.com/apache/datafusion-sqlparser-rs/pull/1649) (yoavcloud)
70+
- Fix MySQL parsing of GRANT, REVOKE, and CREATE VIEW [#1538](https://github.com/apache/datafusion-sqlparser-rs/pull/1538) (mvzink)
71+
- Add support for the Snowflake MINUS set operator [#1652](https://github.com/apache/datafusion-sqlparser-rs/pull/1652) (yoavcloud)
72+
- ALTER TABLE DROP {COLUMN|CONSTRAINT} RESTRICT [#1651](https://github.com/apache/datafusion-sqlparser-rs/pull/1651) (stepancheg)
73+
- Add support for ClickHouse `FORMAT` on `INSERT` [#1628](https://github.com/apache/datafusion-sqlparser-rs/pull/1628) (bombsimon)
74+
- MsSQL SET for session params [#1646](https://github.com/apache/datafusion-sqlparser-rs/pull/1646) (yoavcloud)
75+
- Correctly look for end delimiter dollar quoted string [#1650](https://github.com/apache/datafusion-sqlparser-rs/pull/1650) (hansott)
76+
- Support single line comments starting with '#' for Hive [#1654](https://github.com/apache/datafusion-sqlparser-rs/pull/1654) (wugeer)
77+
- Support trailing commas in `FROM` clause [#1645](https://github.com/apache/datafusion-sqlparser-rs/pull/1645) (barsela1)
78+
- Allow empty options for BigQuery [#1657](https://github.com/apache/datafusion-sqlparser-rs/pull/1657) (MartinSahlen)
79+
- Add support for parsing RAISERROR [#1656](https://github.com/apache/datafusion-sqlparser-rs/pull/1656) (AvivDavid-Satori)
80+
- Add support for Snowflake column aliases that use SQL keywords [#1632](https://github.com/apache/datafusion-sqlparser-rs/pull/1632) (yoavcloud)
81+
- fix parsing of `INSERT INTO ... SELECT ... RETURNING ` [#1661](https://github.com/apache/datafusion-sqlparser-rs/pull/1661) (lovasoa)
82+
- Add support for `IS [NOT] [form] NORMALIZED` [#1655](https://github.com/apache/datafusion-sqlparser-rs/pull/1655) (alexander-beedie)
83+
- Add support for qualified column names in JOIN ... USING [#1663](https://github.com/apache/datafusion-sqlparser-rs/pull/1663) (yoavcloud)
84+
- Add support for Snowflake AT/BEFORE [#1667](https://github.com/apache/datafusion-sqlparser-rs/pull/1667) (yoavcloud)
85+
86+
## Credits
87+
88+
Thank you to everyone who contributed to this release. Here is a breakdown of commits (PRs merged) per contributor.
89+
90+
```
91+
13 Yoav Cohen
92+
9 Andrew Lamb
93+
4 Hans Ott
94+
3 Ramnivas Laddad
95+
3 wugeer
96+
2 Ayman Elkfrawy
97+
2 Ifeanyi Ubah
98+
2 Jax Liu
99+
2 Martin Abelson Sahlen
100+
2 Stepan Koltsov
101+
2 cjw
102+
1 Aleksei Piianin
103+
1 Alexander Beedie
104+
1 AvivDavid-Satori
105+
1 Dmitrii Blaginin
106+
1 Michael Victor Zink
107+
1 Ophir LOJKINE
108+
1 Paul J. Davis
109+
1 Simon Sawert
110+
1 Toby Hede
111+
1 Yuval Shkolar
112+
1 artorias1024
113+
1 bar sela
114+
1 yuyang
115+
```
116+
117+
Thank you also to everyone who contributed in other ways such as filing issues, reviewing PRs, and providing feedback on this release.
118+

dev/release/rat_exclude_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
.tool-versions
44
dev/release/rat_exclude_files.txt
55
fuzz/.gitignore
6+
sqlparser_bench/img/flamegraph.svg
67

src/ast/dml.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ use super::{
3636
CommentDef, Expr, FileFormat, FromTable, HiveDistributionStyle, HiveFormat, HiveIOFormat,
3737
HiveRowFormat, Ident, InsertAliases, MysqlInsertPriority, ObjectName, OnCommit, OnInsert,
3838
OneOrManyWithParens, OrderByExpr, Query, RowAccessPolicy, SelectItem, Setting, SqlOption,
39-
SqliteOnConflict, TableEngine, TableObject, TableWithJoins, Tag, WrappedCollection,
39+
SqliteOnConflict, StorageSerializationPolicy, TableEngine, TableObject, TableWithJoins, Tag,
40+
WrappedCollection,
4041
};
4142

4243
/// CREATE INDEX statement.
@@ -117,6 +118,7 @@ pub struct CreateTable {
117118
pub if_not_exists: bool,
118119
pub transient: bool,
119120
pub volatile: bool,
121+
pub iceberg: bool,
120122
/// Table name
121123
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
122124
pub name: ObjectName,
@@ -192,6 +194,21 @@ pub struct CreateTable {
192194
/// Snowflake "WITH TAG" clause
193195
/// <https://docs.snowflake.com/en/sql-reference/sql/create-table>
194196
pub with_tags: Option<Vec<Tag>>,
197+
/// Snowflake "EXTERNAL_VOLUME" clause for Iceberg tables
198+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
199+
pub external_volume: Option<String>,
200+
/// Snowflake "BASE_LOCATION" clause for Iceberg tables
201+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
202+
pub base_location: Option<String>,
203+
/// Snowflake "CATALOG" clause for Iceberg tables
204+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
205+
pub catalog: Option<String>,
206+
/// Snowflake "CATALOG_SYNC" clause for Iceberg tables
207+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
208+
pub catalog_sync: Option<String>,
209+
/// Snowflake "STORAGE_SERIALIZATION_POLICY" clause for Iceberg tables
210+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
211+
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
195212
}
196213

197214
impl Display for CreateTable {
@@ -205,7 +222,7 @@ impl Display for CreateTable {
205222
// `CREATE TABLE t (a INT) AS SELECT a from t2`
206223
write!(
207224
f,
208-
"CREATE {or_replace}{external}{global}{temporary}{transient}{volatile}TABLE {if_not_exists}{name}",
225+
"CREATE {or_replace}{external}{global}{temporary}{transient}{volatile}{iceberg}TABLE {if_not_exists}{name}",
209226
or_replace = if self.or_replace { "OR REPLACE " } else { "" },
210227
external = if self.external { "EXTERNAL " } else { "" },
211228
global = self.global
@@ -221,6 +238,8 @@ impl Display for CreateTable {
221238
temporary = if self.temporary { "TEMPORARY " } else { "" },
222239
transient = if self.transient { "TRANSIENT " } else { "" },
223240
volatile = if self.volatile { "VOLATILE " } else { "" },
241+
// Only for Snowflake
242+
iceberg = if self.iceberg { "ICEBERG " } else { "" },
224243
name = self.name,
225244
)?;
226245
if let Some(on_cluster) = &self.on_cluster {
@@ -382,6 +401,31 @@ impl Display for CreateTable {
382401
)?;
383402
}
384403

404+
if let Some(external_volume) = self.external_volume.as_ref() {
405+
write!(f, " EXTERNAL_VOLUME = '{external_volume}'")?;
406+
}
407+
408+
if let Some(catalog) = self.catalog.as_ref() {
409+
write!(f, " CATALOG = '{catalog}'")?;
410+
}
411+
412+
if self.iceberg {
413+
if let Some(base_location) = self.base_location.as_ref() {
414+
write!(f, " BASE_LOCATION = '{base_location}'")?;
415+
}
416+
}
417+
418+
if let Some(catalog_sync) = self.catalog_sync.as_ref() {
419+
write!(f, " CATALOG_SYNC = '{catalog_sync}'")?;
420+
}
421+
422+
if let Some(storage_serialization_policy) = self.storage_serialization_policy.as_ref() {
423+
write!(
424+
f,
425+
" STORAGE_SERIALIZATION_POLICY = {storage_serialization_policy}"
426+
)?;
427+
}
428+
385429
if self.copy_grants {
386430
write!(f, " COPY GRANTS")?;
387431
}

src/ast/helpers/stmt_create_table.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::super::dml::CreateTable;
2828
use crate::ast::{
2929
ClusteredBy, ColumnDef, CommentDef, Expr, FileFormat, HiveDistributionStyle, HiveFormat, Ident,
3030
ObjectName, OnCommit, OneOrManyWithParens, Query, RowAccessPolicy, SqlOption, Statement,
31-
TableConstraint, TableEngine, Tag, WrappedCollection,
31+
StorageSerializationPolicy, TableConstraint, TableEngine, Tag, WrappedCollection,
3232
};
3333
use crate::parser::ParserError;
3434

@@ -71,6 +71,7 @@ pub struct CreateTableBuilder {
7171
pub if_not_exists: bool,
7272
pub transient: bool,
7373
pub volatile: bool,
74+
pub iceberg: bool,
7475
pub name: ObjectName,
7576
pub columns: Vec<ColumnDef>,
7677
pub constraints: Vec<TableConstraint>,
@@ -107,6 +108,11 @@ pub struct CreateTableBuilder {
107108
pub with_aggregation_policy: Option<ObjectName>,
108109
pub with_row_access_policy: Option<RowAccessPolicy>,
109110
pub with_tags: Option<Vec<Tag>>,
111+
pub base_location: Option<String>,
112+
pub external_volume: Option<String>,
113+
pub catalog: Option<String>,
114+
pub catalog_sync: Option<String>,
115+
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
110116
}
111117

112118
impl CreateTableBuilder {
@@ -119,6 +125,7 @@ impl CreateTableBuilder {
119125
if_not_exists: false,
120126
transient: false,
121127
volatile: false,
128+
iceberg: false,
122129
name,
123130
columns: vec![],
124131
constraints: vec![],
@@ -155,6 +162,11 @@ impl CreateTableBuilder {
155162
with_aggregation_policy: None,
156163
with_row_access_policy: None,
157164
with_tags: None,
165+
base_location: None,
166+
external_volume: None,
167+
catalog: None,
168+
catalog_sync: None,
169+
storage_serialization_policy: None,
158170
}
159171
}
160172
pub fn or_replace(mut self, or_replace: bool) -> Self {
@@ -192,6 +204,11 @@ impl CreateTableBuilder {
192204
self
193205
}
194206

207+
pub fn iceberg(mut self, iceberg: bool) -> Self {
208+
self.iceberg = iceberg;
209+
self
210+
}
211+
195212
pub fn columns(mut self, columns: Vec<ColumnDef>) -> Self {
196213
self.columns = columns;
197214
self
@@ -371,6 +388,34 @@ impl CreateTableBuilder {
371388
self
372389
}
373390

391+
pub fn base_location(mut self, base_location: Option<String>) -> Self {
392+
self.base_location = base_location;
393+
self
394+
}
395+
396+
pub fn external_volume(mut self, external_volume: Option<String>) -> Self {
397+
self.external_volume = external_volume;
398+
self
399+
}
400+
401+
pub fn catalog(mut self, catalog: Option<String>) -> Self {
402+
self.catalog = catalog;
403+
self
404+
}
405+
406+
pub fn catalog_sync(mut self, catalog_sync: Option<String>) -> Self {
407+
self.catalog_sync = catalog_sync;
408+
self
409+
}
410+
411+
pub fn storage_serialization_policy(
412+
mut self,
413+
storage_serialization_policy: Option<StorageSerializationPolicy>,
414+
) -> Self {
415+
self.storage_serialization_policy = storage_serialization_policy;
416+
self
417+
}
418+
374419
pub fn build(self) -> Statement {
375420
Statement::CreateTable(CreateTable {
376421
or_replace: self.or_replace,
@@ -380,6 +425,7 @@ impl CreateTableBuilder {
380425
if_not_exists: self.if_not_exists,
381426
transient: self.transient,
382427
volatile: self.volatile,
428+
iceberg: self.iceberg,
383429
name: self.name,
384430
columns: self.columns,
385431
constraints: self.constraints,
@@ -416,6 +462,11 @@ impl CreateTableBuilder {
416462
with_aggregation_policy: self.with_aggregation_policy,
417463
with_row_access_policy: self.with_row_access_policy,
418464
with_tags: self.with_tags,
465+
base_location: self.base_location,
466+
external_volume: self.external_volume,
467+
catalog: self.catalog,
468+
catalog_sync: self.catalog_sync,
469+
storage_serialization_policy: self.storage_serialization_policy,
419470
})
420471
}
421472
}
@@ -435,6 +486,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
435486
if_not_exists,
436487
transient,
437488
volatile,
489+
iceberg,
438490
name,
439491
columns,
440492
constraints,
@@ -471,6 +523,11 @@ impl TryFrom<Statement> for CreateTableBuilder {
471523
with_aggregation_policy,
472524
with_row_access_policy,
473525
with_tags,
526+
base_location,
527+
external_volume,
528+
catalog,
529+
catalog_sync,
530+
storage_serialization_policy,
474531
}) => Ok(Self {
475532
or_replace,
476533
temporary,
@@ -505,6 +562,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
505562
clustered_by,
506563
options,
507564
strict,
565+
iceberg,
508566
copy_grants,
509567
enable_schema_evolution,
510568
change_tracking,
@@ -515,6 +573,11 @@ impl TryFrom<Statement> for CreateTableBuilder {
515573
with_row_access_policy,
516574
with_tags,
517575
volatile,
576+
base_location,
577+
external_volume,
578+
catalog,
579+
catalog_sync,
580+
storage_serialization_policy,
518581
}),
519582
_ => Err(ParserError::ParserError(format!(
520583
"Expected create table statement, but received: {stmt}"

0 commit comments

Comments
 (0)