Skip to content

Commit b28f81f

Browse files
committed
Merge remote-tracking branch 'github/main' into fix/receipt-contradictions
2 parents cd4a218 + 58b3331 commit b28f81f

25 files changed

Lines changed: 988 additions & 57 deletions

‎crates/sqlquack-syntax/src/expressions/columns/models.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,47 @@ pub struct DataMetricFunctionAction {
559559
pub items: Vec<DataMetricFunctionItem>,
560560
}
561561

562+
/// Snowflake `{ CREATE | DEFINE } [ SECURE ] DATA METRIC FUNCTION`.
563+
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
564+
pub struct CreateDataMetricFunction {
565+
/// The leading keyword: "CREATE" or "DEFINE".
566+
pub verb: String,
567+
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
568+
pub or_replace: bool,
569+
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
570+
pub or_alter: bool,
571+
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
572+
pub secure: bool,
573+
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
574+
pub if_not_exists: bool,
575+
pub name: TableRef,
576+
pub arguments: Vec<DataMetricTableArgument>,
577+
pub return_type: DataType,
578+
/// `NULL` as true or `NOT NULL` as false after the return type, absent without either.
579+
#[serde(default, skip_serializing_if = "Option::is_none")]
580+
pub nullable: Option<bool>,
581+
#[serde(default, skip_serializing_if = "Option::is_none")]
582+
pub language: Option<Identifier>,
583+
#[serde(default, skip_serializing_if = "Option::is_none")]
584+
pub comment: Option<Expression>,
585+
/// The `AS` body, a string literal.
586+
pub body: Expression,
587+
}
588+
589+
/// One `<name> TABLE ( <column> <type>, ... )` argument of a data metric function.
590+
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
591+
pub struct DataMetricTableArgument {
592+
pub name: Identifier,
593+
pub columns: Vec<DataMetricColumn>,
594+
}
595+
596+
/// One `<column> <type>` of a data metric function's table argument.
597+
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
598+
pub struct DataMetricColumn {
599+
pub name: Identifier,
600+
pub data_type: DataType,
601+
}
602+
562603
/// One `<name> ON ( <argument>, ... )` of a data metric function action, with its clauses.
563604
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
564605
pub struct DataMetricFunctionItem {

‎crates/sqlquack-syntax/src/expressions/schema_objects/models.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,3 +1218,26 @@ pub struct ObjectProperty {
12181218
#[serde(default)]
12191219
pub value: Option<Expression>,
12201220
}
1221+
1222+
/// Snowflake `EXECUTE ALERT | TASK [ GRAPH ] | DCM PROJECT <name>` with its action.
1223+
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
1224+
pub struct ExecuteObject {
1225+
/// The object kind as written in upper case, such as `TASK GRAPH`.
1226+
pub kind: String,
1227+
pub name: TableRef,
1228+
/// The action words in upper case, such as `RETRY LAST` or `PURGE`.
1229+
#[serde(default, skip_serializing_if = "Option::is_none")]
1230+
pub action: Option<String>,
1231+
/// `RETRY GRAPH RUN GROUP '<id>'`: the graph run group.
1232+
#[serde(default, skip_serializing_if = "Option::is_none")]
1233+
pub group: Option<Expression>,
1234+
/// `PURGE AS "<alias>"`: the deployment alias.
1235+
#[serde(default, skip_serializing_if = "Option::is_none")]
1236+
pub alias: Option<Identifier>,
1237+
/// `USING CONFIG = <configuration>`.
1238+
#[serde(default, skip_serializing_if = "Option::is_none")]
1239+
pub config: Option<Expression>,
1240+
/// The clauses and options of a job, notebook, dbt or code bundle, such as `IN COMPUTE POOL` or `ARGS`.
1241+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
1242+
pub properties: Vec<ObjectProperty>,
1243+
}

‎crates/sqlquack-syntax/src/expressions/statements/models.rs‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -360,26 +360,6 @@ pub struct ExecuteUsingPolicyContext {
360360
pub query: Expression,
361361
}
362362

363-
/// Snowflake `EXECUTE ALERT | TASK [ GRAPH ] | DCM PROJECT <name>` with its action.
364-
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
365-
pub struct ExecuteObject {
366-
/// The object kind as written in upper case, such as `TASK GRAPH`.
367-
pub kind: String,
368-
pub name: TableRef,
369-
/// The action words in upper case, such as `RETRY LAST` or `PURGE`.
370-
#[serde(default, skip_serializing_if = "Option::is_none")]
371-
pub action: Option<String>,
372-
/// `RETRY GRAPH RUN GROUP '<id>'`: the graph run group.
373-
#[serde(default, skip_serializing_if = "Option::is_none")]
374-
pub group: Option<Expression>,
375-
/// `PURGE AS "<alias>"`: the deployment alias.
376-
#[serde(default, skip_serializing_if = "Option::is_none")]
377-
pub alias: Option<Identifier>,
378-
/// `USING CONFIG = <configuration>`.
379-
#[serde(default, skip_serializing_if = "Option::is_none")]
380-
pub config: Option<Expression>,
381-
}
382-
383363
/// Named parameter in EXEC statement: @name=value
384364
#[derive(sqlquack_syntax_derive::AstNode, Debug, Clone, PartialEq, Serialize, Deserialize)]
385365
pub struct ExecuteParameter {

‎crates/sqlquack-syntax/src/expressions/tree/_helpers/accessors.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl Expression {
9393
| Expression::AlterView(_)
9494
| Expression::AlterObject(_)
9595
| Expression::CreateObject(_)
96+
| Expression::CreateDataMetricFunction(_)
9697
| Expression::AlterIndex(_)
9798
| Expression::Truncate(_)
9899
| Expression::TruncateTable(_)

‎crates/sqlquack-syntax/src/expressions/tree/_helpers/api.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl Expression {
408408
Expression::AlterView(_) => "alter_view",
409409
Expression::AlterObject(_) => "alter_object",
410410
Expression::CreateObject(_) => "create_object",
411+
Expression::CreateDataMetricFunction(_) => "create_data_metric_function",
411412
Expression::AlterIndex(_) => "alter_index",
412413
Expression::Truncate(_) => "truncate",
413414
Expression::Use(_) => "use",

‎crates/sqlquack-syntax/src/expressions/tree/models.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::expressions::columns::models::Comprehension;
2121
use crate::expressions::columns::models::CompressColumnConstraint;
2222
use crate::expressions::columns::models::ComputedColumnConstraint;
2323
use crate::expressions::columns::models::Constraint;
24+
use crate::expressions::columns::models::CreateDataMetricFunction;
2425
use crate::expressions::columns::models::DateFormatColumnConstraint;
2526
use crate::expressions::columns::models::DefaultColumnConstraint;
2627
use crate::expressions::columns::models::EphemeralColumnConstraint;
@@ -357,6 +358,7 @@ use crate::expressions::schema_objects::models::DropSequence;
357358
use crate::expressions::schema_objects::models::DropTrigger;
358359
use crate::expressions::schema_objects::models::DropType;
359360
use crate::expressions::schema_objects::models::DropView;
361+
use crate::expressions::schema_objects::models::ExecuteObject;
360362
use crate::expressions::statements::models::AddPartition;
361363
use crate::expressions::statements::models::AlterSession;
362364
use crate::expressions::statements::models::Analyze;
@@ -385,7 +387,6 @@ use crate::expressions::statements::models::Delete;
385387
use crate::expressions::statements::models::Describe;
386388
use crate::expressions::statements::models::Detach;
387389
use crate::expressions::statements::models::DropPartition;
388-
use crate::expressions::statements::models::ExecuteObject;
389390
use crate::expressions::statements::models::ExecuteStatement;
390391
use crate::expressions::statements::models::ExecuteUsingPolicyContext;
391392
use crate::expressions::statements::models::Get;
@@ -1183,6 +1184,7 @@ pub enum Expression {
11831184
AlterView(Box<AlterView>),
11841185
AlterObject(Box<AlterObject>),
11851186
CreateObject(Box<CreateObject>),
1187+
CreateDataMetricFunction(Box<CreateDataMetricFunction>),
11861188
AlterIndex(Box<AlterIndex>),
11871189
Truncate(Box<Truncate>),
11881190
Use(Box<Use>),

‎crates/sqlquack-syntax/src/expressions/types/models.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub enum IntervalUnitSpec {
464464
ExprSpan(IntervalSpanExpr),
465465
/// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
466466
Expr(Box<Expression>),
467-
/// Snowflake qualifier with a field precision, such as `YEAR(9) TO MONTH` or `SECOND(9), (3)`.
467+
/// Snowflake qualifier with a field precision, such as `YEAR(9) TO MONTH` or `DAY TO SECOND(3)`.
468468
Qualifier(IntervalQualifier),
469469
}
470470

@@ -477,7 +477,7 @@ pub struct IntervalQualifier {
477477
pub leading_precision: Option<u32>,
478478
/// Trailing field after TO (e.g., SECOND)
479479
pub expression: Option<IntervalUnit>,
480-
/// Fractional seconds precision, as 3 in `DAY TO SECOND(3)` or `SECOND(9), (3)`
480+
/// Fractional seconds precision, as 3 in `DAY TO SECOND(3)`
481481
pub fractional_precision: Option<u32>,
482482
}
483483

‎crates/sqlquack-syntax/src/parser/_helpers/ddl/alter.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ impl Parser {
781781
let id_val = self.parse_expression()?;
782782
partitions.push(vec![(Identifier::new("ID".to_string()), id_val)]);
783783
} else {
784+
if self.applies_snowflake_context_rules() && self.check_next(TokenType::String) {
785+
return Err(self.parse_error("Expected a partition, not a typed string"));
786+
}
784787
let expr = self.parse_expression()?;
785788
partitions.push(vec![(Identifier::new("__expr__".to_string()), expr)]);
786789
}
@@ -1487,7 +1490,16 @@ impl Parser {
14871490
}
14881491
}
14891492

1490-
let kind = if self.match_token(TokenType::Database) {
1493+
let kind_is_name = self.applies_snowflake_context_rules()
1494+
&& matches!(
1495+
self.tokens
1496+
.get(self.current + 1)
1497+
.map(|token| token.token_type),
1498+
None | Some(TokenType::Semicolon | TokenType::Dot)
1499+
);
1500+
let kind = if kind_is_name {
1501+
None
1502+
} else if self.match_token(TokenType::Database) {
14911503
Some(UseKind::Database)
14921504
} else if self.match_token(TokenType::Schema) {
14931505
Some(UseKind::Schema)

‎crates/sqlquack-syntax/src/parser/_helpers/ddl/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) mod snowflake_create_clone;
1818
pub(crate) mod snowflake_create_from;
1919
pub(crate) mod snowflake_create_properties;
2020
pub(crate) mod snowflake_data_metric;
21+
pub(crate) mod snowflake_execute_jobs;
2122
pub(crate) mod snowflake_grant;
2223
pub(crate) mod snowflake_routines;
2324
pub(crate) mod snowflake_show;

‎crates/sqlquack-syntax/src/parser/_helpers/ddl/snowflake_alter_resources.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@ impl Parser {
544544
}
545545

546546
/// Whether the current token starts a stage path.
547-
fn is_stage_path(&self) -> bool {
547+
pub(super) fn is_stage_path(&self) -> bool {
548548
!self.is_at_end() && self.peek_text().starts_with('@')
549549
}
550550

551551
/// Parse a stage path, which like Snowflake's ends at the first whitespace: `@"s 1"` is not one path.
552-
fn parse_stage_path(&mut self) -> Result<Expression> {
552+
pub(super) fn parse_stage_path(&mut self) -> Result<Expression> {
553553
let mut path = self.peek_text().to_owned();
554554
let mut end = self.peek().span.end;
555555
self.skip();

0 commit comments

Comments
 (0)