Skip to content
Permalink
Browse files
[feature-wip](array-type) array_contains support more nested data typ…
…es (#9170)

Co-authored-by: cambyzju <zhuxiaoli01@baidu.com>
  • Loading branch information
cambyzju and cambyzju committed May 13, 2022
1 parent 34e64fb commit 650e3a6ba00595bc99fd4cb5b18ab7ed67610dff
Showing 15 changed files with 467 additions and 186 deletions.
@@ -464,8 +464,8 @@ class IColumn : public COW<IColumn> {
// only used in ColumnNullable replace_column_data
virtual void replace_column_data_default(size_t self_row = 0) = 0;

virtual bool is_date_type() { return is_date; }
virtual bool is_datetime_type() { return is_date_time; }
virtual bool is_date_type() const { return is_date; }
virtual bool is_datetime_type() const { return is_date_time; }

virtual void set_date_type() { is_date = true; }
virtual void set_datetime_type() { is_date_time = true; }
@@ -71,6 +71,7 @@ class ColumnDecimal final : public COWHelper<ColumnVectorHelper, ColumnDecimal<T
friend class COWHelper<ColumnVectorHelper, Self>;

public:
using value_type = T;
using Container = DecimalPaddedPODArray<T>;

private:
@@ -163,8 +163,8 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
return false;
}

bool is_date_type() override { return get_nested_column().is_date_type(); }
bool is_datetime_type() override { return get_nested_column().is_datetime_type(); }
bool is_date_type() const override { return get_nested_column().is_date_type(); }
bool is_datetime_type() const override { return get_nested_column().is_datetime_type(); }
void set_date_type() override { get_nested_column().set_date_type(); }
void set_datetime_type() override { get_nested_column().set_datetime_type(); }

@@ -65,4 +65,10 @@ void DataTypeDate::cast_to_date(Int64& x) {
x = binary_cast<VecDateTimeValue, Int64>(value);
}

MutableColumnPtr DataTypeDate::create_column() const {
auto col = DataTypeNumberBase<Int64>::create_column();
col->set_date_type();
return col;
}

} // namespace doris::vectorized
@@ -38,6 +38,8 @@ class DataTypeDate final : public DataTypeNumberBase<Int64> {
void to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const override;

static void cast_to_date(Int64& x);

MutableColumnPtr create_column() const override;
};

} // namespace doris::vectorized
@@ -88,4 +88,10 @@ void DataTypeDateTime::cast_to_date_time(Int64& x) {
x = binary_cast<doris::vectorized::VecDateTimeValue, Int64>(value);
}

MutableColumnPtr DataTypeDateTime::create_column() const {
auto col = DataTypeNumberBase<Int64>::create_column();
col->set_datetime_type();
return col;
}

} // namespace doris::vectorized
@@ -65,6 +65,8 @@ class DataTypeDateTime final : public DataTypeNumberBase<Int64> {
void to_string(const IColumn& column, size_t row_num, BufferWritable& ostr) const override;

static void cast_to_date_time(Int64& x);

MutableColumnPtr create_column() const override;
};

template <typename DataType>
@@ -189,7 +189,8 @@ Status VUnionNode::get_next_const(RuntimeState* state, Block* block) {
int const_expr_lists_size = _const_expr_lists[_const_expr_list_idx].size();
std::vector<int> result_list(const_expr_lists_size);
for (size_t i = 0; i < const_expr_lists_size; ++i) {
_const_expr_lists[_const_expr_list_idx][i]->execute(&tmp_block, &result_list[i]);
RETURN_IF_ERROR(_const_expr_lists[_const_expr_list_idx][i]->execute(&tmp_block,
&result_list[i]));
}
tmp_block.erase_not_in(result_list);
mblock.merge(tmp_block);
@@ -90,9 +90,11 @@ class FunctionArrayElement : public IFunction {
ColumnPtr _execute_number(const ColumnArray::Offsets& offsets, const IColumn& nested_column,
const UInt8* arr_null_map, const IColumn& indices,
const UInt8* nested_null_map, UInt8* dst_null_map) {
const auto& nested_data = check_and_get_column<ColumnType>(nested_column)->get_data();
auto dst_column = ColumnType::create(offsets.size());
auto& dst_data = dst_column->get_data();
const auto& nested_data = reinterpret_cast<const ColumnType&>(nested_column).get_data();

auto dst_column = nested_column.clone_empty();
auto& dst_data = reinterpret_cast<ColumnType&>(*dst_column).get_data();
dst_data.resize(offsets.size());

// process
for (size_t row = 0; row < offsets.size(); ++row) {
@@ -129,8 +131,10 @@ class FunctionArrayElement : public IFunction {
ColumnPtr _execute_string(const ColumnArray::Offsets& offsets, const IColumn& nested_column,
const UInt8* arr_null_map, const IColumn& indices,
const UInt8* nested_null_map, UInt8* dst_null_map) {
const auto& src_str_offs = check_and_get_column<ColumnString>(nested_column)->get_offsets();
const auto& src_str_chars = check_and_get_column<ColumnString>(nested_column)->get_chars();
const auto& src_str_offs =
reinterpret_cast<const ColumnString&>(nested_column).get_offsets();
const auto& src_str_chars =
reinterpret_cast<const ColumnString&>(nested_column).get_chars();

// prepare return data
auto dst_column = ColumnString::create();
@@ -181,23 +185,33 @@ class FunctionArrayElement : public IFunction {
const DataTypePtr& result_type, size_t input_rows_count,
const UInt8* src_null_map, UInt8* dst_null_map) {
// check array nested column type and get data
auto array_column = check_and_get_column<ColumnArray>(*arguments[0].column);
DCHECK(array_column != nullptr);
const auto& offsets = array_column->get_offsets();
auto left_column = arguments[0].column->convert_to_full_column_if_const();
const auto& array_column = reinterpret_cast<const ColumnArray&>(*left_column);
const auto& offsets = array_column.get_offsets();
DCHECK(offsets.size() == input_rows_count);
const UInt8* nested_null_map = nullptr;
ColumnPtr nested_column = nullptr;
if (is_column_nullable(array_column->get_data())) {
if (is_column_nullable(array_column.get_data())) {
const auto& nested_null_column =
check_and_get_column<ColumnNullable>(array_column->get_data());
nested_null_map = nested_null_column->get_null_map_column().get_data().data();
nested_column = nested_null_column->get_nested_column_ptr();
reinterpret_cast<const ColumnNullable&>(array_column.get_data());
nested_null_map = nested_null_column.get_null_map_column().get_data().data();
nested_column = nested_null_column.get_nested_column_ptr();
} else {
nested_column = array_column->get_data_ptr();
nested_column = array_column.get_data_ptr();
}

ColumnPtr res = nullptr;
if (check_column<ColumnInt8>(*nested_column)) {
if (nested_column->is_date_type()) {
res = _execute_number<ColumnDate>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map, dst_null_map);
} else if (nested_column->is_datetime_type()) {
res = _execute_number<ColumnDateTime>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map,
dst_null_map);
} else if (check_column<ColumnUInt8>(*nested_column)) {
res = _execute_number<ColumnUInt8>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map, dst_null_map);
} else if (check_column<ColumnInt8>(*nested_column)) {
res = _execute_number<ColumnInt8>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map, dst_null_map);
} else if (check_column<ColumnInt16>(*nested_column)) {
@@ -209,6 +223,10 @@ class FunctionArrayElement : public IFunction {
} else if (check_column<ColumnInt64>(*nested_column)) {
res = _execute_number<ColumnInt64>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map, dst_null_map);
} else if (check_column<ColumnInt128>(*nested_column)) {
res = _execute_number<ColumnInt128>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map,
dst_null_map);
} else if (check_column<ColumnFloat32>(*nested_column)) {
res = _execute_number<ColumnFloat32>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map,
@@ -217,6 +235,10 @@ class FunctionArrayElement : public IFunction {
res = _execute_number<ColumnFloat64>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map,
dst_null_map);
} else if (check_column<ColumnDecimal128>(*nested_column)) {
res = _execute_number<ColumnDecimal128>(offsets, *nested_column, src_null_map,
*arguments[1].column, nested_null_map,
dst_null_map);
} else if (check_column<ColumnString>(*nested_column)) {
res = _execute_string(offsets, *nested_column, src_null_map, *arguments[1].column,
nested_null_map, dst_null_map);

0 comments on commit 650e3a6

Please sign in to comment.