Move ColumnArray-specific code out of the ActionsDAG.

This commit is contained in:
Vitaly Baranov 2024-02-08 15:24:01 +01:00
parent 12a71375b8
commit 1b9620001b
3 changed files with 31 additions and 5 deletions

View File

@ -554,6 +554,21 @@ void ColumnArray::insertRangeFrom(const IColumn & src, size_t start, size_t leng
}
MutableColumnPtr ColumnArray::getDataInRange(size_t start, size_t length) const
{
if (start + length > getOffsets().size())
throw Exception(ErrorCodes::PARAMETER_OUT_OF_BOUND, "Parameter out of bound in ColumnArray::getDataPtrForRange method. "
"[start({}) + length({}) > offsets.size({})]", start, length, getOffsets().size());
size_t start_offset = offsetAt(start);
size_t end_offset = offsetAt(start + length);
auto res = getData().cloneEmpty();
res->insertRangeFrom(getData(), start_offset, end_offset - start_offset);
return res;
}
ColumnPtr ColumnArray::filter(const Filter & filt, ssize_t result_size_hint) const
{
if (typeid_cast<const ColumnUInt8 *>(data.get()))

View File

@ -143,6 +143,10 @@ public:
const ColumnPtr & getOffsetsPtr() const { return offsets; }
ColumnPtr & getOffsetsPtr() { return offsets; }
/// Returns a copy of the data column's part corresponding to a specified range of rows.
/// For example, `getDataInRange(0, size())` is the same as `getDataPtr()->clone()`.
MutableColumnPtr getDataInRange(size_t start, size_t length) const;
MutableColumns scatter(ColumnIndex num_columns, const Selector & selector) const override
{
return scatterImpl<ColumnArray>(num_columns, selector);

View File

@ -628,17 +628,24 @@ static ColumnWithTypeAndName executeActionForPartialResult(const ActionsDAG::Nod
if (!array)
throw Exception(ErrorCodes::TYPE_MISMATCH,
"ARRAY JOIN of not array nor map: {}", node->result_name);
res_column.column = array->getDataPtr();
ColumnPtr data;
if (input_rows_count < array->size())
res_column.column = res_column.column->cloneResized(array->getOffsets()[input_rows_count - 1]);
data = array->getDataInRange(0, input_rows_count);
else
data = array->getDataPtr();
res_column.column = data;
break;
}
case ActionsDAG::ActionType::COLUMN:
{
res_column.column = node->column;
if (input_rows_count < res_column.column->size())
res_column.column = res_column.column->cloneResized(input_rows_count);
auto column = node->column;
if (input_rows_count < column->size())
column = column->cloneResized(input_rows_count);
res_column.column = column;
break;
}