Skip to content

Commit c679d96

Browse files
authored
Merge branch 'main' into feat/export_data_for_bigquery
2 parents 1a7e8d9 + 865c191 commit c679d96

6 files changed

Lines changed: 66 additions & 1 deletion

File tree

src/ast/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6780,6 +6780,7 @@ pub enum ActionCreateObjectType {
67806780
OrganiationListing,
67816781
ReplicationGroup,
67826782
Role,
6783+
Schema,
67836784
Share,
67846785
User,
67856786
Warehouse,
@@ -6801,6 +6802,7 @@ impl fmt::Display for ActionCreateObjectType {
68016802
ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
68026803
ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
68036804
ActionCreateObjectType::Role => write!(f, "ROLE"),
6805+
ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
68046806
ActionCreateObjectType::Share => write!(f, "SHARE"),
68056807
ActionCreateObjectType::User => write!(f, "USER"),
68066808
ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
@@ -7038,6 +7040,8 @@ pub enum GrantObjects {
70387040
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
70397041
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
70407042
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
7043+
/// Grant privileges on `ALL FUNCTIONS IN SCHEMA <schema_name> [, ...]`
7044+
AllFunctionsInSchema { schemas: Vec<ObjectName> },
70417045
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
70427046
FutureSchemasInDatabase { databases: Vec<ObjectName> },
70437047
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
@@ -7158,6 +7162,13 @@ impl fmt::Display for GrantObjects {
71587162
display_comma_separated(schemas)
71597163
)
71607164
}
7165+
GrantObjects::AllFunctionsInSchema { schemas } => {
7166+
write!(
7167+
f,
7168+
"ALL FUNCTIONS IN SCHEMA {}",
7169+
display_comma_separated(schemas)
7170+
)
7171+
}
71617172
GrantObjects::FutureSchemasInDatabase { databases } => {
71627173
write!(
71637174
f,
@@ -7833,6 +7844,7 @@ pub enum ObjectType {
78337844
Stage,
78347845
Type,
78357846
User,
7847+
Stream,
78367848
}
78377849

78387850
impl fmt::Display for ObjectType {
@@ -7849,6 +7861,7 @@ impl fmt::Display for ObjectType {
78497861
ObjectType::Stage => "STAGE",
78507862
ObjectType::Type => "TYPE",
78517863
ObjectType::User => "USER",
7864+
ObjectType::Stream => "STREAM",
78527865
})
78537866
}
78547867
}

src/dialect/bigquery.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::ast::Statement;
1919
use crate::dialect::Dialect;
2020
use crate::keywords::Keyword;
2121
use crate::parser::{Parser, ParserError};
22+
use crate::tokenizer::Token;
2223

2324
/// These keywords are disallowed as column identifiers. Such that
2425
/// `SELECT 5 AS <col> FROM T` is rejected by BigQuery.
@@ -47,6 +48,13 @@ pub struct BigQueryDialect;
4748
impl Dialect for BigQueryDialect {
4849
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
4950
if parser.parse_keyword(Keyword::BEGIN) {
51+
if parser.peek_keyword(Keyword::TRANSACTION)
52+
|| parser.peek_token_ref().token == Token::SemiColon
53+
|| parser.peek_token_ref().token == Token::EOF
54+
{
55+
parser.prev_token();
56+
return None;
57+
}
5058
return Some(parser.parse_begin_exception_end());
5159
}
5260

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ define_keywords!(
870870
STORAGE_SERIALIZATION_POLICY,
871871
STORED,
872872
STRAIGHT_JOIN,
873+
STREAM,
873874
STRICT,
874875
STRING,
875876
STRUCT,

src/parser/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6326,6 +6326,8 @@ impl<'a> Parser<'a> {
63266326
ObjectType::Type
63276327
} else if self.parse_keyword(Keyword::USER) {
63286328
ObjectType::User
6329+
} else if self.parse_keyword(Keyword::STREAM) {
6330+
ObjectType::Stream
63296331
} else if self.parse_keyword(Keyword::FUNCTION) {
63306332
return self.parse_drop_function();
63316333
} else if self.parse_keyword(Keyword::POLICY) {
@@ -14109,6 +14111,15 @@ impl<'a> Parser<'a> {
1410914111
Some(GrantObjects::AllMaterializedViewsInSchema {
1411014112
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
1411114113
})
14114+
} else if self.parse_keywords(&[
14115+
Keyword::ALL,
14116+
Keyword::FUNCTIONS,
14117+
Keyword::IN,
14118+
Keyword::SCHEMA,
14119+
]) {
14120+
Some(GrantObjects::AllFunctionsInSchema {
14121+
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
14122+
})
1411214123
} else if self.parse_keywords(&[
1411314124
Keyword::FUTURE,
1411414125
Keyword::SCHEMAS,
@@ -14415,6 +14426,8 @@ impl<'a> Parser<'a> {
1441514426
Some(ActionCreateObjectType::Integration)
1441614427
} else if self.parse_keyword(Keyword::ROLE) {
1441714428
Some(ActionCreateObjectType::Role)
14429+
} else if self.parse_keyword(Keyword::SCHEMA) {
14430+
Some(ActionCreateObjectType::Schema)
1441814431
} else if self.parse_keyword(Keyword::SHARE) {
1441914432
Some(ActionCreateObjectType::Share)
1442014433
} else if self.parse_keyword(Keyword::USER) {

tests/sqlparser_bigquery.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,7 @@ fn test_struct_trailing_and_nested_bracket() {
25682568
}
25692569

25702570
#[test]
2571-
fn test_export() {
2571+
fn test_export_data() {
25722572
bigquery().verified_stmt(concat!(
25732573
"EXPORT DATA OPTIONS(",
25742574
"uri = 'gs://bucket/folder/*', ",
@@ -2587,3 +2587,13 @@ fn test_export() {
25872587
"SELECT field1, field2 FROM mydataset.table1 ORDER BY field1 LIMIT 10",
25882588
));
25892589
}
2590+
2591+
#[test]
2592+
fn test_begin_transaction() {
2593+
bigquery().verified_stmt("BEGIN TRANSACTION");
2594+
}
2595+
2596+
#[test]
2597+
fn test_begin_statement() {
2598+
bigquery().verified_stmt("BEGIN");
2599+
}

tests/sqlparser_common.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9528,6 +9528,7 @@ fn parse_grant() {
95289528
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
95299529
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
95309530
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
9531+
verified_stmt("GRANT USAGE ON ALL FUNCTIONS IN SCHEMA db1.sc1 TO ROLE role1");
95319532
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
95329533
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
95339534
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
@@ -9551,6 +9552,7 @@ fn parse_grant() {
95519552
verified_stmt("GRANT USAGE ON FUNCTION db1.sc1.foo(INT) TO ROLE role1");
95529553
verified_stmt("GRANT ROLE role1 TO ROLE role2");
95539554
verified_stmt("GRANT ROLE role1 TO USER user");
9555+
verified_stmt("GRANT CREATE SCHEMA ON DATABASE db1 TO ROLE role1");
95549556
}
95559557

95569558
#[test]
@@ -16357,3 +16359,21 @@ fn parse_create_user() {
1635716359
_ => unreachable!(),
1635816360
}
1635916361
}
16362+
16363+
#[test]
16364+
fn parse_drop_stream() {
16365+
let sql = "DROP STREAM s1";
16366+
match verified_stmt(sql) {
16367+
Statement::Drop {
16368+
names, object_type, ..
16369+
} => {
16370+
assert_eq!(
16371+
vec!["s1"],
16372+
names.iter().map(ToString::to_string).collect::<Vec<_>>()
16373+
);
16374+
assert_eq!(ObjectType::Stream, object_type);
16375+
}
16376+
_ => unreachable!(),
16377+
}
16378+
verified_stmt("DROP STREAM IF EXISTS s1");
16379+
}

0 commit comments

Comments
 (0)