MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / infer_schema

Function infer_schema

nodedb/src/engine/timeseries/ilp_schema.rs:21–60  ·  view source on GitHub ↗

Infers a columnar schema from a batch of ILP lines. Scans all lines to discover tag keys and field keys, then builds a schema: timestamp + tag columns (Symbol) + field columns (typed).

(lines: &[IlpLine<'_>])

Source from the content-addressed store, hash-verified

19/// Scans all lines to discover tag keys and field keys, then builds
20/// a schema: timestamp + tag columns (Symbol) + field columns (typed).
21pub fn infer_schema(lines: &[IlpLine<'_>]) -> ColumnarSchema {
22 let mut tag_keys: Vec<String> = Vec::new();
23 let mut field_keys: Vec<(String, ColumnType)> = Vec::new();
24 let mut seen_tags: std::collections::HashSet<String> = std::collections::HashSet::new();
25 let mut seen_fields: std::collections::HashSet<String> = std::collections::HashSet::new();
26
27 for line in lines {
28 for &(key, _) in &line.tags {
29 if seen_tags.insert(key.to_string()) {
30 tag_keys.push(key.to_string());
31 }
32 }
33 for &(key, ref val) in &line.fields {
34 if seen_fields.insert(key.to_string()) {
35 let col_type = match val {
36 FieldValue::Float(_) => ColumnType::Float64,
37 FieldValue::Int(_) | FieldValue::UInt(_) => ColumnType::Int64,
38 FieldValue::Str(_) => ColumnType::Symbol,
39 FieldValue::Bool(_) => ColumnType::Float64,
40 };
41 field_keys.push((key.to_string(), col_type));
42 }
43 }
44 }
45
46 let mut columns = Vec::with_capacity(1 + tag_keys.len() + field_keys.len());
47 columns.push(("timestamp".to_string(), ColumnType::Timestamp));
48 for tag in &tag_keys {
49 columns.push((tag.clone(), ColumnType::Symbol));
50 }
51 for (field, ty) in &field_keys {
52 columns.push((field.clone(), *ty));
53 }
54
55 ColumnarSchema {
56 timestamp_idx: 0,
57 codecs: vec![nodedb_codec::ColumnCodec::Auto; columns.len()],
58 columns,
59 }
60}
61
62/// Inject the three reserved bitemporal Int64 columns (`_ts_system`,
63/// `_ts_valid_from`, `_ts_valid_until`) at the end of the schema when

Callers 8

execute_ilp_ingestMethod · 0.85
infer_schema_from_ilpFunction · 0.85
ingest_ilp_batchFunction · 0.85
mixed_field_typesFunction · 0.85

Calls 5

to_stringMethod · 0.80
insertMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45

Tested by 7

infer_schema_from_ilpFunction · 0.68
ingest_ilp_batchFunction · 0.68
mixed_field_typesFunction · 0.68