Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,22 @@ sqlbuild-scopes = { path = "crates/sqlbuild-scopes" }
sqlbuild-sqltext = { path = "crates/sqlbuild-sqltext" }
sqlbuild-state = { path = "crates/sqlbuild-state" }
# SQL lint Rules, quality Rules and the formatter.
sqlclean = { git = "https://github.com/sqlstack-io/sqlclean.git", rev = "bbc94e556dc51e936e86fa4c85111c87a7915fc5" }
sqlclean = { git = "https://github.com/sqlstack-io/sqlclean.git", rev = "b0728bb990b7d8ff196cb00cc20545f2fa4df555" }
# SQL change fingerprints over SQLQuack's tokenizers.
sqlquack-fingerprint = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890", features = ["bigquery", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
sqlquack-fingerprint = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed", features = ["bigquery", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
# Scopes, name resolution, types and lineage for the native analysis route.
sqlquack-semantics = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890", features = ["bigquery", "clickhouse", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
sqlquack-semantics = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed", features = ["bigquery", "clickhouse", "databricks", "duckdb", "postgres", "snowflake", "sqlite", "sqlserver"] }
# SQLQuack's Snowflake-family parser and tokenizer, reached as SQLQuack exposes them.
sqlquack-parse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-parse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
# SQLQuack's syntax tree and lossless tokens.
sqlquack-syntax = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-bigquery = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-clickhouse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-databricks = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-duckdb = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-postgres = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-sqlite = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax-sqlserver = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "75d4c8486ab262a6c9c02a6c913334856367d890" }
sqlquack-syntax = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-bigquery = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-clickhouse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-databricks = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-duckdb = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-postgres = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-sqlite = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
sqlquack-syntax-sqlserver = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "fe3d1caf5ed81981abf8abd1d00cc9d99462e6ed" }
stacker = "0.1"
# Counts heap allocations in growth tests, which measure work instead of time.
stats_alloc = "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ impl LineageSchema for BigQueryTypes<'_> {
/// A type BigQuery's dry run accepts, as BigQuery names it; `None` for one it refuses.
fn native_type(data_type: &DataType) -> Option<String> {
Some(match data_type {
DataType::BigInt { length: None } => "INT64".to_owned(),
DataType::Decimal { precision, scale } => {
DataType::BigInt { length: None, .. } => "INT64".to_owned(),
DataType::Decimal {
precision, scale, ..
} => {
let given: Vec<u32> = [*precision, *scale].into_iter().flatten().collect();
decimal("NUMERIC", &given, NUMERIC_DIGITS)?
}
Expand All @@ -155,14 +157,17 @@ fn native_type(data_type: &DataType) -> Option<String> {
DataType::Time {
precision: None,
timezone: false,
..
} => "TIME".to_owned(),
DataType::Timestamp {
precision: None,
timezone: false,
..
} => "DATETIME".to_owned(),
DataType::Timestamp {
precision: None,
timezone: true,
..
} => "TIMESTAMP".to_owned(),
DataType::Interval {
unit: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ fn canonical(data_type: &DataType) -> Option<String> {
DataType::String { .. } | DataType::Char { .. } | DataType::VarChar { .. } => {
DATABRICKS_STRING_TYPE.to_owned()
}
DataType::Decimal { precision, scale } => {
DataType::Decimal {
precision, scale, ..
} => {
let (default_precision, default_scale) = DATABRICKS_DEFAULT_DECIMAL;
format!(
"DECIMAL({},{})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ fn given_sql_bigquery_refuses_when_parsing_then_the_gap_says_whether_it_is_a_syn
},
ParseFailureTestCase {
description: "the nesting limit is not a syntax error",
sql: format!("SELECT {}1{}", "(".repeat(300), ")".repeat(300)),
sql: format!("SELECT {}1{}", "(".repeat(600), ")".repeat(600)),
expected_syntax: false,
expected_offset: None,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ fn given_databricks_model_sql_when_probing_its_parser_then_only_sql_it_reads_who
},
NativeGapTestCase {
description: "a construct the shared tree lacks is a gap named by the parser",
sql: "VACUUM t",
sql: "REPAIR PRIVILEGES t",
placeholders: &[],
expected_gap: Some(LocatedGap {
construct: "vacuum".to_owned(),
message: "vacuum".to_owned(),
construct: "repair".to_owned(),
message: "repair".to_owned(),
line: 1,
column: 1,
syntax: false,
Expand Down Expand Up @@ -275,7 +275,7 @@ fn given_sql_databricks_refuses_when_parsing_then_the_gap_says_whether_it_is_a_s
},
ParseFailureTestCase {
description: "the nesting limit is not a syntax error",
sql: format!("SELECT {}1{}", "(".repeat(300), ")".repeat(300)),
sql: format!("SELECT {}1{}", "(".repeat(600), ")".repeat(600)),
expected_syntax: false,
expected_offset: None,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/sqlbuild-analysis/src/parse_guard/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Constants of parse_guard.

/// The deepest function-call nesting a Polyglot or SQLQuack shared or Snowflake parse accepts.
/// The deepest function-call nesting that a guarded parse or a SQLClean lint accepts.
pub const MAX_FUNCTION_CALL_DEPTH: usize = 256;
2 changes: 1 addition & 1 deletion crates/sqlbuild-analysis/src/parse_guard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! One call depth for Polyglot and SQLQuack's shared and Snowflake parsers, not per-dialect ones.
//! One call depth for Polyglot, SQLQuack's shared and Snowflake parsers and SQLClean's lint.

pub mod constants;
pub mod main;
Expand Down
27 changes: 20 additions & 7 deletions crates/sqlbuild-analysis/src/source_drift/_helpers/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::HashSet;

use sqlbuild_core::text::main::python_casefold::python_casefold;
use sqlquack_syntax::expressions::queries::models::{JoinKind, Select, With};
use sqlquack_syntax::expressions::queries::models::{Join, JoinKind, Select, With};
use sqlquack_syntax::{Expression, ExpressionWalk};

use crate::source_drift::constants::{COUNT_FUNCTION, OPAQUE_KINDS, SHARED_SCOPE_RELATIONS};
Expand Down Expand Up @@ -141,17 +141,14 @@ impl<'a> Walk<'a> {
.map(|cte| std::ptr::from_ref(&cte.this))
.collect();
let mut local: Vec<(Option<String>, bool)> = Vec::new();
let relations = select
.from
.iter()
.flat_map(|from| from.expressions.iter())
.chain(select.joins.iter().map(|join| &join.this));
let (items, joins): (Vec<&Expression>, Vec<&Join>) = from_items_and_joins(select);
let relations = items.into_iter().chain(joins.iter().map(|join| &join.this));
for relation in relations {
walked.insert(std::ptr::from_ref(relation));
local.extend(self.relation(relation, &ctes, outer));
}
let drifted_here: bool = local.iter().any(|(_, exposes)| *exposes);
for join in &select.joins {
for join in joins {
let natural: bool = matches!(
join.kind,
JoinKind::Natural
Expand Down Expand Up @@ -338,3 +335,19 @@ fn nested_queries(expression: &Expression) -> Vec<&Expression> {
}
found
}

/// The select's FROM items and joins, with each unaliased joined FROM item read as its left side and joins.
fn from_items_and_joins(select: &Select) -> (Vec<&Expression>, Vec<&Join>) {
let mut items: Vec<&Expression> = Vec::new();
let mut joins: Vec<&Join> = select.joins.iter().collect();
for item in select.from.iter().flat_map(|from| from.expressions.iter()) {
match item {
Expression::JoinedTable(joined) if joined.alias.is_none() => {
items.push(&joined.left);
joins.extend(joined.joins.iter());
}
_ => items.push(item),
}
}
(items, joins)
}
Loading
Loading