Skip to content

Commit 72493e7

Browse files
authored
chore: simplification for new collector logic (#1265)
1 parent 1ee970a commit 72493e7

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

src/builder/analyzer.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -899,25 +899,16 @@ impl AnalyzerContext {
899899
};
900900

901901
// Pre-compute field index mappings for efficient evaluation
902-
let field_name_to_index: HashMap<&FieldName, usize> = collector_schema
903-
.fields
902+
let field_name_to_index: HashMap<&FieldName, usize> = input_field_names
904903
.iter()
905904
.enumerate()
906-
.map(|(i, f)| (&f.name, i))
905+
.map(|(i, n)| (n, i))
907906
.collect();
908-
let mut field_index_mapping: HashMap<usize, usize> = HashMap::new();
909-
for (input_idx, field_name) in input_field_names.iter().enumerate() {
910-
let collector_idx = field_name_to_index
911-
.get(field_name)
912-
.copied()
913-
.ok_or_else(|| {
914-
anyhow!(
915-
"field `{}` not found in merged collector schema",
916-
field_name
917-
)
918-
})?;
919-
field_index_mapping.insert(collector_idx, input_idx);
920-
}
907+
let field_index_mapping = collector_schema
908+
.fields
909+
.iter()
910+
.map(|field| field_name_to_index.get(&field.name).copied())
911+
.collect::<Vec<Option<usize>>>();
921912

922913
let collect_op = AnalyzedReactiveOp::Collect(AnalyzedCollectOp {
923914
name: reactive_op_name,

src/builder/plan.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::base::schema::FieldSchema;
22
use crate::base::spec::FieldName;
33
use crate::prelude::*;
44

5-
use std::collections::HashMap;
6-
75
use crate::ops::interface::*;
86
use crate::utils::fingerprint::{Fingerprint, Fingerprinter};
97

@@ -97,7 +95,7 @@ pub struct AnalyzedCollectOp {
9795
pub collector_schema: Arc<schema::CollectorSchema>,
9896
pub collector_ref: AnalyzedCollectorReference,
9997
/// Pre-computed mapping from collector field index to input field index.
100-
pub field_index_mapping: HashMap<usize, usize>,
98+
pub field_index_mapping: Vec<Option<usize>>,
10199
/// Fingerprinter of the collector's schema. Used to decide when to reuse auto-generated UUIDs.
102100
pub fingerprinter: Fingerprinter,
103101
}

src/execution/evaluator.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,15 @@ async fn evaluate_op_scope(
522522
.collect::<Result<Vec<_>>>()?;
523523

524524
// Create field_values vector for all fields in the merged schema
525-
let mut field_values: Vec<value::Value> =
526-
vec![value::Value::Null; op.collector_schema.fields.len()];
527-
528-
// Use pre-computed field index mappings for O(1) field placement
529-
for (&collector_idx, &input_idx) in op.field_index_mapping.iter() {
530-
field_values[collector_idx] = input_values[input_idx].clone();
531-
}
525+
let mut field_values = op
526+
.field_index_mapping
527+
.iter()
528+
.map(|idx| {
529+
idx.map_or(value::Value::Null, |input_idx| {
530+
input_values[input_idx].clone()
531+
})
532+
})
533+
.collect::<Vec<_>>();
532534

533535
// Handle auto_uuid_field (assumed to be at position 0 for efficiency)
534536
if op.has_auto_uuid_field {

0 commit comments

Comments
 (0)