Skip to content

Commit 57c822b

Browse files
Box every Statement variant payload
1 parent 560a13c commit 57c822b

24 files changed

Lines changed: 5874 additions & 4603 deletions

‎src/ast/dcl.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! (commonly referred to as Data Control Language, or DCL)
2020
2121
#[cfg(not(feature = "std"))]
22-
use alloc::vec::Vec;
22+
use alloc::{boxed::Box, vec::Vec};
2323
use core::fmt;
2424

2525
#[cfg(feature = "serde")]
@@ -482,7 +482,7 @@ impl fmt::Display for Grant {
482482

483483
impl From<Grant> for crate::ast::Statement {
484484
fn from(v: Grant) -> Self {
485-
crate::ast::Statement::Grant(v)
485+
crate::ast::Statement::Grant(Box::new(v))
486486
}
487487
}
488488

@@ -532,6 +532,6 @@ impl fmt::Display for Revoke {
532532

533533
impl From<Revoke> for crate::ast::Statement {
534534
fn from(v: Revoke) -> Self {
535-
crate::ast::Statement::Revoke(v)
535+
crate::ast::Statement::Revoke(Box::new(v))
536536
}
537537
}

‎src/ast/ddl.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5960,13 +5960,13 @@ impl fmt::Display for DropPolicy {
59605960

59615961
impl From<CreatePolicy> for crate::ast::Statement {
59625962
fn from(v: CreatePolicy) -> Self {
5963-
crate::ast::Statement::CreatePolicy(v)
5963+
crate::ast::Statement::CreatePolicy(Box::new(v))
59645964
}
59655965
}
59665966

59675967
impl From<DropPolicy> for crate::ast::Statement {
59685968
fn from(v: DropPolicy) -> Self {
5969-
crate::ast::Statement::DropPolicy(v)
5969+
crate::ast::Statement::DropPolicy(Box::new(v))
59705970
}
59715971
}
59725972

@@ -6003,7 +6003,7 @@ impl fmt::Display for AlterPolicy {
60036003

60046004
impl From<AlterPolicy> for crate::ast::Statement {
60056005
fn from(v: AlterPolicy) -> Self {
6006-
crate::ast::Statement::AlterPolicy(v)
6006+
crate::ast::Statement::AlterPolicy(Box::new(v))
60076007
}
60086008
}
60096009

@@ -6058,7 +6058,7 @@ impl fmt::Display for CreateForeignTable {
60586058

60596059
impl From<CreateForeignTable> for crate::ast::Statement {
60606060
fn from(v: CreateForeignTable) -> Self {
6061-
crate::ast::Statement::CreateForeignTable(v)
6061+
crate::ast::Statement::CreateForeignTable(Box::new(v))
60626062
}
60636063
}
60646064

‎src/ast/helpers/stmt_create_database.rs‎

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
#[cfg(not(feature = "std"))]
19-
use alloc::{format, string::String, vec::Vec};
19+
use alloc::{boxed::Box, format, string::String, vec::Vec};
2020

2121
#[cfg(feature = "serde")]
2222
use serde::{Deserialize, Serialize};
@@ -25,7 +25,8 @@ use serde::{Deserialize, Serialize};
2525
use sqlparser_derive::{Visit, VisitMut};
2626

2727
use crate::ast::{
28-
CatalogSyncNamespaceMode, ContactEntry, ObjectName, Statement, StorageSerializationPolicy, Tag,
28+
CatalogSyncNamespaceMode, ContactEntry, CreateDatabase, ObjectName, Statement,
29+
StorageSerializationPolicy, Tag,
2930
};
3031
use crate::parser::ParserError;
3132

@@ -278,7 +279,7 @@ impl CreateDatabaseBuilder {
278279

279280
/// Build the `CREATE DATABASE` statement.
280281
pub fn build(self) -> Statement {
281-
Statement::CreateDatabase {
282+
Statement::CreateDatabase(Box::new(CreateDatabase {
282283
db_name: self.db_name,
283284
if_not_exists: self.if_not_exists,
284285
managed_location: self.managed_location,
@@ -301,7 +302,7 @@ impl CreateDatabaseBuilder {
301302
catalog_sync_namespace_flatten_delimiter: self.catalog_sync_namespace_flatten_delimiter,
302303
with_tags: self.with_tags,
303304
with_contacts: self.with_contacts,
304-
}
305+
}))
305306
}
306307
}
307308

@@ -310,53 +311,56 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
310311

311312
fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
312313
match stmt {
313-
Statement::CreateDatabase {
314-
db_name,
315-
if_not_exists,
316-
location,
317-
managed_location,
318-
or_replace,
319-
transient,
320-
clone,
321-
data_retention_time_in_days,
322-
max_data_extension_time_in_days,
323-
external_volume,
324-
catalog,
325-
replace_invalid_characters,
326-
default_ddl_collation,
327-
storage_serialization_policy,
328-
comment,
329-
default_charset,
330-
default_collation,
331-
catalog_sync,
332-
catalog_sync_namespace_mode,
333-
catalog_sync_namespace_flatten_delimiter,
334-
with_tags,
335-
with_contacts,
336-
} => Ok(Self {
337-
db_name,
338-
if_not_exists,
339-
location,
340-
managed_location,
341-
or_replace,
342-
transient,
343-
clone,
344-
data_retention_time_in_days,
345-
max_data_extension_time_in_days,
346-
external_volume,
347-
catalog,
348-
replace_invalid_characters,
349-
default_ddl_collation,
350-
storage_serialization_policy,
351-
comment,
352-
default_charset,
353-
default_collation,
354-
catalog_sync,
355-
catalog_sync_namespace_mode,
356-
catalog_sync_namespace_flatten_delimiter,
357-
with_tags,
358-
with_contacts,
359-
}),
314+
Statement::CreateDatabase(create_database) => {
315+
let CreateDatabase {
316+
db_name,
317+
if_not_exists,
318+
location,
319+
managed_location,
320+
or_replace,
321+
transient,
322+
clone,
323+
data_retention_time_in_days,
324+
max_data_extension_time_in_days,
325+
external_volume,
326+
catalog,
327+
replace_invalid_characters,
328+
default_ddl_collation,
329+
storage_serialization_policy,
330+
comment,
331+
default_charset,
332+
default_collation,
333+
catalog_sync,
334+
catalog_sync_namespace_mode,
335+
catalog_sync_namespace_flatten_delimiter,
336+
with_tags,
337+
with_contacts,
338+
} = *create_database;
339+
Ok(Self {
340+
db_name,
341+
if_not_exists,
342+
location,
343+
managed_location,
344+
or_replace,
345+
transient,
346+
clone,
347+
data_retention_time_in_days,
348+
max_data_extension_time_in_days,
349+
external_volume,
350+
catalog,
351+
replace_invalid_characters,
352+
default_ddl_collation,
353+
storage_serialization_policy,
354+
comment,
355+
default_charset,
356+
default_collation,
357+
catalog_sync,
358+
catalog_sync_namespace_mode,
359+
catalog_sync_namespace_flatten_delimiter,
360+
with_tags,
361+
with_contacts,
362+
})
363+
}
360364
_ => Err(ParserError::ParserError(format!(
361365
"Expected create database statement, but received: {stmt}"
362366
))),
@@ -367,7 +371,7 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
367371
#[cfg(test)]
368372
mod tests {
369373
use crate::ast::helpers::stmt_create_database::CreateDatabaseBuilder;
370-
use crate::ast::{Ident, ObjectName, Statement};
374+
use crate::ast::{Commit, Ident, ObjectName, Statement};
371375
use crate::parser::ParserError;
372376

373377
#[test]
@@ -381,11 +385,11 @@ mod tests {
381385

382386
#[test]
383387
pub fn test_from_invalid_statement() {
384-
let stmt = Statement::Commit {
388+
let stmt = Statement::Commit(Box::new(Commit {
385389
chain: false,
386390
end: false,
387391
modifier: None,
388-
};
392+
}));
389393

390394
assert_eq!(
391395
CreateDatabaseBuilder::try_from(stmt).unwrap_err(),

‎src/ast/helpers/stmt_create_table.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
676676
// ownership.
677677
fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
678678
match stmt {
679-
Statement::CreateTable(create_table) => Ok(create_table.into()),
679+
Statement::CreateTable(create_table) => Ok((*create_table).into()),
680680
_ => Err(ParserError::ParserError(format!(
681681
"Expected create table statement, but received: {stmt}"
682682
))),
@@ -767,7 +767,7 @@ pub(crate) struct CreateTableConfiguration {
767767
#[cfg(test)]
768768
mod tests {
769769
use crate::ast::helpers::stmt_create_table::CreateTableBuilder;
770-
use crate::ast::{Ident, ObjectName, Statement};
770+
use crate::ast::{Commit, Ident, ObjectName, Statement};
771771
use crate::parser::ParserError;
772772

773773
#[test]
@@ -782,11 +782,11 @@ mod tests {
782782

783783
#[test]
784784
pub fn test_from_invalid_statement() {
785-
let stmt = Statement::Commit {
785+
let stmt = Statement::Commit(Box::new(Commit {
786786
chain: false,
787787
end: false,
788788
modifier: None,
789-
};
789+
}));
790790

791791
assert_eq!(
792792
CreateTableBuilder::try_from(stmt).unwrap_err(),

0 commit comments

Comments
 (0)