Skip to content
Merged
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
21 changes: 16 additions & 5 deletions src/execution/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ impl<'a> ScopeKey<'a> {
}
}

impl std::fmt::Display for ScopeKey<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ScopeKey::None => write!(f, "()"),
ScopeKey::MapKey(k) => write!(f, "{{{k}}}"),
ScopeKey::ListIndex(i) => write!(f, "[{i}]"),
}
}
}

struct ScopeEntry<'a> {
key: ScopeKey<'a>,
value: &'a ScopeValueBuilder,
Expand Down Expand Up @@ -254,19 +264,20 @@ impl<'a> ScopeEntry<'a> {
&self,
output_field: &AnalyzedOpOutput,
val: value::Value<ScopeValueBuilder>,
) {
) -> Result<()> {
let field_index = output_field.field_idx as usize;
let index_base = self.key.value_field_index_base() as usize;
self.value.fields[field_index - index_base]
.set(val)
.expect("Field is already set, violating single-definition rule");
self.value.fields[field_index - index_base].set(val).map_err(|_| {
anyhow!("Field {field_index} for scope is already set, violating single-definition rule.")
})?;
Ok(())
}

fn define_field(&self, output_field: &AnalyzedOpOutput, val: &value::Value) -> Result<()> {
let field_index = output_field.field_idx as usize;
let field_schema = &self.schema.fields[field_index];
let val = augmented_value(val, &field_schema.value_type.typ)?;
self.define_field_w_builder(output_field, val);
self.define_field_w_builder(output_field, val)?;
Ok(())
}
}
Expand Down
Loading