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

[improve](ut) add ut for column_array #45827

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion be/src/olap/rowset/segment_v2/hierarchical_data_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class HierarchicalDataReader : public ColumnIterator {
for (const auto& subcolumn : entry.second) {
const auto& column = subcolumn.column;
const auto& type = subcolumn.type;
if (!remove_nullable(column)->is_column_array()) {
if (!is_column<ColumnArray>(remove_nullable(column).get())) {
return Status::InvalidArgument(
"Meet none array column when flatten nested array, path {}, type {}",
subcolumn.path.get_path(), subcolumn.type->get_name());
Expand Down
2 changes: 1 addition & 1 deletion be/src/pipeline/exec/join_probe_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Status JoinProbeLocalState<SharedStateArg, Derived>::_build_output_block(
/// TODO: maybe need a method to check if a column need to be converted to full
/// column.
if (is_column_const(*origin_column) ||
check_column<vectorized::ColumnArray>(origin_column.get())) {
is_column<vectorized::ColumnArray>(origin_column.get())) {
auto column_ptr = origin_column->convert_to_full_column_if_const();
insert_column_datas(mutable_columns[i], column_ptr, rows);
} else {
Expand Down
4 changes: 2 additions & 2 deletions be/src/vec/columns/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ void IColumn::compare_internal(size_t rhs_row_id, const IColumn& rhs, int nan_di
}

bool is_column_nullable(const IColumn& column) {
return check_column<ColumnNullable>(column);
return is_column<ColumnNullable>(column);
}

bool is_column_const(const IColumn& column) {
return check_column<ColumnConst>(column);
return is_column<ColumnConst>(column);
}

} // namespace doris::vectorized
10 changes: 2 additions & 8 deletions be/src/vec/columns/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,6 @@ class IColumn : public COW<IColumn> {

virtual bool is_column_dictionary() const { return false; }

virtual bool is_column_array() const { return false; }

virtual bool is_column_map() const { return false; }

virtual bool is_column_struct() const { return false; }

/// If the only value column can contain is NULL.
virtual bool only_null() const { return false; }

Expand Down Expand Up @@ -715,12 +709,12 @@ const Type* check_and_get_column(const IColumn* column) {
}

template <typename Type>
bool check_column(const IColumn& column) {
bool is_column(const IColumn& column) {
return check_and_get_column<Type>(&column);
}

template <typename Type>
bool check_column(const IColumn* column) {
bool is_column(const IColumn* column) {
return check_and_get_column<Type>(column);
}

Expand Down
28 changes: 12 additions & 16 deletions be/src/vec/columns/column_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace doris::vectorized {

ColumnArray::ColumnArray(MutableColumnPtr&& nested_column, MutableColumnPtr&& offsets_column)
: data(std::move(nested_column)), offsets(std::move(offsets_column)) {
data = data->convert_to_full_column_if_const();
offsets = offsets->convert_to_full_column_if_const();
const auto* offsets_concrete = typeid_cast<const ColumnOffsets*>(offsets.get());

if (!offsets_concrete) {
Expand All @@ -70,12 +72,12 @@ ColumnArray::ColumnArray(MutableColumnPtr&& nested_column, MutableColumnPtr&& of
}

ColumnArray::ColumnArray(MutableColumnPtr&& nested_column) : data(std::move(nested_column)) {
data = data->convert_to_full_column_if_const();
if (!data->empty()) {
throw doris::Exception(ErrorCode::INTERNAL_ERROR,
"Not empty data passed to ColumnArray, but no offsets passed");
__builtin_unreachable();
}

offsets = ColumnOffsets::create();
}

Expand Down Expand Up @@ -122,10 +124,10 @@ Field ColumnArray::operator[](size_t n) const {
size_t size = size_at(n);

if (size > max_array_size_as_field)
throw doris::Exception(
ErrorCode::INVALID_ARGUMENT,
"Array of size {}, is too large to be manipulated as single field, maximum size {}",
size, max_array_size_as_field);
throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
"Array of size {} in row {}, is too large to be manipulated as "
"single field, maximum size {}",
size, n, max_array_size_as_field);

Array res(size);

Expand All @@ -139,10 +141,10 @@ void ColumnArray::get(size_t n, Field& res) const {
size_t size = size_at(n);

if (size > max_array_size_as_field)
throw doris::Exception(
ErrorCode::INVALID_ARGUMENT,
"Array of size {}, is too large to be manipulated as single field, maximum size {}",
size, max_array_size_as_field);
throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
"Array of size {} in row {}, is too large to be manipulated as "
"single field, maximum size {}",
size, n, max_array_size_as_field);

res = Array(size);
Array& res_arr = doris::vectorized::get<Array&>(res);
Expand Down Expand Up @@ -362,7 +364,7 @@ void ColumnArray::insert_default() {

void ColumnArray::pop_back(size_t n) {
auto& offsets_data = get_offsets();
DCHECK(n <= offsets_data.size());
DCHECK(n <= offsets_data.size()) << " n:" << n << " with offsets size: " << offsets_data.size();
size_t nested_n = offsets_data.back() - offset_at(offsets_data.size() - n);
if (nested_n) get_data().pop_back(nested_n);
offsets_data.resize_assume_reserved(offsets_data.size() - n);
Expand Down Expand Up @@ -390,12 +392,6 @@ size_t ColumnArray::allocated_bytes() const {
return get_data().allocated_bytes() + get_offsets().allocated_bytes();
}

ColumnPtr ColumnArray::convert_to_full_column_if_const() const {
amorynan marked this conversation as resolved.
Show resolved Hide resolved
/// It is possible to have an array with constant data and non-constant offsets.
/// Example is the result of expression: replicate('hello', [1])
return ColumnArray::create(data->convert_to_full_column_if_const(), offsets);
}

bool ColumnArray::has_equal_offsets(const ColumnArray& other) const {
const Offsets64& offsets1 = get_offsets();
const Offsets64& offsets2 = other.get_offsets();
Expand Down
3 changes: 0 additions & 3 deletions be/src/vec/columns/column_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class ColumnArray final : public COWHelper<IColumn, ColumnArray> {
using ColumnOffsets = ColumnVector<Offset64>;

std::string get_name() const override;
bool is_column_array() const override { return true; }
bool is_variable_length() const override { return true; }

bool is_exclusive() const override {
Expand Down Expand Up @@ -165,8 +164,6 @@ class ColumnArray final : public COWHelper<IColumn, ColumnArray> {
ColumnPtr replicate(const IColumn::Offsets& replicate_offsets) const override;
void insert_many_from(const IColumn& src, size_t position, size_t length) override;

ColumnPtr convert_to_full_column_if_const() const override;

/** More efficient methods of manipulation */
IColumn& get_data() { return *data; }
const IColumn& get_data() const { return *data; }
Expand Down
1 change: 0 additions & 1 deletion be/src/vec/columns/column_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class ColumnMap final : public COWHelper<IColumn, ColumnMap> {
void insert_default() override;

void pop_back(size_t n) override;
bool is_column_map() const override { return true; }
StringRef serialize_value_into_arena(size_t n, Arena& arena, char const*& begin) const override;
const char* deserialize_and_insert_from_arena(const char* pos) override;

Expand Down
3 changes: 0 additions & 3 deletions be/src/vec/columns/column_nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,6 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable>, public N
bool is_nullable() const override { return true; }
bool is_concrete_nullable() const override { return true; }
bool is_column_string() const override { return get_nested_column().is_column_string(); }
bool is_column_array() const override { return get_nested_column().is_column_array(); }
bool is_column_map() const override { return get_nested_column().is_column_map(); }
bool is_column_struct() const override { return get_nested_column().is_column_struct(); }

bool is_exclusive() const override {
return IColumn::is_exclusive() && nested_column->is_exclusive() &&
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/columns/column_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ bool ColumnObject::is_finalized() const {
void ColumnObject::Subcolumn::wrapp_array_nullable() {
// Wrap array with nullable, treat empty array as null to elimate conflict at present
auto& result_column = get_finalized_column_ptr();
if (result_column->is_column_array() && !result_column->is_nullable()) {
if (is_column<vectorized::ColumnArray>(result_column.get()) && !result_column->is_nullable()) {
auto new_null_map = ColumnUInt8::create();
new_null_map->reserve(result_column->size());
auto& null_map_data = new_null_map->get_data();
Expand Down
1 change: 0 additions & 1 deletion be/src/vec/columns/column_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class ColumnStruct final : public COWHelper<IColumn, ColumnStruct> {
}

std::string get_name() const override;
bool is_column_struct() const override { return true; }
MutableColumnPtr clone_empty() const override;
MutableColumnPtr clone_resized(size_t size) const override;
size_t size() const override { return columns.at(0)->size(); }
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/exprs/table_function/vexplode_json_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void VExplodeJsonObjectTableFunction::get_same_many_values(MutableColumnPtr& col
assert_cast<ColumnUInt8*>(
assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
->insert_many_defaults(length);
} else if (column->is_column_struct()) {
} else if (is_column<ColumnStruct>(column.get())) {
ret = assert_cast<ColumnStruct*>(column.get());
} else {
throw Exception(ErrorCode::INTERNAL_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/exprs/table_function/vexplode_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void VExplodeMapTableFunction::get_same_many_values(MutableColumnPtr& column, in
assert_cast<ColumnUInt8*>(
assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
->insert_many_defaults(length);
} else if (column->is_column_struct()) {
} else if (is_column<ColumnStruct>(column.get())) {
ret = assert_cast<ColumnStruct*>(column.get());
} else {
throw Exception(ErrorCode::INTERNAL_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/exprs/table_function/vposexplode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void VPosExplodeTableFunction::get_same_many_values(MutableColumnPtr& column, in
assert_cast<ColumnUInt8*>(
assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
->insert_many_defaults(length);
} else if (column->is_column_struct()) {
} else if (is_column<ColumnStruct>(column.get())) {
ret = assert_cast<ColumnStruct*>(column.get());
} else {
throw Exception(ErrorCode::INTERNAL_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/array/function_array_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class FunctionArrayElement : public IFunction {
args = {col_left, block.get_by_position(arguments[1])};
}
ColumnPtr res_column = nullptr;
if (args[0].column->is_column_map() ||
if (is_column<ColumnMap>(args[0].column.get()) ||
check_column_const<ColumnMap>(args[0].column.get())) {
res_column = _execute_map(args, input_rows_count, src_null_map, dst_null_map);
} else {
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/array/function_array_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class FunctionArrayIndex : public IFunction {
const IColumn& right_column,
const UInt8* right_nested_null_map,
const UInt8* outer_null_map) const {
if (check_column<NestedColumnType>(right_column)) {
if (is_column<NestedColumnType>(right_column)) {
return _execute_number<NestedColumnType, NestedColumnType>(
offsets, nested_null_map, nested_column, right_column, right_nested_null_map,
outer_null_map);
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/array/function_array_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct ArrayMapImpl {
static bool _execute_internal(ColumnArrayMutableData& dst, ColumnArrayExecutionDatas datas,
std::vector<bool>& col_const, size_t start_row, size_t end_row) {
for (auto data : datas) {
if (!check_column<ColumnType>(*data.nested_col)) {
if (!is_column<ColumnType>(*data.nested_col)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/array/function_array_remove.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class FunctionArrayRemove : public IFunction {
ColumnPtr _execute_number_expanded(const ColumnArray::Offsets64& offsets,
const IColumn& nested_column, const IColumn& right_column,
const UInt8* nested_null_map) const {
if (check_column<NestedColumnType>(right_column)) {
if (is_column<NestedColumnType>(right_column)) {
return _execute_number<NestedColumnType, NestedColumnType>(
offsets, nested_column, right_column, nested_null_map);
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/array/function_array_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct ArraySetImpl {
const ColumnArrayExecutionData& left_data,
const ColumnArrayExecutionData& right_data) {
using Impl = OpenSetImpl<operation, ColumnType>;
if (!check_column<ColumnType>(*left_data.nested_col)) {
if (!is_column<ColumnType>(*left_data.nested_col)) {
return false;
}
constexpr auto execute_left_column_first = Impl::Action::execute_left_column_first;
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/function_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const ColumnConst* check_and_get_column_const_string_or_fixedstring(const IColum

const ColumnConst* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column);

if (check_column<ColumnString>(&res->get_data_column())) return res;
if (is_column<ColumnString>(&res->get_data_column())) return res;

return {};
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/function_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ColumnConst* check_and_get_column_const(const IColumn* column) {

const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column);

if (!check_column<Type>(&res->get_data_column())) {
if (!is_column<Type>(&res->get_data_column())) {
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/function_reverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FunctionReverseCommon : public IFunction {
RETURN_IF_ERROR(ReverseImpl::vector(col_string->get_chars(), col_string->get_offsets(),
col_res->get_chars(), col_res->get_offsets()));
block.replace_by_position(result, std::move(col_res));
} else if (check_column<ColumnArray>(src_column.get())) {
} else if (is_column<ColumnArray>(src_column.get())) {
return ArrayReverseImpl::_execute(block, arguments, result, input_rows_count);
} else {
return Status::RuntimeError("Illegal column {} used for argument of function {}",
Expand Down
4 changes: 2 additions & 2 deletions be/src/vec/functions/function_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ class FunctionStringConcatWs : public IFunction {
null_list[i] = &const_null_map->get_data();
}

if (check_column<ColumnArray>(argument_columns[i].get())) {
if (is_column<ColumnArray>(argument_columns[i].get())) {
continue;
}

Expand All @@ -1382,7 +1382,7 @@ class FunctionStringConcatWs : public IFunction {
fmt::memory_buffer buffer;
std::vector<std::string_view> views;

if (check_column<ColumnArray>(argument_columns[1].get())) {
if (is_column<ColumnArray>(argument_columns[1].get())) {
// Determine if the nested type of the array is String
const auto& array_column = reinterpret_cast<const ColumnArray&>(*argument_columns[1]);
if (!array_column.get_data().is_column_string()) {
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Status FunctionMatchBase::execute_impl(FunctionContext* context, Block& block,
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
const auto* values = check_and_get_column<ColumnString>(source_col.get());
const ColumnArray* array_col = nullptr;
if (source_col->is_column_array()) {
if (is_column<vectorized::ColumnArray>(source_col.get())) {
array_col = check_and_get_column<ColumnArray>(source_col.get());
if (array_col && !array_col->get_data().is_column_string()) {
return Status::NotSupported(fmt::format(
Expand Down
Loading
Loading