Skip to content

Commit 57d7d04

Browse files
committed
T1.33 fix 4: the declared type set by describe, inference's lines kept
The marked big integers' declared types are now set on the described schema in describe_source, after assembly, from the catalog columns and the preview it already holds, so sdm-schema's inference is unchanged and the family maps' line citations into it hold. Signed-off-by: Adi Wadaskar <awadaskar@nvidia.com>
1 parent 2b1c91c commit 57d7d04

5 files changed

Lines changed: 31 additions & 10 deletions

File tree

‎rust/crates/sdm-core/src/describe.rs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ pub(crate) async fn run(
110110
};
111111

112112
let mut tables = Vec::with_capacity(names.len());
113+
// Each table's marked big integers' declared types (big_integer_types).
114+
let mut big_types = Vec::with_capacity(names.len());
113115
for table in &names {
114116
let one = || vec![table.source.clone()];
115117
let asked = describe_all(
@@ -176,6 +178,7 @@ pub(crate) async fn run(
176178
}
177179
// A big integer's tier, the whole column's (P1B-43).
178180
let preview = whole_column_tiers(&asker, &table.source, preview).await?;
181+
big_types.push(big_integer_types(&preview, &declared));
179182
let previewed = infer::preview(
180183
&table.name,
181184
&table.source,
@@ -290,6 +293,14 @@ pub(crate) async fn run(
290293
for warning in warnings {
291294
asker.warn(warning);
292295
}
296+
for (table, types) in description.tables.iter_mut().zip(big_types) {
297+
for column in &mut table.columns {
298+
column.declared_type = types
299+
.iter()
300+
.find(|(name, _)| *name == column.name)
301+
.map(|(_, declared)| declared.clone());
302+
}
303+
}
293304
// Each table's repeated keys, as the reference's count sets them.
294305
if let Some(counted) = counted {
295306
for (table, repeats) in description.tables.iter_mut().zip(counted) {
@@ -320,6 +331,25 @@ fn falls_back(failed: &CoreError) -> bool {
320331
}
321332
}
322333

334+
/// The catalog's declared type of each big-integer column the host layer
335+
/// read from an opaque type and marked ([`crate::big_integer`]), by name:
336+
/// what the described schema keeps (`DescribedColumn::declared_type`), so a
337+
/// `decimal128(38, 0)` seed is joined to such a key in the key's own type
338+
/// with no statement `materialize` adds (register P1B-43). Every other
339+
/// column keeps none, and joins as before part 3.
340+
fn big_integer_types(preview: &ArrowData, declared: &[CatalogColumn]) -> Vec<(String, String)> {
341+
preview
342+
.schema
343+
.fields()
344+
.iter()
345+
.filter(|f| big_integer::is_marked(f))
346+
.filter_map(|f| {
347+
let column = declared.iter().find(|c| &c.name == f.name())?;
348+
Some((column.name.clone(), column.declared_type.clone()))
349+
})
350+
.collect()
351+
}
352+
323353
/// `preview` with each big-integer column the host layer read
324354
/// ([`crate::big_integer`]) in the tier of its values over the whole
325355
/// table, so the column is described in one tier every fetch is held to:

‎rust/crates/sdm-schema/src/assemble.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub fn assemble(
241241
stype_before_key: c.stype_before_key,
242242
nullable: c.nullable,
243243
unique: c.unique,
244-
declared_type: c.declared_type,
244+
declared_type: None,
245245
})
246246
.collect(),
247247
primary_key: table.primary_key.into_iter().collect(),

‎rust/crates/sdm-schema/src/infer.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::collections::BTreeSet;
1919

2020
use arrow_array::RecordBatch;
2121
use arrow_schema::{DataType, Schema};
22-
use sdm_contract::data::{BIG_INTEGER_MARKED, BIG_INTEGER_MARKER};
2322
use sdm_contract::ops::{Dtype, Stype};
2423
use sdm_contract::{ColumnType, CoreError, ErrorCode, ErrorKind, Scalar};
2524

@@ -77,9 +76,6 @@ pub struct InferredColumn {
7776
/// Whether the catalog declares a primary or unique key of this one
7877
/// column.
7978
pub unique: bool,
80-
/// The catalog's declared type, for a big-integer column the host layer
81-
/// read and marked only (`DescribedColumn::declared_type`).
82-
pub declared_type: Option<String>,
8379
}
8480

8581
/// Why inference passed a timestamp over for the time column, as the
@@ -488,9 +484,6 @@ pub fn preview(
488484
received: ColumnType::from_arrow(&declared.name, field.data_type())?,
489485
nullable: !is_primary && !declared.not_null,
490486
unique: declared_unique.contains(&declared.name),
491-
declared_type: (field.metadata().get(BIG_INTEGER_MARKER).map(String::as_str)
492-
== Some(BIG_INTEGER_MARKED))
493-
.then(|| declared.declared_type.clone()),
494487
});
495488
let text_time = dtype == Dtype::String && stype == Stype::Timestamp;
496489
instants.push(if dtype == Dtype::Time {

‎rust/crates/sdm-schema/tests/assemble.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ fn column(name: &str, dtype: Dtype, stype: Stype) -> InferredColumn {
3636
},
3737
nullable: true,
3838
unique: false,
39-
declared_type: None,
4039
}
4140
}
4241

‎rust/crates/sdm-schema/tests/keys.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fn column(name: &str, unique: bool) -> InferredColumn {
2525
received: ColumnType::Int64,
2626
nullable: true,
2727
unique,
28-
declared_type: None,
2928
}
3029
}
3130

0 commit comments

Comments
 (0)