Skip to content

Commit 4830fd3

Browse files
committed
Merge branch 'main' into sql-pipe-operator-part1
2 parents f55f102 + 4e392f5 commit 4830fd3

File tree

14 files changed

+759
-65
lines changed

14 files changed

+759
-65
lines changed

dev/release/generate-changelog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def print_pulls(repo_name, title, pulls):
2828
print()
2929
for (pull, commit) in pulls:
3030
url = "https://github.com/{}/pull/{}".format(repo_name, pull.number)
31-
print("- {} [#{}]({}) ({})".format(pull.title, pull.number, url, commit.author.login))
31+
author = f"({commit.author.login})" if commit.author else ''
32+
print("- {} [#{}]({}) {}".format(pull.title, pull.number, url, author))
3233
print()
3334

3435

@@ -161,4 +162,4 @@ def cli(args=None):
161162
generate_changelog(repo, project, args.tag1, args.tag2, args.version)
162163

163164
if __name__ == "__main__":
164-
cli()
165+
cli()

src/ast/ddl.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,10 @@ impl fmt::Display for ClusteredBy {
21572157
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
21582158
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
21592159
pub struct CreateFunction {
2160+
/// True if this is a `CREATE OR ALTER FUNCTION` statement
2161+
///
2162+
/// [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql?view=sql-server-ver16#or-alter)
2163+
pub or_alter: bool,
21602164
pub or_replace: bool,
21612165
pub temporary: bool,
21622166
pub if_not_exists: bool,
@@ -2219,9 +2223,10 @@ impl fmt::Display for CreateFunction {
22192223
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22202224
write!(
22212225
f,
2222-
"CREATE {or_replace}{temp}FUNCTION {if_not_exists}{name}",
2226+
"CREATE {or_alter}{or_replace}{temp}FUNCTION {if_not_exists}{name}",
22232227
name = self.name,
22242228
temp = if self.temporary { "TEMPORARY " } else { "" },
2229+
or_alter = if self.or_alter { "OR ALTER " } else { "" },
22252230
or_replace = if self.or_replace { "OR REPLACE " } else { "" },
22262231
if_not_exists = if self.if_not_exists {
22272232
"IF NOT EXISTS "
@@ -2272,6 +2277,9 @@ impl fmt::Display for CreateFunction {
22722277
if let Some(CreateFunctionBody::AsAfterOptions(function_body)) = &self.function_body {
22732278
write!(f, " AS {function_body}")?;
22742279
}
2280+
if let Some(CreateFunctionBody::AsBeginEnd(bes)) = &self.function_body {
2281+
write!(f, " AS {bes}")?;
2282+
}
22752283
Ok(())
22762284
}
22772285
}

src/ast/mod.rs

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ pub use self::query::{
8181
TableIndexType, TableSample, TableSampleBucket, TableSampleKind, TableSampleMethod,
8282
TableSampleModifier, TableSampleQuantity, TableSampleSeed, TableSampleSeedModifier,
8383
TableSampleUnit, TableVersion, TableWithJoins, Top, TopQuantity, UpdateTableFromKind,
84-
ValueTableMode, Values, WildcardAdditionalOptions, With, WithFill,
84+
ValueTableMode, Values, WildcardAdditionalOptions, With, WithFill, XmlNamespaceDefinition,
85+
XmlPassingArgument, XmlPassingClause, XmlTableColumn, XmlTableColumnOption,
8586
};
8687

8788
pub use self::trigger::{
@@ -2292,18 +2293,14 @@ pub enum ConditionalStatements {
22922293
/// SELECT 1; SELECT 2; SELECT 3; ...
22932294
Sequence { statements: Vec<Statement> },
22942295
/// BEGIN SELECT 1; SELECT 2; SELECT 3; ... END
2295-
BeginEnd {
2296-
begin_token: AttachedToken,
2297-
statements: Vec<Statement>,
2298-
end_token: AttachedToken,
2299-
},
2296+
BeginEnd(BeginEndStatements),
23002297
}
23012298

23022299
impl ConditionalStatements {
23032300
pub fn statements(&self) -> &Vec<Statement> {
23042301
match self {
23052302
ConditionalStatements::Sequence { statements } => statements,
2306-
ConditionalStatements::BeginEnd { statements, .. } => statements,
2303+
ConditionalStatements::BeginEnd(bes) => &bes.statements,
23072304
}
23082305
}
23092306
}
@@ -2317,12 +2314,41 @@ impl fmt::Display for ConditionalStatements {
23172314
}
23182315
Ok(())
23192316
}
2320-
ConditionalStatements::BeginEnd { statements, .. } => {
2321-
write!(f, "BEGIN ")?;
2322-
format_statement_list(f, statements)?;
2323-
write!(f, " END")
2324-
}
2317+
ConditionalStatements::BeginEnd(bes) => write!(f, "{}", bes),
2318+
}
2319+
}
2320+
}
2321+
2322+
/// Represents a list of statements enclosed within `BEGIN` and `END` keywords.
2323+
/// Example:
2324+
/// ```sql
2325+
/// BEGIN
2326+
/// SELECT 1;
2327+
/// SELECT 2;
2328+
/// END
2329+
/// ```
2330+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2331+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2332+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2333+
pub struct BeginEndStatements {
2334+
pub begin_token: AttachedToken,
2335+
pub statements: Vec<Statement>,
2336+
pub end_token: AttachedToken,
2337+
}
2338+
2339+
impl fmt::Display for BeginEndStatements {
2340+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2341+
let BeginEndStatements {
2342+
begin_token: AttachedToken(begin_token),
2343+
statements,
2344+
end_token: AttachedToken(end_token),
2345+
} = self;
2346+
2347+
write!(f, "{begin_token} ")?;
2348+
if !statements.is_empty() {
2349+
format_statement_list(f, statements)?;
23252350
}
2351+
write!(f, " {end_token}")
23262352
}
23272353
}
23282354

@@ -2446,10 +2472,11 @@ impl fmt::Display for DeclareAssignment {
24462472
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24472473
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
24482474
pub enum DeclareType {
2449-
/// Cursor variable type. e.g. [Snowflake] [PostgreSQL]
2475+
/// Cursor variable type. e.g. [Snowflake] [PostgreSQL] [MsSql]
24502476
///
24512477
/// [Snowflake]: https://docs.snowflake.com/en/developer-guide/snowflake-scripting/cursors#declaring-a-cursor
24522478
/// [PostgreSQL]: https://www.postgresql.org/docs/current/plpgsql-cursors.html
2479+
/// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/declare-cursor-transact-sql
24532480
Cursor,
24542481

24552482
/// Result set variable type. [Snowflake]
@@ -3037,6 +3064,10 @@ pub enum Statement {
30373064
/// CREATE VIEW
30383065
/// ```
30393066
CreateView {
3067+
/// True if this is a `CREATE OR ALTER VIEW` statement
3068+
///
3069+
/// [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql)
3070+
or_alter: bool,
30403071
or_replace: bool,
30413072
materialized: bool,
30423073
/// View name
@@ -3614,6 +3645,7 @@ pub enum Statement {
36143645
/// 1. [Hive](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-Create/Drop/ReloadFunction)
36153646
/// 2. [PostgreSQL](https://www.postgresql.org/docs/15/sql-createfunction.html)
36163647
/// 3. [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_function_statement)
3648+
/// 4. [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql)
36173649
CreateFunction(CreateFunction),
36183650
/// CREATE TRIGGER
36193651
///
@@ -4054,6 +4086,18 @@ pub enum Statement {
40544086
arguments: Vec<Expr>,
40554087
options: Vec<RaisErrorOption>,
40564088
},
4089+
/// ```sql
4090+
/// PRINT msg_str | @local_variable | string_expr
4091+
/// ```
4092+
///
4093+
/// See: <https://learn.microsoft.com/en-us/sql/t-sql/statements/print-transact-sql>
4094+
Print(PrintStatement),
4095+
/// ```sql
4096+
/// RETURN [ expression ]
4097+
/// ```
4098+
///
4099+
/// See [ReturnStatement]
4100+
Return(ReturnStatement),
40574101
}
40584102

40594103
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -4584,6 +4628,7 @@ impl fmt::Display for Statement {
45844628
Ok(())
45854629
}
45864630
Statement::CreateView {
4631+
or_alter,
45874632
name,
45884633
or_replace,
45894634
columns,
@@ -4600,7 +4645,8 @@ impl fmt::Display for Statement {
46004645
} => {
46014646
write!(
46024647
f,
4603-
"CREATE {or_replace}",
4648+
"CREATE {or_alter}{or_replace}",
4649+
or_alter = if *or_alter { "OR ALTER " } else { "" },
46044650
or_replace = if *or_replace { "OR REPLACE " } else { "" },
46054651
)?;
46064652
if let Some(params) = params {
@@ -5745,7 +5791,8 @@ impl fmt::Display for Statement {
57455791
}
57465792
Ok(())
57475793
}
5748-
5794+
Statement::Print(s) => write!(f, "{s}"),
5795+
Statement::Return(r) => write!(f, "{r}"),
57495796
Statement::List(command) => write!(f, "LIST {command}"),
57505797
Statement::Remove(command) => write!(f, "REMOVE {command}"),
57515798
}
@@ -8348,6 +8395,7 @@ impl fmt::Display for FunctionDeterminismSpecifier {
83488395
///
83498396
/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83508397
/// [PostgreSQL]: https://www.postgresql.org/docs/15/sql-createfunction.html
8398+
/// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
83518399
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
83528400
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
83538401
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -8376,6 +8424,22 @@ pub enum CreateFunctionBody {
83768424
///
83778425
/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83788426
AsAfterOptions(Expr),
8427+
/// Function body with statements before the `RETURN` keyword.
8428+
///
8429+
/// Example:
8430+
/// ```sql
8431+
/// CREATE FUNCTION my_scalar_udf(a INT, b INT)
8432+
/// RETURNS INT
8433+
/// AS
8434+
/// BEGIN
8435+
/// DECLARE c INT;
8436+
/// SET c = a + b;
8437+
/// RETURN c;
8438+
/// END
8439+
/// ```
8440+
///
8441+
/// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
8442+
AsBeginEnd(BeginEndStatements),
83798443
/// Function body expression using the 'RETURN' keyword.
83808444
///
83818445
/// Example:
@@ -9211,6 +9275,47 @@ pub enum CopyIntoSnowflakeKind {
92119275
Location,
92129276
}
92139277

9278+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9279+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9280+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9281+
pub struct PrintStatement {
9282+
pub message: Box<Expr>,
9283+
}
9284+
9285+
impl fmt::Display for PrintStatement {
9286+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9287+
write!(f, "PRINT {}", self.message)
9288+
}
9289+
}
9290+
9291+
/// Represents a `Return` statement.
9292+
///
9293+
/// [MsSql triggers](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql)
9294+
/// [MsSql functions](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql)
9295+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9296+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9297+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9298+
pub struct ReturnStatement {
9299+
pub value: Option<ReturnStatementValue>,
9300+
}
9301+
9302+
impl fmt::Display for ReturnStatement {
9303+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9304+
match &self.value {
9305+
Some(ReturnStatementValue::Expr(expr)) => write!(f, "RETURN {}", expr),
9306+
None => write!(f, "RETURN"),
9307+
}
9308+
}
9309+
}
9310+
9311+
/// Variants of a `RETURN` statement
9312+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9313+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9314+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9315+
pub enum ReturnStatementValue {
9316+
Expr(Expr),
9317+
}
9318+
92149319
#[cfg(test)]
92159320
mod tests {
92169321
use super::*;

0 commit comments

Comments
 (0)