Skip to content

Commit

Permalink
fix some comment and add note for column
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan committed Nov 26, 2024
1 parent 3c963bb commit 5ea740b
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 124 deletions.
29 changes: 5 additions & 24 deletions be/src/vec/columns/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class IColumn : public COW<IColumn> {
// insert the data of target columns into self column according to positions
// positions[i] means index of srcs whitch need to insert_from
// the virtual function overhead of multiple calls to insert_from can be reduced to once
void insert_from_multi_column(const std::vector<const IColumn*>& srcs,
std::vector<size_t> positions);
virtual void insert_from_multi_column(const std::vector<const IColumn*>& srcs,
const std::vector<size_t>& positions) = 0;

/// Appends a batch elements from other column with the same type
/// Also here should make sure indices_end is bigger than indices_begin
Expand Down Expand Up @@ -480,14 +480,6 @@ class IColumn : public COW<IColumn> {
*/
virtual Ptr replicate(const Offsets& offsets) const = 0;

/// Appends one field multiple times. Can be optimized in inherited classes.
// this function has not used ??
// virtual void insert_many(const Field& field, size_t length) {
// for (size_t i = 0; i < length; ++i) {
// insert(field);
// }
// }

/** Split column to smaller columns. Each value goes to column index, selected by corresponding element of 'selector'.
* Selector must contain values from 0 to num_columns - 1.
* For default implementation, see column_impl.h
Expand Down Expand Up @@ -603,23 +595,12 @@ class IColumn : public COW<IColumn> {
* To avoid confusion between these cases, we don't have isContiguous method.
*/

/// Values in column are represented as continuous memory segment of fixed size. Implies values_have_fixed_size.
virtual bool is_fixed_and_contiguous() const { return false; }

/// If is_fixed_and_contiguous, returns the underlying data array, otherwise throws an exception.
virtual StringRef get_raw_data() const {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
"Column {} is not a contiguous block of memory", get_name());
return StringRef {};
}

/// If values_have_fixed_size, returns size of value, otherwise throw an exception.
virtual size_t size_of_value_if_fixed() const {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
"Values of column {} are not fixed size.", get_name());
return 0;
}

/// Returns ratio of values in column, that are equal to default value of column.
/// Checks only @sample_ratio ratio of rows.
virtual double get_ratio_of_default_rows(double sample_ratio = 1.0) const { return 0.0; }
Expand All @@ -633,8 +614,6 @@ class IColumn : public COW<IColumn> {

virtual bool is_column_string() const { return false; }

virtual bool is_predicate_column() const { return false; }

virtual bool is_column_string64() const { return false; }

virtual bool is_column_decimal() const { return false; }
Expand Down Expand Up @@ -677,7 +656,6 @@ class IColumn : public COW<IColumn> {
String dump_structure() const;

// only used in agg value replace for column which is not variable length, eg.BlockReader::_copy_value_data
// ColumnString should replace according to 0,1,2... ,size,0,1,2...
// usage: self_column.replace_column_data(other_column, other_column's row index, self_column's row index)
virtual void replace_column_data(const IColumn&, size_t row, size_t self_row = 0) = 0;
// replace data to default value if null, used to avoid null data output decimal check failure
Expand Down Expand Up @@ -710,6 +688,9 @@ class IColumn : public COW<IColumn> {
template <typename Derived>
void append_data_by_selector_impl(MutablePtr& res, const Selector& selector, size_t begin,
size_t end) const;
template <typename Derived>
void insert_from_multi_column_impl(const std::vector<const IColumn*>& srcs,
const std::vector<size_t>& positions);
};

using ColumnPtr = IColumn::Ptr;
Expand Down
5 changes: 0 additions & 5 deletions be/src/vec/columns/column_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,6 @@ class ColumnObject final : public COWHelper<IColumn, ColumnObject> {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "get_raw_data" + get_name());
}

size_t size_of_value_if_fixed() const override {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
"size_of_value_if_fixed" + get_name());
}

StringRef get_data_at(size_t) const override {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "get_data_at" + get_name());
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/vec/common/schema_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ Status _parse_variant_columns(Block& block, const std::vector<int>& variant_pos,
bool is_nullable = column_ref->is_nullable();
const auto& column = remove_nullable(column_ref);
const auto& var = assert_cast<const ColumnObject&>(*column.get());
((ColumnObject&)var).finalize();
// ColumnObject should be finalized before parsing, finalize maybe modify original column structure
const_cast<ColumnObject&>(var).finalize();

MutableColumnPtr variant_column;
if (!var.is_scalar_variant()) {
Expand Down
3 changes: 2 additions & 1 deletion be/src/vec/functions/function_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,8 @@ class FunctionCast final : public IFunctionBase {
auto& variant = assert_cast<const ColumnObject&>(*col_from);
ColumnPtr col_to = data_type_to->create_column();
if (!variant.is_finalized()) {
((ColumnObject&)variant).finalize();
// ColumnObject should be finalized before parsing, finalize maybe modify original column structure
const_cast<ColumnObject&>(variant).finalize();
}
// It's important to convert as many elements as possible in this context. For instance,
// if the root of this variant column is a number column, converting it to a number column
Expand Down
4 changes: 3 additions & 1 deletion be/src/vec/functions/function_variant_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class FunctionVariantElement : public IFunction {
*result = ColumnObject::create(true);
// src subcolumns empty but src row count may not be 0
(*result)->assume_mutable()->insert_many_defaults(src.size());
((ColumnObject&)(*result)).finalize();
// ColumnObject should be finalized before parsing, finalize maybe modify original column structure
auto& variant = assert_cast<const ColumnObject&>(*(*result));
const_cast<ColumnObject&>(variant).finalize();
return Status::OK();
}
if (src.is_scalar_variant() &&
Expand Down
13 changes: 2 additions & 11 deletions be/test/vec/columns/column_ip_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ TEST_F(ColumnIPTest, FieldTest) {
TEST_F(ColumnIPTest, GetRawDataTest) {
// insert from data csv and assert insert result
MutableColumns ip_cols;
// ip_cols.push_back(column_ipv4->get_ptr());
ip_cols.push_back(column_ipv6->get_ptr());
check_data(ip_cols, {serde[1]}, ';', {2}, data_files[0], assert_get_raw_data_callback<IPv6>);
}
Expand Down Expand Up @@ -183,14 +182,6 @@ TEST_F(ColumnIPTest, SizeTest) {
check_data(ip_cols, serde, ';', {1, 2}, data_files[0], assert_size_callback);
}

TEST_F(ColumnIPTest, SizeOfValueIfFixedTest) {
// insert from data csv and assert insert result
MutableColumns ip_cols;
ip_cols.push_back(column_ipv4->get_ptr());
ip_cols.push_back(column_ipv6->get_ptr());
check_data(ip_cols, serde, ';', {1, 2}, data_files[0], assert_size_of_value_if_fixed_callback);
}

TEST_F(ColumnIPTest, ByteSizeTest) {
// insert from data csv and assert insert result
MutableColumns ip_cols;
Expand Down Expand Up @@ -305,8 +296,8 @@ TEST_F(ColumnIPTest, PermutationAndSortTest) {
ip_cols.push_back(column_ipv6->get_ptr());
load_data_from_csv(serde, ip_cols, data_files[0], ';', {1, 2});
// this function will make res not equal ?!
// assertColumnPermutations(column_ipv4->assume_mutable_ref(), dt_ipv4);
// assertColumnPermutations(column_ipv6->assume_mutable_ref(), dt_ipv6);
assertColumnPermutations(column_ipv4->assume_mutable_ref(), dt_ipv4);
assertColumnPermutations(column_ipv6->assume_mutable_ref(), dt_ipv6);
// assertColumnPermutations(column_ipv4->assume_mutable_ref(), IndexInRangeUInt32Transform());
// assertColumnPermutations(column_ipv6->assume_mutable_ref(), IndexInRangeUInt64Transform());
}
Expand Down
Loading

0 comments on commit 5ea740b

Please sign in to comment.