Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refine cast variant to map #16691

Merged
merged 3 commits into from
Oct 27, 2024
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
33 changes: 14 additions & 19 deletions src/query/expression/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::types::BooleanType;
use crate::types::DataType;
use crate::types::NullableType;
use crate::types::NumberScalar;
use crate::types::StringType;
use crate::types::VariantType;
use crate::values::Column;
use crate::values::ColumnBuilder;
Expand Down Expand Up @@ -640,7 +641,7 @@ impl<'a> Evaluator<'a> {
]))))
}
Value::Column(Column::Variant(col)) => {
let mut key_builder = StringColumnBuilder::with_capacity(0, 0);
let mut key_builder = StringType::create_builder(col.len(), &[]);
let mut value_builder =
ArrayType::<VariantType>::create_builder(col.len(), &[]);

Expand All @@ -662,38 +663,32 @@ impl<'a> Evaluator<'a> {
v.write_to_vec(&mut value_builder.builder.data);
value_builder.builder.commit_row();
}

value_builder.commit_row();
}
let key_column = Column::String(key_builder.build());

let value_column = value_builder.build();
let validity = validity.map(|validity| {
let mut inner_validity = MutableBitmap::with_capacity(col.len());
for (index, offsets) in value_column.offsets.windows(2).enumerate() {
inner_validity.extend_constant(
(offsets[1] - offsets[0]) as usize,
validity.get_bit(index),
);
}
inner_validity.into()
});
let key_col = Column::String(key_builder.build());
let value_col = Column::Array(Box::new(value_builder.build().upcast()));

let new_value_column = self
let value_col = self
.run_cast(
span,
&DataType::Variant,
&DataType::Array(Box::new(DataType::Variant)),
&fields_dest_ty[1],
Value::Column(Column::Variant(value_column.values)),
Value::Column(value_col),
validity,
options,
)?
.into_column()
.unwrap()
.into_array()
.unwrap();

let kv_column = Column::Tuple(vec![key_column, new_value_column]);
let kv_col = Column::Tuple(vec![key_col, value_col.values]);

Ok(Value::Column(Column::Map(Box::new(ArrayColumn {
values: kv_column,
offsets: col.offsets,
values: kv_col,
offsets: value_col.offsets,
}))))
}
other => unreachable!("source: {}", other),
Expand Down
Loading