Skip to content

Commit d9a2145

Browse files
authored
fix(query): fix cast nested types cause panic (#17622)
* fix(query): fix cast nested types cause panic * fix * fix typo * fix * fix * fix
1 parent ff841d1 commit d9a2145

File tree

20 files changed

+284
-229
lines changed

20 files changed

+284
-229
lines changed

src/common/native/src/nested.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,18 @@ fn to_nested_recursive(
171171
Column::Array(inner) => {
172172
parents.push(Nested::LargeList(ListNested {
173173
is_nullable: nullable,
174-
offsets: inner.offsets.clone(),
174+
offsets: inner.underlying_offsets(),
175175
validity,
176176
}));
177-
to_nested_recursive(&inner.values, nested, parents)?;
177+
to_nested_recursive(&inner.underlying_column(), nested, parents)?;
178178
}
179179
Column::Map(inner) => {
180180
parents.push(Nested::LargeList(ListNested {
181181
is_nullable: nullable,
182-
offsets: inner.offsets.clone(),
182+
offsets: inner.underlying_offsets(),
183183
validity,
184184
}));
185-
to_nested_recursive(&inner.values, nested, parents)?;
185+
to_nested_recursive(&inner.underlying_column(), nested, parents)?;
186186
}
187187
_ => {
188188
parents.push(Nested::Primitive(column.len(), nullable, validity));
@@ -206,10 +206,10 @@ fn to_leaves_recursive(column: &Column, leaves: &mut Vec<Column>) {
206206
cs.iter().for_each(|a| to_leaves_recursive(a, leaves));
207207
}
208208
Column::Array(col) => {
209-
to_leaves_recursive(&col.values, leaves);
209+
to_leaves_recursive(&col.underlying_column(), leaves);
210210
}
211211
Column::Map(col) => {
212-
to_leaves_recursive(&col.values, leaves);
212+
to_leaves_recursive(&col.underlying_column(), leaves);
213213
}
214214
// Handle nullable columns by recursing into their inner value
215215
Column::Nullable(inner) => to_leaves_recursive(&inner.column, leaves),
@@ -243,7 +243,7 @@ impl InitNested {
243243
pub fn create_list(data_type: TableDataType, nested: &mut NestedState, values: Column) -> Column {
244244
let n = nested.pop().unwrap();
245245
let (offsets, validity) = n.inner();
246-
let col = Column::Array(Box::new(ArrayColumn::<AnyType> { values, offsets }));
246+
let col = Column::Array(Box::new(ArrayColumn::<AnyType>::new(values, offsets)));
247247

248248
if data_type.is_nullable() {
249249
col.wrap_nullable(validity.clone())
@@ -256,7 +256,7 @@ pub fn create_list(data_type: TableDataType, nested: &mut NestedState, values: C
256256
pub fn create_map(data_type: TableDataType, nested: &mut NestedState, values: Column) -> Column {
257257
let n = nested.pop().unwrap();
258258
let (offsets, validity) = n.inner();
259-
let col = Column::Map(Box::new(ArrayColumn::<AnyType> { values, offsets }));
259+
let col = Column::Map(Box::new(ArrayColumn::<AnyType>::new(values, offsets)));
260260
if data_type.is_nullable() {
261261
col.wrap_nullable(validity.clone())
262262
} else {

src/query/expression/src/converts/arrow/from.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl Column {
315315
let values = Column::from_arrow_rs(array.values().clone(), inner.as_ref())?;
316316
let offsets: Buffer<u64> = array.offsets().inner().inner().clone().into();
317317

318-
let inner_col = ArrayColumn { values, offsets };
318+
let inner_col = ArrayColumn::new(values, offsets);
319319
Column::Array(Box::new(inner_col))
320320
}
321321
DataType::Map(inner) => {
@@ -333,7 +333,7 @@ impl Column {
333333
let offsets: Buffer<i32> = array.offsets().inner().inner().clone().into();
334334
let offsets = offsets.into_iter().map(|x| x as u64).collect();
335335

336-
let inner_col = ArrayColumn { values, offsets };
336+
let inner_col = ArrayColumn::new(values, offsets);
337337
Column::Map(Box::new(inner_col))
338338
}
339339
DataType::Tuple(ts) => {

src/query/expression/src/converts/arrow/to.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ impl From<&Column> for ArrayData {
303303
Column::Date(col) => buffer_to_array_data((col.clone(), arrow_type)),
304304
Column::Interval(col) => buffer_to_array_data((col.clone(), arrow_type)),
305305
Column::Array(col) => {
306-
let child_data = ArrayData::from(&col.values);
306+
let child_data = ArrayData::from(&col.underlying_column());
307307
let builder = ArrayDataBuilder::new(arrow_type)
308308
.len(value.len())
309-
.buffers(vec![col.offsets.clone().into()])
309+
.buffers(vec![col.underlying_offsets().into()])
310310
.child_data(vec![child_data]);
311311

312312
unsafe { builder.build_unchecked() }
@@ -318,8 +318,12 @@ impl From<&Column> for ArrayData {
318318
unsafe { builder.nulls(Some(nulls)).build_unchecked() }
319319
}
320320
Column::Map(col) => {
321-
let child_data = ArrayData::from(&col.values);
322-
let offsets: Vec<i32> = col.offsets.iter().map(|x| *x as i32).collect();
321+
let child_data = ArrayData::from(&col.underlying_column());
322+
let offsets: Vec<i32> = col
323+
.underlying_offsets()
324+
.into_iter()
325+
.map(|x| x as i32)
326+
.collect();
323327
let builder = ArrayDataBuilder::new(arrow_type)
324328
.len(value.len())
325329
.buffers(vec![offsets.into()])

src/query/expression/src/converts/meta/bincode.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ impl From<LegacyColumn> for Column {
144144
LegacyColumn::Timestamp(buf) => Column::Timestamp(buf),
145145
LegacyColumn::Date(buf) => Column::Date(buf),
146146
LegacyColumn::Interval(buf) => Column::Interval(buf),
147-
LegacyColumn::Array(arr_col) => Column::Array(Box::new(ArrayColumn::<AnyType> {
148-
values: arr_col.values.into(),
149-
offsets: arr_col.offsets,
150-
})),
151-
LegacyColumn::Map(map_col) => Column::Map(Box::new(ArrayColumn::<AnyType> {
152-
values: map_col.values.into(),
153-
offsets: map_col.offsets,
154-
})),
147+
LegacyColumn::Array(arr_col) => Column::Array(Box::new(ArrayColumn::<AnyType>::new(
148+
arr_col.values.into(),
149+
arr_col.offsets,
150+
))),
151+
LegacyColumn::Map(map_col) => Column::Map(Box::new(ArrayColumn::<AnyType>::new(
152+
map_col.values.into(),
153+
map_col.offsets,
154+
))),
155155
LegacyColumn::Bitmap(str_col) => Column::Bitmap(BinaryColumn::from(str_col)),
156156
LegacyColumn::Nullable(nullable_col) => {
157157
Column::Nullable(Box::new(NullableColumn::<AnyType> {
@@ -207,12 +207,12 @@ impl From<Column> for LegacyColumn {
207207
Column::Date(buf) => LegacyColumn::Date(buf),
208208
Column::Interval(buf) => LegacyColumn::Interval(buf),
209209
Column::Array(arr_col) => LegacyColumn::Array(Box::new(LegacyArrayColumn {
210-
values: arr_col.values.into(),
211-
offsets: arr_col.offsets,
210+
values: arr_col.underlying_column().into(),
211+
offsets: arr_col.underlying_offsets(),
212212
})),
213213
Column::Map(map_col) => LegacyColumn::Map(Box::new(LegacyArrayColumn {
214-
values: map_col.values.into(),
215-
offsets: map_col.offsets,
214+
values: map_col.underlying_column().into(),
215+
offsets: map_col.underlying_offsets(),
216216
})),
217217
Column::Bitmap(str_col) => LegacyColumn::Bitmap(LegacyBinaryColumn::from(str_col)),
218218
Column::Nullable(nullable_col) => {

0 commit comments

Comments
 (0)