Skip to content
Merged
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
3 changes: 3 additions & 0 deletions crates/sqlbuild-analysis/src/assembly/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! The native model analysis session: catalog, dataflow scheduling, projection and shape publication.

pub mod project;
1 change: 1 addition & 0 deletions crates/sqlbuild-analysis/src/assembly/project/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! Compiled project assembly: resources, dependencies, destinations and their diagnostics.
1 change: 1 addition & 0 deletions crates/sqlbuild-analysis/src/contracts/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! Model column contracts and promotion conflicts.
5 changes: 5 additions & 0 deletions crates/sqlbuild-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

#![forbid(unsafe_code)]

pub mod assembly;
pub mod column_references;
pub mod compiler;
mod constants;
pub mod contracts;
pub mod lineage;
pub mod query_analysis;
pub mod semantic_checks;
pub mod semantic_usage;
pub mod semantic_validation;
pub mod sql_tokens;
pub mod type_system;
1 change: 1 addition & 0 deletions crates/sqlbuild-analysis/src/lineage/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! Fast column lineage facts for compiled models.
1 change: 1 addition & 0 deletions crates/sqlbuild-analysis/src/semantic_checks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! Semantic completion: type recovery, metadata checks, diagnostic recovery and explanations.
1 change: 1 addition & 0 deletions crates/sqlbuild-analysis/src/type_system/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! Type normalization and type equality shared by every analysis stage.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native model analysis session functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native contract functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native column lineage functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
7 changes: 7 additions & 0 deletions crates/sqlbuild-python/src/bindings/_helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
pub(crate) mod analysis;
pub(crate) mod analysis_session;
pub(crate) mod attachments;
pub(crate) mod boundary;
pub(crate) mod cache;
pub(crate) mod contracts;
pub(crate) mod discovery;
pub(crate) mod lineage;
pub(crate) mod model_config;
pub(crate) mod project_assembly;
pub(crate) mod render;
pub(crate) mod rules;
pub(crate) mod scopes;
pub(crate) mod semantic_checks;
pub(crate) mod sql_test_glue;
pub(crate) mod sqltext;
pub(crate) mod type_system;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native project assembly functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native semantic completion functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native SQL test planning functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod registration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Register the native type system functions.

use pyo3::prelude::{Bound, PyModule, PyResult};

pub(crate) fn register(_module: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
16 changes: 15 additions & 1 deletion crates/sqlbuild-python/src/bindings/main/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use sqlbuild_rules::constants::{API_VERSION, NATIVE_BUILD_IDENTITY};

use crate::bindings::_helpers::boundary::panics::NativeCompilerError;
use crate::bindings::_helpers::{
analysis, attachments, boundary, cache, discovery, model_config, render, rules, scopes, sqltext,
analysis, analysis_session, attachments, boundary, cache, contracts, discovery, lineage,
model_config, project_assembly, render, rules, scopes, semantic_checks, sql_test_glue, sqltext,
type_system,
};
use crate::bindings::models;

Expand Down Expand Up @@ -32,7 +34,19 @@ pub fn _native(module: &Bound<'_, PyModule>) -> PyResult<()> {
render::macro_calls::register(module)?;
cache::native_store::register(module)?;
attachments::registration::register(module)?;
register_analysis_stages(module)?;
module.add("API_VERSION", API_VERSION)?;
module.add("BUILD_IDENTITY", NATIVE_BUILD_IDENTITY)?;
Ok(())
}

fn register_analysis_stages(module: &Bound<'_, PyModule>) -> PyResult<()> {
type_system::registration::register(module)?;
analysis_session::registration::register(module)?;
semantic_checks::registration::register(module)?;
contracts::registration::register(module)?;
lineage::registration::register(module)?;
sql_test_glue::registration::register(module)?;
project_assembly::registration::register(module)?;
Ok(())
}
14 changes: 14 additions & 0 deletions src/sqlbuild/_native.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ def content_digest(parts: list[str]) -> str: ...
def fingerprint_project_files(root: str, excluded_files: list[str]) -> str: ...
def digest_files(paths: list[str]) -> list[str | None]: ...

# Native analysis: type system.

# Native analysis: model analysis session.

# Native analysis: semantic completion.

# Native analysis: contracts.

# Native analysis: column lineage facts.

# Native analysis: SQL test planning glue.

# Native analysis: compiled project assembly.

# Internal oracle hooks for tests that compare native foundations with Python; not an API.
def _oracle_json_dumps(dialect_json: str, value_json: str) -> str: ...
def _oracle_text_positions(
Expand Down
14 changes: 14 additions & 0 deletions src/sqlbuild/adapter/type_system/main/_native_normalize_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Native type normalization for the preview compiler engine."""

from __future__ import annotations

from sqlbuild.adapter.contract.models import NormalizedType
from sqlbuild.adapter.contract.types import TypeDialect


def normalize_native_type(
*, type_sql: str, dialect: TypeDialect | str | None
) -> NormalizedType | None:
"""Return the native normalization, or None where Python must normalize the type."""

return None
26 changes: 21 additions & 5 deletions src/sqlbuild/cli/commands/_helpers/compile/target_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
DiagnosticSeverity,
FunctionLanguage,
)
from sqlbuild.compiler.frontier.main.native_stage_enabled import native_stage_enabled
from sqlbuild.compiler.frontier.types import NativeStage
from sqlbuild.compiler.planner.exceptions import PlannerInputError
from sqlbuild.compiler.planner.main.execution.sql_test_artifacts import (
plan_and_render_sql_test_artifacts,
Expand All @@ -56,6 +58,9 @@
)
from sqlbuild.compiler.planner.models import AuditPlanEntry, NativeSqlTestArtifact, PlanOutput
from sqlbuild.compiler.profiling.main.record import record_compile_timing
from sqlbuild.compiler.sql_test_glue.main.plan_native_sql_test_artifacts import (
plan_native_sql_test_artifacts,
)
from sqlbuild.executor.testing.main.comparison_sql import build_sql_test_comparison_sql
from sqlbuild.runtime.observability.classes.operation_lifecycle import OperationLifecycle

Expand Down Expand Up @@ -569,12 +574,23 @@ def _plan_static_test_artifacts(
with OperationLifecycle(
operation_kind="project", operation_name="sql_test_planning"
) as lifecycle:
native_artifacts: tuple[NativeSqlTestArtifact, ...] = plan_and_render_sql_test_artifacts(
project=project,
tests=tests,
adapter=adapter,
sql_analysis_enabled=project.settings.sql_analysis,
native_artifacts: tuple[NativeSqlTestArtifact, ...] | None = (
plan_native_sql_test_artifacts(
project=project,
tests=tests,
adapter=adapter,
sql_analysis_enabled=project.settings.sql_analysis,
)
if native_stage_enabled(NativeStage.SQL_TEST_GLUE)
else None
)
if native_artifacts is None:
native_artifacts = plan_and_render_sql_test_artifacts(
project=project,
tests=tests,
adapter=adapter,
sql_analysis_enabled=project.settings.sql_analysis,
)
lifecycle.completed(metadata={"item_count": len(native_artifacts)})
return native_artifacts

Expand Down
1 change: 1 addition & 0 deletions src/sqlbuild/compiler/analysis_session/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The native model analysis session for the preview compiler engine."""
1 change: 1 addition & 0 deletions src/sqlbuild/compiler/analysis_session/main/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Native model analysis session entry points."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Analyze model SQL natively for the preview compiler engine."""

from __future__ import annotations

from sqlbuild.compiler.analysis_session.models import NativeModelAnalysisRequest
from sqlbuild.compiler.compile.models import ModelSqlAnalysis


def analyze_native_model_sql(
*, request: NativeModelAnalysisRequest
) -> dict[str, ModelSqlAnalysis] | None:
"""Return each model's analysis (and any pivot proof) by name, or None to defer to Python."""

return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Infer expression-source shapes natively for the preview compiler engine."""

from __future__ import annotations

from sqlbuild.adapter.contract.models import ExpressionInferenceProfile


def infer_native_expression_source_shapes(
*, expressions: tuple[str, ...], profile: ExpressionInferenceProfile
) -> tuple[dict[str, str] | None, ...] | None:
"""Return one shape per expression, or None where Python must infer the shapes."""

return None
27 changes: 27 additions & 0 deletions src/sqlbuild/compiler/analysis_session/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Inputs handed to the native model analysis session."""

from __future__ import annotations

from dataclasses import dataclass

from sqlbuild.adapter.contract.models import ExpressionInferenceProfile
from sqlbuild.compiler.compile.models import CompileModelInput, ModelAnalysisCaching
from sqlbuild.compiler.lineage.types import InferredNullability
from sqlbuild.spec.contracts.models import SchemaDynamicColumnFamily


@dataclass(frozen=True)
class NativeModelAnalysisRequest:
"""The Python model analysis's arguments plus the facts dynamic pivot proofs need."""

known_functions: tuple[str, ...]
known_types: tuple[str, ...]
model_inputs: tuple[CompileModelInput, ...]
column_nullability_by_table: dict[str, dict[str, InferredNullability]]
column_types_by_table: dict[str, dict[str, str]]
inference_profile: ExpressionInferenceProfile
allow_compact_analysis: bool
rich_type_inference: bool
analysis_caching: ModelAnalysisCaching | None
complete_binding_schemas: dict[str, dict[str, str]]
dynamic_families_by_table: dict[str, tuple[SchemaDynamicColumnFamily, ...]]
Loading
Loading