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 2 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
39 changes: 12 additions & 27 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,22 @@ 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 offsets = value_builder.offsets.into();
let key_col = key_builder.build();
let value_col = value_builder.builder.build();

let new_value_column = self
.run_cast(
span,
&DataType::Variant,
&fields_dest_ty[1],
Value::Column(Column::Variant(value_column.values)),
validity,
options,
)?
.into_column()
.unwrap();
let kv_col = Column::Tuple(vec![
Column::String(key_col),
Column::Variant(value_col),
andylokandy marked this conversation as resolved.
Show resolved Hide resolved
]);

let kv_column = Column::Tuple(vec![key_column, new_value_column]);
Ok(Value::Column(Column::Map(Box::new(ArrayColumn {
values: kv_column,
offsets: col.offsets,
values: kv_col,
offsets,
}))))
}
other => unreachable!("source: {}", other),
Expand Down
Loading