Skip to content

Commit e9221bc

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/rule-facts-sqlquack
2 parents 0352b44 + decd291 commit e9221bc

88 files changed

Lines changed: 1920 additions & 248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.release-please-manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.198.0"
2+
".": "0.199.0"
33
}

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [0.199.0](https://github.com/sqlstack-io/sqlbuild/compare/v0.198.0...v0.199.0) (2026-11-08)
4+
5+
6+
### Features
7+
8+
* **analysis:** route each dialect's SQL analysis to Polyglot or a native module ([#1354](https://github.com/sqlstack-io/sqlbuild/issues/1354)) ([97ab62c](https://github.com/sqlstack-io/sqlbuild/commit/97ab62c82a511e0fb79ff7f8626f3829a1845b80))
9+
10+
11+
### Bug Fixes
12+
13+
* **ui:** wrap list toolbars instead of clipping their filters and counts ([#1349](https://github.com/sqlstack-io/sqlbuild/issues/1349)) ([702224e](https://github.com/sqlstack-io/sqlbuild/commit/702224e261e03f106e2a028acddedd3486e0939b))
14+
315
## [0.198.0](https://github.com/sqlstack-io/sqlbuild/compare/v0.197.0...v0.198.0) (2026-11-07)
416

517

‎Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! The native dialects and the diagnostic a model the native parser cannot read takes.
2+
3+
use crate::analysis_route::types::NativeDialect;
4+
5+
/// Each dialect, by its adapter's analysis dialect name, whose SQL a native module analyses.
6+
pub(crate) const NATIVE_DIALECTS: &[(&str, &dyn NativeDialect)] = &[];
7+
/// The warning, or under `require_sql_analysis` the error, for a model analysis skips.
8+
pub(crate) const SKIPPED_ANALYSIS_CODE: &str = "P026";
9+
/// ClickHouse's top-level nullability wrapper, which the native profile spells as a flag.
10+
pub(crate) const NULLABLE_WRAPPER: &str = "Nullable";
11+
/// ClickHouse's top-level dictionary-encoding wrapper, which leaves the column's type as it is.
12+
pub(crate) const LOW_CARDINALITY_WRAPPER: &str = "LowCardinality";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::analysis_route::constants::NATIVE_DIALECTS;
2+
use crate::analysis_route::models::AnalysisRoute;
3+
4+
/// The route of `dialect`, an adapter's analysis dialect name; unlisted dialects stay on Polyglot.
5+
#[must_use]
6+
pub fn analysis_route(dialect: Option<&str>) -> AnalysisRoute {
7+
dialect
8+
.and_then(|name| NATIVE_DIALECTS.iter().find(|(native, _)| *native == name))
9+
.map_or(AnalysisRoute::Legacy, |(_, module)| {
10+
AnalysisRoute::Native(*module)
11+
})
12+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::analysis_route::constants::{LOW_CARDINALITY_WRAPPER, NULLABLE_WRAPPER};
2+
use crate::analysis_route::models::TypeMatch;
3+
4+
/// A declared and an inferred ClickHouse type compared without top-level wrappers, nullability apart.
5+
#[must_use]
6+
pub fn clickhouse_type_match(declared: &str, inferred: &str, inferred_nullable: bool) -> TypeMatch {
7+
let (declared_base, declared_nullable) = unwrapped(declared);
8+
let (inferred_base, wrapped_nullable) = unwrapped(inferred);
9+
TypeMatch {
10+
same_type: declared_base == inferred_base,
11+
nullable_into_non_null: !declared_nullable && (inferred_nullable || wrapped_nullable),
12+
}
13+
}
14+
15+
/// The type inside its top-level `Nullable` and `LowCardinality` wrappers, and whether it is nullable.
16+
fn unwrapped(type_sql: &str) -> (&str, bool) {
17+
let mut current: &str = type_sql.trim();
18+
let mut nullable: bool = false;
19+
loop {
20+
if let Some(inner) = wrapped(current, NULLABLE_WRAPPER) {
21+
nullable = true;
22+
current = inner;
23+
} else if let Some(inner) = wrapped(current, LOW_CARDINALITY_WRAPPER) {
24+
current = inner;
25+
} else {
26+
return (current, nullable);
27+
}
28+
}
29+
}
30+
31+
/// The argument of `wrapper(...)` when the whole of `type_sql` is that one call.
32+
fn wrapped<'a>(type_sql: &'a str, wrapper: &str) -> Option<&'a str> {
33+
let head: &str = type_sql.get(..wrapper.len())?;
34+
if !head.eq_ignore_ascii_case(wrapper) {
35+
return None;
36+
}
37+
let inner: &str = type_sql[wrapper.len()..]
38+
.trim_start()
39+
.strip_prefix('(')?
40+
.strip_suffix(')')?;
41+
let mut depth: usize = 0;
42+
for character in inner.chars() {
43+
match character {
44+
'(' => depth += 1,
45+
')' if depth == 0 => return None,
46+
')' => depth -= 1,
47+
_ => {}
48+
}
49+
}
50+
Some(inner.trim())
51+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod analysis_route;
2+
pub mod clickhouse_type_match;
3+
pub mod native_gap;
4+
pub mod skipped_analysis;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use sqlbuild_sqltext::compiler::main::placeholder_defaults::placeholder_defaults;
2+
3+
use crate::analysis_route::models::{LocatedGap, ParserGap};
4+
use crate::analysis_route::types::NativeDialect;
5+
use crate::assembly::project::models::SyntaxCheck;
6+
use crate::compiled_project::main::text_position::text_position;
7+
use crate::compiled_project::models::TextPosition;
8+
use crate::semantic_validation::main::normalize_native::normalize_native_sql;
9+
10+
/// The native parser's first gap in `check`'s analysis SQL, with the dialect's stub spelling.
11+
pub fn native_gap(
12+
dialect: &dyn NativeDialect,
13+
check: &SyntaxCheck,
14+
) -> Result<Option<LocatedGap>, String> {
15+
let normalised: String =
16+
normalize_native_sql(&check.sql, dialect.name(), dialect.stub_prefix())?;
17+
let analysed: String = placeholder_defaults(&normalised, &check.placeholders);
18+
Ok(dialect
19+
.read_whole(&analysed)
20+
.err()
21+
.map(|gap| located(&analysed, gap)))
22+
}
23+
24+
/// The gap with the line and column of its offset; an offset past the end is the end.
25+
fn located(sql: &str, gap: ParserGap) -> LocatedGap {
26+
let before: &str = sql.get(..gap.offset).unwrap_or(sql);
27+
let position: TextPosition = text_position(sql, before.chars().count());
28+
LocatedGap {
29+
construct: gap.construct,
30+
line: position.line,
31+
column: position.column,
32+
}
33+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::analysis_route::constants::SKIPPED_ANALYSIS_CODE;
2+
use crate::analysis_route::models::LocatedGap;
3+
4+
/// P026's code and message for a model whose SQL the dialect's native parser cannot read.
5+
#[must_use]
6+
pub fn skipped_analysis(model: &str, dialect: &str, gap: &LocatedGap) -> (&'static str, String) {
7+
(
8+
SKIPPED_ANALYSIS_CODE,
9+
format!(
10+
"SQL analysis skipped for model '{model}': the {dialect} parser cannot read {} at \
11+
line {}, column {}",
12+
gap.construct, gap.line, gap.column
13+
),
14+
)
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Which engine analyses a dialect's SQL: the Polyglot path, or a native module over SQLQuack.
2+
3+
pub(crate) mod constants;
4+
pub mod main;
5+
pub mod models;
6+
pub mod types;
7+
8+
#[cfg(test)]
9+
mod tests;

0 commit comments

Comments
 (0)