Skip to content

Commit bc6b1b2

Browse files
authored
refactor: port the compiler frontier, pipeline helpers and model assembly to the native extension (#1097)
* refactor: run the compiler frontier and stage captures natively * refactor: validate targets and apply target defaults in the native compile driver * style: sort imports after the frontier port * refactor: run macro store keys, deferral, relation targets and diff selection natively * refactor: build Python plan entries and macro store module digests natively * style: satisfy clippy in the native frontier and pipeline ports * refactor: align the native frontier and pipeline ports with the fensu and boundary rules * chore: update the Python boundary ratchet after the frontier port * refactor: walk macro modules over the shared CPython tree * refactor: compute semantic shapes, coverage and model analysis rows natively * refactor: build each compiled model natively * refactor: rebind models to inspected source columns natively * chore: update the Python boundary ratchet after the assembly port * test: drop the deleted assembly package from the differential code scan
1 parent ab0217e commit bc6b1b2

221 files changed

Lines changed: 7574 additions & 4298 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.

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/sqlbuild-analysis/src/assembly/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
33
pub mod analysis_session;
44
pub mod project;
5+
pub mod target_checks;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Error codes and values of the target namespace checks.
2+
3+
/// A target, resource or loader schema that keeps the logical schema.
4+
pub const PRESERVE_TARGET_VALUE: &str = "preserve";
5+
/// Execution needs an explicit database and schema for every model and seed.
6+
pub const MISSING_TARGET_PARTS_CODE: &str = "S101";
7+
/// Two targets write managed loader data to one namespace.
8+
pub const LOADER_COLLISION_CODE: &str = "S102";
9+
/// A managed write has no explicit physical schema.
10+
pub const MANAGED_WRITE_SCHEMA_CODE: &str = "S103";
11+
/// A named target chooses no schema strategy.
12+
pub const NAMED_TARGET_SCHEMA_CODE: &str = "S104";
13+
pub(crate) const DATABASE_PART: &str = "database";
14+
pub(crate) const SCHEMA_PART: &str = "schema";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! The target namespace check failures.
2+
3+
use crate::assembly::target_checks::models::{LoaderCollision, MissingParts};
4+
5+
/// One target namespace check failure.
6+
#[derive(Debug, Clone, PartialEq, Eq)]
7+
pub enum TargetError {
8+
/// A resource of an adapter that needs both parts resolved without some of them.
9+
MissingParts(MissingParts),
10+
/// Two targets on one connection write managed loader data to one namespace.
11+
LoaderCollision(LoaderCollision),
12+
/// A managed write, named by its label, without an explicit physical schema.
13+
ManagedWriteSchema(String),
14+
/// A named target without an explicit schema.
15+
NamedTargetSchema(String),
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! `_optional_explicit_schema`: a schema that names a physical write schema.
2+
3+
use sqlbuild_core::text::main::python_strip::python_strip;
4+
5+
use crate::assembly::target_checks::constants::PRESERVE_TARGET_VALUE;
6+
7+
/// The stripped schema, unless it is blank or `preserve`.
8+
pub fn explicit_write_schema(value: Option<&str>) -> Option<String> {
9+
let schema: &str = python_strip(value?);
10+
(!schema.is_empty() && schema != PRESERVE_TARGET_VALUE).then(|| schema.to_owned())
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! The namespace a loader collision reports: the first shared one by its Python `repr`.
2+
3+
use sqlbuild_core::text::main::python_str_repr::python_str_repr;
4+
5+
/// Python's `repr` of an optional string.
6+
fn optional_repr(value: Option<&String>) -> String {
7+
value.map_or_else(|| "None".to_owned(), |text| python_str_repr(text))
8+
}
9+
10+
/// `sorted(namespaces, key=repr)[0]` of `(database, schema)` pairs, or `None` when empty.
11+
pub fn first_shared_namespace(
12+
namespaces: &[(Option<String>, Option<String>)],
13+
) -> Option<(Option<String>, Option<String>)> {
14+
namespaces
15+
.iter()
16+
.min_by_key(|(database, schema)| {
17+
format!(
18+
"({}, {})",
19+
optional_repr(database.as_ref()),
20+
optional_repr(schema.as_ref())
21+
)
22+
})
23+
.cloned()
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! The parts of a relation location execution needs but the location lacks.
2+
3+
use crate::assembly::target_checks::constants::{DATABASE_PART, SCHEMA_PART};
4+
5+
/// `database` and then `schema`, each when it is missing.
6+
pub fn missing_target_parts(database: Option<&str>, schema: Option<&str>) -> Vec<&'static str> {
7+
let mut missing: Vec<&'static str> = Vec::new();
8+
if database.is_none() {
9+
missing.push(DATABASE_PART);
10+
}
11+
if schema.is_none() {
12+
missing.push(SCHEMA_PART);
13+
}
14+
missing
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod explicit_write_schema;
2+
pub mod first_shared_namespace;
3+
pub mod missing_target_parts;
4+
pub mod target_error_message;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! The message Python raises for a target namespace check failure.
2+
3+
use sqlbuild_core::text::main::python_str_repr::python_str_repr;
4+
5+
use crate::assembly::target_checks::constants::PRESERVE_TARGET_VALUE;
6+
use crate::assembly::target_checks::errors::TargetError;
7+
use crate::assembly::target_checks::main::missing_target_parts::missing_target_parts;
8+
9+
/// Python's `repr` of an optional string.
10+
fn optional_repr(value: Option<&String>) -> String {
11+
value.map_or_else(|| "None".to_owned(), |text| python_str_repr(text))
12+
}
13+
14+
/// The `PlannerInputError` message of `error`.
15+
pub fn target_error_message(error: &TargetError) -> String {
16+
match error {
17+
TargetError::MissingParts(parts) => format!(
18+
"{} execution requires explicit target {}. {} '{}' resolved to database={} schema={}. \
19+
Set them in the model config, the environment config, or the project defaults.",
20+
parts.adapter_name,
21+
missing_target_parts(parts.database.as_deref(), parts.schema.as_deref()).join(", "),
22+
parts.resource_kind,
23+
parts.resource_name,
24+
optional_repr(parts.database.as_ref()),
25+
optional_repr(parts.schema.as_ref()),
26+
),
27+
TargetError::LoaderCollision(collision) => format!(
28+
"Managed loader write collision: targets '{left}' and '{right}' both resolve to \
29+
database={} schema={}. Set distinct targets.{left}.loader_schema and \
30+
targets.{right}.loader_schema values.",
31+
optional_repr(collision.database.as_ref()),
32+
optional_repr(collision.schema.as_ref()),
33+
left = collision.left_target,
34+
right = collision.right_target,
35+
),
36+
TargetError::ManagedWriteSchema(label) => format!(
37+
"{label} has no explicitly resolved physical write schema. Set schema on the \
38+
resource or its defaults, selected target, loader_schema, or connection."
39+
),
40+
TargetError::NamedTargetSchema(target) => format!(
41+
"Named target '{target}' must explicitly set schema to a nonblank literal or \
42+
'{PRESERVE_TARGET_VALUE}'. Resource schemas, defaults, and connection schemas do \
43+
not select a named target schema strategy."
44+
),
45+
}
46+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub mod constants;
2+
pub mod errors;
3+
pub mod main;
4+
pub mod models;
5+
6+
#[cfg(test)]
7+
mod tests;

0 commit comments

Comments
 (0)