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
12 changes: 6 additions & 6 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ proc-macro2 = { version = "1", features = ["span-locations"] }
pyo3 = { version = "0.26", features = ["abi3-py312"] }
rpassword = "7.5.4"
rcgen = "0.14"
sqlquack-semantics = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "f48808e9b3ea7c3f928a758459a2b55fff7301a3" }
sqlquack-syntax = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "f48808e9b3ea7c3f928a758459a2b55fff7301a3" }
sqlquack-syntax-clickhouse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "f48808e9b3ea7c3f928a758459a2b55fff7301a3" }
sqlquack-semantics = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "7e5e1b1d485b74043a5cbf0f2cdb3eb73316f6de" }
sqlquack-syntax = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "7e5e1b1d485b74043a5cbf0f2cdb3eb73316f6de" }
sqlquack-syntax-clickhouse = { git = "https://github.com/sqlstack-io/sqlquack.git", rev = "7e5e1b1d485b74043a5cbf0f2cdb3eb73316f6de" }
polyglot-sql = { git = "https://github.com/sqlstack-io/polyglot.git", rev = "8767d688c5b504ad609645e27ab77a260d91c5a1", default-features = false, features = [
"ast-tools",
"builder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use sqlquack_syntax::Parsed;
use sqlquack_syntax_clickhouse::parse_strict;

use crate::analysis_route::_helpers::clickhouse_spelling::clickhouse_spelling;
use crate::analysis_route::constants::{
CLICKHOUSE_DIALECT, CLICKHOUSE_STUB_PREFIX, STATEMENTS_CONSTRUCT,
};
use crate::analysis_route::constants::{CLICKHOUSE_DIALECT, CLICKHOUSE_STUB_PREFIX};
use crate::analysis_route::main::clickhouse_type_match::clickhouse_type_match;
use crate::analysis_route::models::{ClickHouseDialect, ParserGap, TypeMatch};
use crate::analysis_route::types::NativeDialect;
Expand All @@ -20,19 +18,11 @@ impl NativeDialect for ClickHouseDialect {
CLICKHOUSE_DIALECT
}

fn read_whole(&self, sql: &str) -> Result<(), ParserGap> {
let parsed: Parsed = self.parse(sql)?;
match (parsed.gaps.first(), parsed.statements.len()) {
(Some(gap), _) => Err(ParserGap {
construct: gap.construct.to_owned(),
offset: gap.start,
}),
(None, 1) => Ok(()),
(None, _) => Err(ParserGap {
construct: STATEMENTS_CONSTRUCT.to_owned(),
offset: sql.len(),
}),
}
fn parse(&self, sql: &str) -> Result<Parsed, ParserGap> {
parse_strict(sql).map_err(|error| ParserGap {
construct: error.message,
offset: error.position,
})
}

fn stub_prefix(&self) -> &'static str {
Expand All @@ -41,14 +31,6 @@ impl NativeDialect for ClickHouseDialect {
}

impl ClickHouseDialect {
/// Every statement of `sql` with the parser's named gaps, or the first error.
pub fn parse(&self, sql: &str) -> Result<Parsed, ParserGap> {
parse_strict(sql).map_err(|error| ParserGap {
construct: error.message,
offset: error.position,
})
}

/// The ClickHouse profile: names compared with case, types as ClickHouse 26.1 reports them.
#[must_use]
pub fn profile(&self) -> &'static dyn DialectProfile {
Expand Down
2 changes: 2 additions & 0 deletions crates/sqlbuild-analysis/src/analysis_route/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub(crate) const CLICKHOUSE_DIALECT: &str = "clickhouse";
pub(crate) const CLICKHOUSE_STUB_PREFIX: &str = "__sqlbuild_";
/// The construct of SQL holding more than one statement.
pub(crate) const STATEMENTS_CONSTRUCT: &str = "more than one statement";
/// The construct of a statement a parser kept as unparsed text.
pub(crate) const UNPARSED_STATEMENT_CONSTRUCT: &str = "unparsed statement";
/// Polyglot's ClickHouse respelling of each SQL type alias (`{}` keeps the arguments) and family.
pub(crate) const CLICKHOUSE_TYPE_ALIASES: &[(&str, &str, Option<TypeFamily>)] = &[
("BOOLEAN", "Bool", None),
Expand Down
4 changes: 4 additions & 0 deletions crates/sqlbuild-analysis/src/analysis_route/tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#[path = "tests/helpers.rs"]
mod helpers;
#[path = "tests/test_clickhouse_dialect.rs"]
mod test_clickhouse_dialect;
#[path = "tests/test_clickhouse_type_match.rs"]
mod test_clickhouse_type_match;
#[path = "tests/test_native_gap.rs"]
mod test_native_gap;
#[path = "tests/test_planner_routes.rs"]
mod test_planner_routes;
#[path = "tests/test_types.rs"]
mod test_types;
27 changes: 27 additions & 0 deletions crates/sqlbuild-analysis/src/analysis_route/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::planner_fixtures::models::{FixtureColumn, FixtureStarRelation};
use crate::relation_names::models::RelationName;

/// A relation written `schema.name`, or `name` without a schema.
pub(super) fn qualified(relation: &RelationName) -> String {
let parts: Vec<&str> = relation
.schema
.iter()
.map(String::as_str)
.chain([relation.name.as_str()])
.collect();
parts.join(".")
}

/// A fixture relation `name` with one typed column.
pub(super) fn fixture_relation(name: &str) -> FixtureStarRelation {
FixtureStarRelation {
key: ("model".to_owned(), name.to_owned()),
columns: vec![FixtureColumn {
name: "id".to_owned(),
folded_name: "id".to_owned(),
sql_type: Some("Int32".to_owned()),
nullable: Some(false),
}],
authoritative: true,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ fn given_clickhouse_model_sql_when_probing_the_native_parser_then_only_unreadabl
expected_gap: None,
},
NativeGapTestCase {
description: "INTO OUTFILE is a named gap at its line and column",
sql: "SELECT 'é' AS a\nFROM t\n INTO OUTFILE 'x.csv'",
description: "WITH TIES is a named gap at its line and column",
sql: "SELECT 'é' AS a\nFROM t\n ORDER BY a LIMIT 1 WITH TIES",
placeholders: &[],
expected_gap: Some(LocatedGap {
construct: "into_outfile".to_owned(),
construct: "with_ties".to_owned(),
line: 3,
column: 3,
column: 22,
}),
},
NativeGapTestCase {
Expand Down
Loading
Loading