Skip to content
6 changes: 3 additions & 3 deletions src/ast/dcl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! (commonly referred to as Data Control Language, or DCL)

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use alloc::{boxed::Box, vec::Vec};
use core::fmt;

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

impl From<Grant> for crate::ast::Statement {
fn from(v: Grant) -> Self {
crate::ast::Statement::Grant(v)
crate::ast::Statement::Grant(Box::new(v))
}
}

Expand Down Expand Up @@ -532,6 +532,6 @@ impl fmt::Display for Revoke {

impl From<Revoke> for crate::ast::Statement {
fn from(v: Revoke) -> Self {
crate::ast::Statement::Revoke(v)
crate::ast::Statement::Revoke(Box::new(v))
}
}
10 changes: 5 additions & 5 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5994,13 +5994,13 @@ impl fmt::Display for DropPolicy {

impl From<CreatePolicy> for crate::ast::Statement {
fn from(v: CreatePolicy) -> Self {
crate::ast::Statement::CreatePolicy(v)
crate::ast::Statement::CreatePolicy(Box::new(v))
}
}

impl From<DropPolicy> for crate::ast::Statement {
fn from(v: DropPolicy) -> Self {
crate::ast::Statement::DropPolicy(v)
crate::ast::Statement::DropPolicy(Box::new(v))
}
}

Expand Down Expand Up @@ -6037,7 +6037,7 @@ impl fmt::Display for AlterPolicy {

impl From<AlterPolicy> for crate::ast::Statement {
fn from(v: AlterPolicy) -> Self {
crate::ast::Statement::AlterPolicy(v)
crate::ast::Statement::AlterPolicy(Box::new(v))
}
}

Expand Down Expand Up @@ -6092,7 +6092,7 @@ impl fmt::Display for CreateForeignTable {

impl From<CreateForeignTable> for crate::ast::Statement {
fn from(v: CreateForeignTable) -> Self {
crate::ast::Statement::CreateForeignTable(v)
crate::ast::Statement::CreateForeignTable(Box::new(v))
}
}

Expand Down Expand Up @@ -6178,7 +6178,7 @@ pub enum CreateAggregateArgs {

impl From<CreateAggregate> for crate::ast::Statement {
fn from(v: CreateAggregate) -> Self {
crate::ast::Statement::CreateAggregate(v)
crate::ast::Statement::CreateAggregate(Box::new(v))
}
}

Expand Down
112 changes: 58 additions & 54 deletions src/ast/helpers/stmt_create_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

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

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

use crate::ast::{
CatalogSyncNamespaceMode, ContactEntry, ObjectName, Statement, StorageSerializationPolicy, Tag,
CatalogSyncNamespaceMode, ContactEntry, CreateDatabase, ObjectName, Statement,
StorageSerializationPolicy, Tag,
};
use crate::parser::ParserError;

Expand Down Expand Up @@ -278,7 +279,7 @@ impl CreateDatabaseBuilder {

/// Build the `CREATE DATABASE` statement.
pub fn build(self) -> Statement {
Statement::CreateDatabase {
Statement::CreateDatabase(Box::new(CreateDatabase {
db_name: self.db_name,
if_not_exists: self.if_not_exists,
managed_location: self.managed_location,
Expand All @@ -301,7 +302,7 @@ impl CreateDatabaseBuilder {
catalog_sync_namespace_flatten_delimiter: self.catalog_sync_namespace_flatten_delimiter,
with_tags: self.with_tags,
with_contacts: self.with_contacts,
}
}))
}
}

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

fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
match stmt {
Statement::CreateDatabase {
db_name,
if_not_exists,
location,
managed_location,
or_replace,
transient,
clone,
data_retention_time_in_days,
max_data_extension_time_in_days,
external_volume,
catalog,
replace_invalid_characters,
default_ddl_collation,
storage_serialization_policy,
comment,
default_charset,
default_collation,
catalog_sync,
catalog_sync_namespace_mode,
catalog_sync_namespace_flatten_delimiter,
with_tags,
with_contacts,
} => Ok(Self {
db_name,
if_not_exists,
location,
managed_location,
or_replace,
transient,
clone,
data_retention_time_in_days,
max_data_extension_time_in_days,
external_volume,
catalog,
replace_invalid_characters,
default_ddl_collation,
storage_serialization_policy,
comment,
default_charset,
default_collation,
catalog_sync,
catalog_sync_namespace_mode,
catalog_sync_namespace_flatten_delimiter,
with_tags,
with_contacts,
}),
Statement::CreateDatabase(create_database) => {
let CreateDatabase {
db_name,
if_not_exists,
location,
managed_location,
or_replace,
transient,
clone,
data_retention_time_in_days,
max_data_extension_time_in_days,
external_volume,
catalog,
replace_invalid_characters,
default_ddl_collation,
storage_serialization_policy,
comment,
default_charset,
default_collation,
catalog_sync,
catalog_sync_namespace_mode,
catalog_sync_namespace_flatten_delimiter,
with_tags,
with_contacts,
} = *create_database;
Ok(Self {
db_name,
if_not_exists,
location,
managed_location,
or_replace,
transient,
clone,
data_retention_time_in_days,
max_data_extension_time_in_days,
external_volume,
catalog,
replace_invalid_characters,
default_ddl_collation,
storage_serialization_policy,
comment,
default_charset,
default_collation,
catalog_sync,
catalog_sync_namespace_mode,
catalog_sync_namespace_flatten_delimiter,
with_tags,
with_contacts,
})
}
_ => Err(ParserError::ParserError(format!(
"Expected create database statement, but received: {stmt}"
))),
Expand All @@ -367,7 +371,7 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
#[cfg(test)]
mod tests {
use crate::ast::helpers::stmt_create_database::CreateDatabaseBuilder;
use crate::ast::{Ident, ObjectName, Statement};
use crate::ast::{Commit, Ident, ObjectName, Statement};
use crate::parser::ParserError;

#[test]
Expand All @@ -381,11 +385,11 @@ mod tests {

#[test]
pub fn test_from_invalid_statement() {
let stmt = Statement::Commit {
let stmt = Statement::Commit(Box::new(Commit {
chain: false,
end: false,
modifier: None,
};
}));

assert_eq!(
CreateDatabaseBuilder::try_from(stmt).unwrap_err(),
Expand Down
8 changes: 4 additions & 4 deletions src/ast/helpers/stmt_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
// ownership.
fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
match stmt {
Statement::CreateTable(create_table) => Ok(create_table.into()),
Statement::CreateTable(create_table) => Ok((*create_table).into()),
_ => Err(ParserError::ParserError(format!(
"Expected create table statement, but received: {stmt}"
))),
Expand Down Expand Up @@ -756,7 +756,7 @@ pub(crate) struct CreateTableConfiguration {
#[cfg(test)]
mod tests {
use crate::ast::helpers::stmt_create_table::CreateTableBuilder;
use crate::ast::{Ident, ObjectName, Statement};
use crate::ast::{Commit, Ident, ObjectName, Statement};
use crate::parser::ParserError;

#[test]
Expand All @@ -771,11 +771,11 @@ mod tests {

#[test]
pub fn test_from_invalid_statement() {
let stmt = Statement::Commit {
let stmt = Statement::Commit(Box::new(Commit {
chain: false,
end: false,
modifier: None,
};
}));

assert_eq!(
CreateTableBuilder::try_from(stmt).unwrap_err(),
Expand Down
Loading
Loading