Skip to content

Commit f09b69b

Browse files
authored
refactor: read every state table name from sqlbuild-core (#1423)
The microbatch, node result, audit result and janitor event table names were still separate Python literals, and a few Rust paths repeated the table names as strings. Python now imports all ten names from the native module, and Rust uses the sqlbuild-core constants. The microbatch table name no longer round-trips through the Python host table. The SQL Server state table builders share one helper instead of five copies of the same build, strip and wrap steps; their SQL is unchanged.
1 parent 58c4134 commit f09b69b

26 files changed

Lines changed: 99 additions & 100 deletions

File tree

‎crates/sqlbuild-host/src/entries/_helpers/executor.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,6 @@ pub(crate) const ENTRIES: &[HostEntry] = &[
504504
kind: HostKind::Value,
505505
edge: HostEdge::Executor,
506506
},
507-
HostEntry {
508-
name: "MICROBATCH_TABLE_NAME",
509-
kind: HostKind::Value,
510-
edge: HostEdge::Executor,
511-
},
512507
HostEntry {
513508
name: "MicrobatchStateError",
514509
kind: HostKind::Exception,

‎crates/sqlbuild-host/src/entries/models.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ pub enum ExecutorHost {
303303
MicrobatchColumnTypes,
304304
MicrobatchDirectIndexes,
305305
MicrobatchGenerationWildcard,
306-
MicrobatchTableName,
307306
MicrobatchStateError,
308307
MicrobatchCoverageProjection,
309308
MicrobatchInterval,

‎crates/sqlbuild-orchestration/src/warehouse_metadata/main/ingest/ingest_fingerprints.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Import bounded fingerprint history without conflating semantic and exact-content hashes.
22
33
use serde_json::json;
4+
use sqlbuild_core::constants::FINGERPRINT_TABLE_NAME;
45
use sqlbuild_recall::records::main::sha256_hex::sha256_hex;
56
use uuid::Uuid;
67

@@ -37,7 +38,7 @@ pub async fn ingest_fingerprints(
3738
(
3839
record.state_database.as_deref(),
3940
&record.state_schema,
40-
"_sqlbuild_fingerprints",
41+
FINGERPRINT_TABLE_NAME,
4142
),
4243
&source_event_id,
4344
)?;

‎crates/sqlbuild-orchestration/src/warehouse_metadata/main/ingest/ingest_source_freshness.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Persist source identities; only legacy rows use a fixed observation-key fallback.
22
33
use serde_json::json;
4+
use sqlbuild_core::constants::SOURCE_FRESHNESS_TABLE_NAME;
45
use sqlbuild_state::freshness::main::event_id::event_id as legacy_event_id;
56
use sqlbuild_state::freshness::models::FreshnessEventIdentity;
67
use uuid::Uuid;
@@ -53,7 +54,7 @@ pub async fn ingest_source_freshness(
5354
(
5455
record.state_database.as_deref(),
5556
&record.state_schema,
56-
"_sqlbuild_source_freshness",
57+
SOURCE_FRESHNESS_TABLE_NAME,
5758
),
5859
&source_event_id,
5960
)?;

‎crates/sqlbuild-python/src/bindings/_helpers/exported_constants/constants.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ use sqlbuild_core::command_output::constants::{
1818
INVOCATION_CONTEXT_ENV,
1919
};
2020
use sqlbuild_core::constants::{
21-
COLUMN_MIGRATION_TABLE_NAME, CONSUMPTION_TABLE_NAME, FINGERPRINT_TABLE_NAME,
22-
MIGRATION_TABLE_NAME, OLD_NAME_VIEW_TABLE_NAME, PROJECT_CONFIG_FILENAME,
21+
AUDIT_RESULTS_TABLE_NAME, COLUMN_MIGRATION_TABLE_NAME, CONSUMPTION_TABLE_NAME,
22+
FINGERPRINT_TABLE_NAME, JANITOR_EVENTS_TABLE_NAME, MICROBATCH_TABLE_NAME, MIGRATION_TABLE_NAME,
23+
NODE_RESULTS_TABLE_NAME, OLD_NAME_VIEW_TABLE_NAME, PROJECT_CONFIG_FILENAME,
2324
PYTHON_INIT_MODULE_STEM, PYTHON_NODE_ROOT, SETTINGS_SECTION, SOURCE_FRESHNESS_TABLE_NAME,
2425
STAGED_PROMOTION_MODE, TABLE_PROMOTION_MODE_SETTING_KEY, ZERO_DAY_DURATION,
2526
};
@@ -88,6 +89,10 @@ pub(crate) const EXPORTED_TEXTS: &[(&str, &str)] = &[
8889
("MIGRATION_TABLE_NAME", MIGRATION_TABLE_NAME),
8990
("COLUMN_MIGRATION_TABLE_NAME", COLUMN_MIGRATION_TABLE_NAME),
9091
("OLD_NAME_VIEW_TABLE_NAME", OLD_NAME_VIEW_TABLE_NAME),
92+
("MICROBATCH_TABLE_NAME", MICROBATCH_TABLE_NAME),
93+
("NODE_RESULTS_TABLE_NAME", NODE_RESULTS_TABLE_NAME),
94+
("AUDIT_RESULTS_TABLE_NAME", AUDIT_RESULTS_TABLE_NAME),
95+
("JANITOR_EVENTS_TABLE_NAME", JANITOR_EVENTS_TABLE_NAME),
9196
("COLUMN_NODE_TYPE", COLUMN_NODE_TYPE),
9297
("COLUMN_NODE_NAME", COLUMN_NODE_NAME),
9398
("COLUMN_TARGET_DATABASE", COLUMN_TARGET_DATABASE),

‎crates/sqlbuild-python/src/bindings/_helpers/microbatches/statements.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Direct-mode microbatch state DDL, idempotent inserts, reads and event IDs.
22
33
use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyModuleMethods, PyResult, Python};
4-
use pyo3::types::{PyDict, PyTuple};
4+
use pyo3::types::{PyDict, PyString, PyTuple};
55
use pyo3::{pyfunction, wrap_pyfunction};
6+
use sqlbuild_core::constants::MICROBATCH_TABLE_NAME;
67
use sqlbuild_host::entries::models::{AdapterHost, ExecutorHost};
78
use sqlbuild_state::events::main::microbatch_event_id::microbatch_event_id;
89
use sqlbuild_state::microbatches::main::create_index_sqls::create_index_sqls;
@@ -81,7 +82,7 @@ fn qualified_table<'py>(
8182
(database, schema): (&Bound<'py, PyAny>, &Bound<'py, PyAny>),
8283
) -> PyResult<Option<String>> {
8384
let py: Python<'py> = render_qualified_name.py();
84-
let table_name: Bound<'py, PyAny> = host::entry(py, ExecutorHost::MicrobatchTableName)?;
85+
let table_name: Bound<'py, PyAny> = PyString::new(py, MICROBATCH_TABLE_NAME).into_any();
8586
optional_text(&call_with(
8687
render_qualified_name,
8788
&[
@@ -236,14 +237,13 @@ fn create_indexes<'py>(request: Option<&Bound<'py, PyDict>>) -> PyResult<Bound<'
236237
&[
237238
("database", request.get("database")?),
238239
("schema", schema.clone()),
239-
("name", host::entry(py, ExecutorHost::MicrobatchTableName)?),
240+
("name", PyString::new(py, MICROBATCH_TABLE_NAME).into_any()),
240241
],
241242
)?;
242243
let table: String = if rendered.is_truthy()? {
243244
rendered.extract()?
244245
} else {
245-
let name: String = host::entry(py, ExecutorHost::MicrobatchTableName)?.extract()?;
246-
format!("{}.{name}", schema.str()?)
246+
format!("{}.{MICROBATCH_TABLE_NAME}", schema.str()?)
247247
};
248248
let render_identifier: Bound<'_, PyAny> = request.get("render_identifier")?;
249249
let identifier = |name: &Bound<'_, PyAny>| -> PyResult<String> {

‎crates/sqlbuild-python/src/bindings/_helpers/native_host/warehouse_metadata.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use sqlbuild_config::command_connection::constants::{
99
DUCKDB_ADAPTER, DUCKDB_MEMORY_DATABASE, LOCAL_DATABASE_PATH_KEYS,
1010
};
1111
use sqlbuild_core::constants::{
12-
COLUMN_MIGRATION_TABLE_NAME, CONSUMPTION_TABLE_NAME, FINGERPRINT_TABLE_NAME,
13-
NODE_RESULTS_TABLE_NAME, SOURCE_FRESHNESS_TABLE_NAME,
12+
AUDIT_RESULTS_TABLE_NAME, COLUMN_MIGRATION_TABLE_NAME, CONSUMPTION_TABLE_NAME,
13+
FINGERPRINT_TABLE_NAME, JANITOR_EVENTS_TABLE_NAME, MICROBATCH_TABLE_NAME, MIGRATION_TABLE_NAME,
14+
NODE_RESULTS_TABLE_NAME, OLD_NAME_VIEW_TABLE_NAME, SOURCE_FRESHNESS_TABLE_NAME,
1415
};
1516
use sqlbuild_core::models::SqlValue;
1617
use sqlbuild_orchestration::warehouse_metadata::constants::MAX_HISTORY_RECORDS;
@@ -167,7 +168,7 @@ fn read_page(
167168
read.after.as_ref().map(|cursor| cursor.as_slice()),
168169
read.observed_since,
169170
read.limit,
170-
"_sqlbuild_audit_results",
171+
AUDIT_RESULTS_TABLE_NAME,
171172
event_columns.as_slice(),
172173
"occurred_at",
173174
),
@@ -176,7 +177,7 @@ fn read_page(
176177
read.after.as_ref().map(|cursor| cursor.as_slice()),
177178
read.observed_since,
178179
read.limit,
179-
"_sqlbuild_janitor_events",
180+
JANITOR_EVENTS_TABLE_NAME,
180181
event_columns.as_slice(),
181182
"occurred_at",
182183
),
@@ -185,7 +186,7 @@ fn read_page(
185186
read.after.as_ref().map(|cursor| cursor.as_slice()),
186187
read.observed_since,
187188
read.limit,
188-
"_sqlbuild_migrations",
189+
MIGRATION_TABLE_NAME,
189190
MIGRATION_COLUMNS.as_slice(),
190191
"created_at",
191192
),
@@ -194,7 +195,7 @@ fn read_page(
194195
read.after.as_ref().map(|cursor| cursor.as_slice()),
195196
read.observed_since,
196197
read.limit,
197-
"_sqlbuild_old_name_views",
198+
OLD_NAME_VIEW_TABLE_NAME,
198199
OLD_NAME_VIEW_COLUMNS.as_slice(),
199200
"created_at",
200201
),
@@ -203,7 +204,7 @@ fn read_page(
203204
read.after.as_ref().map(|cursor| cursor.as_slice()),
204205
read.observed_since,
205206
read.limit,
206-
"_sqlbuild_microbatches",
207+
MICROBATCH_TABLE_NAME,
207208
event_columns.as_slice(),
208209
"created_at",
209210
),

‎fensu.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ reason = "Native code resolves these through the sqlbuild._native_host name tabl
634634

635635
[[targets.python.dead_code.roots]]
636636
modules = ["sqlbuild.microbatches.constants"]
637-
symbols = ["MICROBATCH_COLUMNS", "MICROBATCH_COLUMN_TYPES", "MICROBATCH_DIRECT_INDEXES", "MICROBATCH_GENERATION_WILDCARD", "MICROBATCH_TABLE_NAME"]
637+
symbols = ["MICROBATCH_COLUMNS", "MICROBATCH_COLUMN_TYPES", "MICROBATCH_DIRECT_INDEXES", "MICROBATCH_GENERATION_WILDCARD"]
638638
reason = "Native code resolves these through the sqlbuild._native_host name table."
639639

640640
[[targets.python.dead_code.roots]]

‎src/sqlbuild/_native.pyi‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ CONSUMPTION_TABLE_NAME: str
188188
MIGRATION_TABLE_NAME: str
189189
COLUMN_MIGRATION_TABLE_NAME: str
190190
OLD_NAME_VIEW_TABLE_NAME: str
191+
MICROBATCH_TABLE_NAME: str
192+
NODE_RESULTS_TABLE_NAME: str
193+
AUDIT_RESULTS_TABLE_NAME: str
194+
JANITOR_EVENTS_TABLE_NAME: str
191195
COLUMN_NODE_TYPE: str
192196
COLUMN_NODE_NAME: str
193197
COLUMN_TARGET_DATABASE: str

‎src/sqlbuild/_native_host.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@
507507
"sqlbuild.microbatches.constants",
508508
"MICROBATCH_GENERATION_WILDCARD",
509509
),
510-
"MICROBATCH_TABLE_NAME": ("sqlbuild.microbatches.constants", "MICROBATCH_TABLE_NAME"),
511510
"MicrobatchStateError": ("sqlbuild.microbatches.exceptions", "MicrobatchStateError"),
512511
"MicrobatchCoverageProjection": (
513512
"sqlbuild.microbatches.models",

0 commit comments

Comments
 (0)