diff --git a/be/src/core/column/column_variant.cpp b/be/src/core/column/column_variant.cpp index 9938faada1632a..f85833b75c04f1 100644 --- a/be/src/core/column/column_variant.cpp +++ b/be/src/core/column/column_variant.cpp @@ -2620,64 +2620,29 @@ bool ColumnVariant::try_insert_many_defaults_from_nested(const Subcolumns::NodeP return true; } -/// Visitor that keeps @num_dimensions_to_keep dimensions in arrays -/// and replaces all scalars or nested arrays to @replacement at that level. -class FieldVisitorReplaceScalars : public StaticVisitor { -public: - FieldVisitorReplaceScalars(const Field& replacement_, size_t num_dimensions_to_keep_) - : replacement(replacement_), num_dimensions_to_keep(num_dimensions_to_keep_) {} - - template - Field apply(const typename PrimitiveTypeTraits::CppType& x) const { - if constexpr (T == TYPE_ARRAY) { - if (num_dimensions_to_keep == 0) { - return replacement; - } - - const size_t size = x.size(); - Array res(size); - for (size_t i = 0; i < size; ++i) { - res[i] = apply_visitor( - FieldVisitorReplaceScalars(replacement, num_dimensions_to_keep - 1), x[i]); - } - return Field::create_field(res); - } else { - return replacement; - } - } - -private: - const Field& replacement; - size_t num_dimensions_to_keep; -}; - bool ColumnVariant::try_insert_default_from_nested(const Subcolumns::NodePtr& entry) const { const auto* leaf = get_leaf_of_the_same_nested(entry); if (!leaf) { return false; } - auto last_field = leaf->data.get_last_field(); - if (last_field.is_null()) { + size_t leaf_size = leaf->data.size(); + if (leaf_size == 0) { return false; } - size_t leaf_num_dimensions = leaf->data.get_dimensions(); - size_t entry_num_dimensions = entry->data.get_dimensions(); - - if (entry_num_dimensions > leaf_num_dimensions) { - throw doris::Exception( - ErrorCode::INVALID_ARGUMENT, - "entry_num_dimensions > leaf_num_dimensions, entry_num_dimensions={}, " - "leaf_num_dimensions={}", - entry_num_dimensions, leaf_num_dimensions); + if (leaf->data.is_null_at(leaf_size - 1)) { + return false; } - auto default_scalar = entry->data.get_least_common_type()->get_default(); + FieldInfo field_info = { + .scalar_type_id = entry->data.least_common_type.get_base_type_id(), + .num_dimensions = entry->data.get_dimensions(), + }; - auto default_field = apply_visitor( - FieldVisitorReplaceScalars(default_scalar, leaf_num_dimensions), last_field); - entry->data.insert(std::move(default_field)); + auto new_subcolumn = leaf->data.cut(leaf_size - 1, 1).clone_with_default_values(field_info); + entry->data.insert_range_from(new_subcolumn, 0, 1); + ENABLE_CHECK_CONSISTENCY(this); return true; } diff --git a/be/src/core/data_type/data_type.cpp b/be/src/core/data_type/data_type.cpp index e4c93e38dbb231..60e5b6f2ee6204 100644 --- a/be/src/core/data_type/data_type.cpp +++ b/be/src/core/data_type/data_type.cpp @@ -61,7 +61,9 @@ ColumnPtr IDataType::create_column_const(size_t size, const Field& field) const } ColumnPtr IDataType::create_column_const_with_default_value(size_t size) const { - return create_column_const(size, get_default()); + auto column = create_column(); + column->insert_default(); + return ColumnConst::create(std::move(column), size); } size_t IDataType::get_size_of_value_in_memory() const { diff --git a/be/src/core/data_type/data_type.h b/be/src/core/data_type/data_type.h index e013fa206c9906..8b62b1bb794ff9 100644 --- a/be/src/core/data_type/data_type.h +++ b/be/src/core/data_type/data_type.h @@ -125,11 +125,6 @@ class IDataType : private boost::noncopyable { ColumnPtr create_column_const(size_t size, const Field& field) const; ColumnPtr create_column_const_with_default_value(size_t size) const; - /** Get default value of data type. - * It is the "default" default, regardless the fact that a table could contain different user-specified default. - */ - virtual Field get_default() const = 0; - virtual Field get_field(const TExprNode& node) const = 0; /// Checks that two instances belong to the same type diff --git a/be/src/core/data_type/data_type_array.cpp b/be/src/core/data_type/data_type_array.cpp index 851a98695b599a..f1841f0e2dc904 100644 --- a/be/src/core/data_type/data_type_array.cpp +++ b/be/src/core/data_type/data_type_array.cpp @@ -59,12 +59,6 @@ Status DataTypeArray::check_column(const IColumn& column) const { return nested->check_column(column_array->get_data()); } -Field DataTypeArray::get_default() const { - Array a; - a.push_back(nested->get_default()); - return Field::create_field(a); -} - bool DataTypeArray::equals(const IDataType& rhs) const { return typeid(rhs) == typeid(*this) && nested->equals(*static_cast(rhs).nested); diff --git a/be/src/core/data_type/data_type_array.h b/be/src/core/data_type/data_type_array.h index d17743cd958489..7579ad5cb2604e 100644 --- a/be/src/core/data_type/data_type_array.h +++ b/be/src/core/data_type/data_type_array.h @@ -67,7 +67,6 @@ class DataTypeArray final : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, diff --git a/be/src/core/data_type/data_type_bitmap.h b/be/src/core/data_type/data_type_bitmap.h index 66fd0a8a114fec..c47e9b30a78c15 100644 --- a/be/src/core/data_type/data_type_bitmap.h +++ b/be/src/core/data_type/data_type_bitmap.h @@ -68,10 +68,6 @@ class DataTypeBitMap : public IDataType { bool equals(const IDataType& rhs) const override { return typeid(rhs) == typeid(*this); } - Field get_default() const override { - return Field::create_field(BitmapValue::empty_bitmap()); - } - [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for BitMap"); diff --git a/be/src/core/data_type/data_type_decimal.cpp b/be/src/core/data_type/data_type_decimal.cpp index cfc06c83ceecc8..eaf5ee95622c57 100644 --- a/be/src/core/data_type/data_type_decimal.cpp +++ b/be/src/core/data_type/data_type_decimal.cpp @@ -259,11 +259,6 @@ void DataTypeDecimal::to_pb_column_meta(PColumnMeta* col_meta) const { } } -template -Field DataTypeDecimal::get_default() const { - return Field::create_field(typename PrimitiveTypeTraits::CppType()); -} - template MutableColumnPtr DataTypeDecimal::create_column() const { return ColumnType::create(0, scale); diff --git a/be/src/core/data_type/data_type_decimal.h b/be/src/core/data_type/data_type_decimal.h index 5d75d4e26721ed..12b7605d964bbe 100644 --- a/be/src/core/data_type/data_type_decimal.h +++ b/be/src/core/data_type/data_type_decimal.h @@ -184,8 +184,6 @@ class DataTypeDecimal final : public IDataType { int be_exec_version) const override; void to_pb_column_meta(PColumnMeta* col_meta) const override; - Field get_default() const override; - Field get_field(const TExprNode& node) const override { DCHECK_EQ(node.node_type, TExprNodeType::DECIMAL_LITERAL); DCHECK(node.__isset.decimal_literal); diff --git a/be/src/core/data_type/data_type_fixed_length_object.h b/be/src/core/data_type/data_type_fixed_length_object.h index fae94895ee02d4..d8ff996ab62626 100644 --- a/be/src/core/data_type/data_type_fixed_length_object.h +++ b/be/src/core/data_type/data_type_fixed_length_object.h @@ -52,8 +52,6 @@ class DataTypeFixedLengthObject final : public IDataType { return doris::FieldType::OLAP_FIELD_TYPE_NONE; } - Field get_default() const override { return Field::create_field(String()); } - [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for DataTypeFixedLengthObject"); diff --git a/be/src/core/data_type/data_type_hll.h b/be/src/core/data_type/data_type_hll.h index 0b111b2ff3f9d7..3c4b632cc14135 100644 --- a/be/src/core/data_type/data_type_hll.h +++ b/be/src/core/data_type/data_type_hll.h @@ -68,10 +68,6 @@ class DataTypeHLL : public IDataType { bool equals(const IDataType& rhs) const override { return typeid(rhs) == typeid(*this); } - Field get_default() const override { - return Field::create_field(HyperLogLog::empty()); - } - [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for HLL"); } diff --git a/be/src/core/data_type/data_type_jsonb.cpp b/be/src/core/data_type/data_type_jsonb.cpp index 416a4af11e0101..dce379027d356c 100644 --- a/be/src/core/data_type/data_type_jsonb.cpp +++ b/be/src/core/data_type/data_type_jsonb.cpp @@ -35,17 +35,6 @@ class IColumn; namespace doris { #include "common/compile_check_begin.h" -Field DataTypeJsonb::get_default() const { - std::string default_json = "null"; - // convert default_json to binary - JsonBinaryValue jsonb_value; - THROW_IF_ERROR(jsonb_value.from_json_string(default_json)); - // Throw exception if default_json.size() is large than INT32_MAX - // JsonbField keeps its own memory - return Field::create_field( - JsonbField(jsonb_value.value(), cast_set(jsonb_value.size()))); -} - Field DataTypeJsonb::get_field(const TExprNode& node) const { DCHECK_EQ(node.node_type, TExprNodeType::JSON_LITERAL); DCHECK(node.__isset.json_literal); diff --git a/be/src/core/data_type/data_type_jsonb.h b/be/src/core/data_type/data_type_jsonb.h index c11b5e077a9cdc..c7fe0af35af7ea 100644 --- a/be/src/core/data_type/data_type_jsonb.h +++ b/be/src/core/data_type/data_type_jsonb.h @@ -64,8 +64,6 @@ class DataTypeJsonb final : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; - Field get_field(const TExprNode& node) const override; FieldWithDataType get_field_with_data_type(const IColumn& column, diff --git a/be/src/core/data_type/data_type_map.cpp b/be/src/core/data_type/data_type_map.cpp index 9705811e85b242..42581b1f93c30d 100644 --- a/be/src/core/data_type/data_type_map.cpp +++ b/be/src/core/data_type/data_type_map.cpp @@ -44,16 +44,6 @@ DataTypeMap::DataTypeMap(const DataTypePtr& key_type_, const DataTypePtr& value_ value_type = value_type_; } -Field DataTypeMap::get_default() const { - Map m; - Array key, val; - key.push_back(key_type->get_default()); - val.push_back(value_type->get_default()); - m.push_back(Field::create_field(key)); - m.push_back(Field::create_field(val)); - return Field::create_field(m); -}; - MutableColumnPtr DataTypeMap::create_column() const { return ColumnMap::create(key_type->create_column(), value_type->create_column(), ColumnArray::ColumnOffsets::create()); diff --git a/be/src/core/data_type/data_type_map.h b/be/src/core/data_type/data_type_map.h index 2224eb0adcb5e9..ccb155af330574 100644 --- a/be/src/core/data_type/data_type_map.h +++ b/be/src/core/data_type/data_type_map.h @@ -67,7 +67,6 @@ class DataTypeMap final : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for map"); diff --git a/be/src/core/data_type/data_type_nothing.h b/be/src/core/data_type/data_type_nothing.h index e50c9c87a946b9..f73388c954c1df 100644 --- a/be/src/core/data_type/data_type_nothing.h +++ b/be/src/core/data_type/data_type_nothing.h @@ -70,12 +70,6 @@ class DataTypeNothing final : public IDataType { const char* deserialize(const char* buf, MutableColumnPtr* column, int be_exec_version) const override; - [[noreturn]] Field get_default() const override { - throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, - "Method get_default() is not implemented for data type {}.", - get_name()); - } - [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for Nothing"); diff --git a/be/src/core/data_type/data_type_nullable.cpp b/be/src/core/data_type/data_type_nullable.cpp index dcf67afd2cf134..b8310bfca93a99 100644 --- a/be/src/core/data_type/data_type_nullable.cpp +++ b/be/src/core/data_type/data_type_nullable.cpp @@ -207,10 +207,6 @@ Status DataTypeNullable::check_column(const IColumn& column) const { return nested_data_type->check_column(column_nullable->get_nested_column()); } -Field DataTypeNullable::get_default() const { - return Field(); -} - bool DataTypeNullable::equals(const IDataType& rhs) const { return rhs.is_nullable() && nested_data_type->equals(*static_cast(rhs).nested_data_type); diff --git a/be/src/core/data_type/data_type_nullable.h b/be/src/core/data_type/data_type_nullable.h index fbb653ba1a1d73..a506fb9fb568b4 100644 --- a/be/src/core/data_type/data_type_nullable.h +++ b/be/src/core/data_type/data_type_nullable.h @@ -73,8 +73,6 @@ class DataTypeNullable final : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; - Field get_field(const TExprNode& node) const override { if (node.node_type == TExprNodeType::NULL_LITERAL) { return Field(); diff --git a/be/src/core/data_type/data_type_number_base.cpp b/be/src/core/data_type/data_type_number_base.cpp index f2149bf29eb254..1dd7a19591b067 100644 --- a/be/src/core/data_type/data_type_number_base.cpp +++ b/be/src/core/data_type/data_type_number_base.cpp @@ -71,11 +71,6 @@ std::string DataTypeNumberBase::to_string( } #endif -template -Field DataTypeNumberBase::get_default() const { - return Field::create_field(typename PrimitiveTypeTraits::CppType()); -} - template Field DataTypeNumberBase::get_field(const TExprNode& node) const { if constexpr (T == TYPE_BOOLEAN) { diff --git a/be/src/core/data_type/data_type_number_base.h b/be/src/core/data_type/data_type_number_base.h index 6614f25930bd15..4b3fb37406c6b5 100644 --- a/be/src/core/data_type/data_type_number_base.h +++ b/be/src/core/data_type/data_type_number_base.h @@ -120,8 +120,6 @@ class DataTypeNumberBase : public IDataType { throw Exception(Status::FatalError("__builtin_unreachable")); } - Field get_default() const override; - Field get_field(const TExprNode& node) const override; int64_t get_uncompressed_serialized_bytes(const IColumn& column, diff --git a/be/src/core/data_type/data_type_quantilestate.h b/be/src/core/data_type/data_type_quantilestate.h index 210873642c8737..370f9bcb7d487e 100644 --- a/be/src/core/data_type/data_type_quantilestate.h +++ b/be/src/core/data_type/data_type_quantilestate.h @@ -64,10 +64,6 @@ class DataTypeQuantileState : public IDataType { bool equals(const IDataType& rhs) const override { return typeid(rhs) == typeid(*this); } - Field get_default() const override { - return Field::create_field(QuantileState()); - } - [[noreturn]] Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for quantile state"); diff --git a/be/src/core/data_type/data_type_string.cpp b/be/src/core/data_type/data_type_string.cpp index 27866dd80f5223..05dfb781486c49 100644 --- a/be/src/core/data_type/data_type_string.cpp +++ b/be/src/core/data_type/data_type_string.cpp @@ -44,10 +44,6 @@ namespace doris { #include "common/compile_check_begin.h" -Field DataTypeString::get_default() const { - return Field::create_field(String()); -} - MutableColumnPtr DataTypeString::create_column() const { return ColumnString::create(); } diff --git a/be/src/core/data_type/data_type_string.h b/be/src/core/data_type/data_type_string.h index 083c153dfb3283..32385b7afb1991 100644 --- a/be/src/core/data_type/data_type_string.h +++ b/be/src/core/data_type/data_type_string.h @@ -67,8 +67,6 @@ class DataTypeString : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; - Field get_field(const TExprNode& node) const override { DCHECK_EQ(node.node_type, TExprNodeType::STRING_LITERAL); DCHECK(node.__isset.string_literal); diff --git a/be/src/core/data_type/data_type_struct.cpp b/be/src/core/data_type/data_type_struct.cpp index 0c981481c69db4..d0b119e1c60431 100644 --- a/be/src/core/data_type/data_type_struct.cpp +++ b/be/src/core/data_type/data_type_struct.cpp @@ -125,15 +125,6 @@ Status DataTypeStruct::check_column(const IColumn& column) const { return Status::OK(); } -Field DataTypeStruct::get_default() const { - size_t size = elems.size(); - Tuple t; - for (size_t i = 0; i < size; ++i) { - t.push_back(elems[i]->get_default()); - } - return Field::create_field(t); -} - bool DataTypeStruct::equals(const IDataType& rhs) const { if (typeid(rhs) != typeid(*this)) { return false; diff --git a/be/src/core/data_type/data_type_struct.h b/be/src/core/data_type/data_type_struct.h index 9f7d90667a786f..657364efbca52f 100644 --- a/be/src/core/data_type/data_type_struct.h +++ b/be/src/core/data_type/data_type_struct.h @@ -81,8 +81,6 @@ class DataTypeStruct final : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; - Field get_field(const TExprNode& node) const override { throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, "Unimplemented get_field for struct"); diff --git a/be/src/core/data_type/data_type_varbinary.cpp b/be/src/core/data_type/data_type_varbinary.cpp index f4d51e8d0818de..0bf483b8bbc203 100644 --- a/be/src/core/data_type/data_type_varbinary.cpp +++ b/be/src/core/data_type/data_type_varbinary.cpp @@ -42,10 +42,6 @@ namespace doris { #include "common/compile_check_begin.h" -Field DataTypeVarbinary::get_default() const { - return Field::create_field(StringView()); -} - MutableColumnPtr DataTypeVarbinary::create_column() const { return ColumnVarbinary::create(); } diff --git a/be/src/core/data_type/data_type_varbinary.h b/be/src/core/data_type/data_type_varbinary.h index c987cb946c2779..de50e59c8f8c77 100644 --- a/be/src/core/data_type/data_type_varbinary.h +++ b/be/src/core/data_type/data_type_varbinary.h @@ -66,8 +66,6 @@ class DataTypeVarbinary : public IDataType { MutableColumnPtr create_column() const override; Status check_column(const IColumn& column) const override; - Field get_default() const override; - Field get_field(const TExprNode& node) const override { DCHECK_EQ(node.node_type, TExprNodeType::VARBINARY_LITERAL); DCHECK(node.__isset.varbinary_literal); diff --git a/be/src/core/data_type/data_type_variant.h b/be/src/core/data_type/data_type_variant.h index a55f43b82c3b08..f8ec3484d6b686 100644 --- a/be/src/core/data_type/data_type_variant.h +++ b/be/src/core/data_type/data_type_variant.h @@ -73,7 +73,6 @@ class DataTypeVariant : public IDataType { char* serialize(const IColumn& column, char* buf, int be_exec_version) const override; const char* deserialize(const char* buf, MutableColumnPtr* column, int be_exec_version) const override; - Field get_default() const override { return Field::create_field(VariantMap()); } Field get_field(const TExprNode& node) const override; diff --git a/be/src/storage/partial_update_info.cpp b/be/src/storage/partial_update_info.cpp index 33b55372a419df..e1eaee711d12b9 100644 --- a/be/src/storage/partial_update_info.cpp +++ b/be/src/storage/partial_update_info.cpp @@ -449,7 +449,7 @@ Status FixedReadPlan::fill_missing_columns( // If the control flow reaches this branch, the column neither has default value // nor is nullable. It means that the row's delete sign is marked, and the value // columns are useless and won't be read. So we can just put arbitary values in the cells - missing_col->insert(tablet_column.get_vec_type()->get_default()); + missing_col->insert_default(); } } else { missing_col->insert_from(*old_value_block.get_by_position(i).column, @@ -619,7 +619,7 @@ static void fill_non_primary_key_cell_for_column_store( // store the generated auto-increment value in fixed partial update new_col->insert_from(cur_col, block_pos); } else { - new_col->insert(tablet_column.get_vec_type()->get_default()); + new_col->insert_default(); } } else { auto pos_in_old_block = read_index.at(cid).at(segment_pos); @@ -725,7 +725,7 @@ static void fill_non_primary_key_cell_for_row_store( // store the generated auto-increment value in fixed partial update new_col->insert_from(cur_col, block_pos); } else { - new_col->insert(tablet_column.get_vec_type()->get_default()); + new_col->insert_default(); } } else { new_col->insert_from(old_value_col, pos_in_old_block); diff --git a/be/src/storage/tablet/base_tablet.cpp b/be/src/storage/tablet/base_tablet.cpp index a87e3a75656f87..fbdc5544044c2a 100644 --- a/be/src/storage/tablet/base_tablet.cpp +++ b/be/src/storage/tablet/base_tablet.cpp @@ -1167,7 +1167,7 @@ Status BaseTablet::generate_new_block_for_partial_update( mutable_column.get()) ->insert_default(); } else { - mutable_column->insert(rs_column.get_vec_type()->get_default()); + mutable_column->insert_default(); } } else { mutable_column->insert_from(*old_block.get_by_position(i).column, @@ -1219,7 +1219,7 @@ static void fill_cell_for_flexible_partial_update( // keep consistency between replicas new_col->insert_from(cur_col, read_index_update[cast_set(idx)]); } else { - new_col->insert(tablet_column.get_vec_type()->get_default()); + new_col->insert_default(); } } else { new_col->insert_from(old_value_col, read_index_old[cast_set(idx)]); diff --git a/be/test/core/column/column_variant_test.cpp b/be/test/core/column/column_variant_test.cpp index 2c81fe1a107c9f..45894ef30e1ef1 100644 --- a/be/test/core/column/column_variant_test.cpp +++ b/be/test/core/column/column_variant_test.cpp @@ -1115,7 +1115,10 @@ TEST_F(ColumnVariantTest, clone_resized) { for (; i < clone_count; ++i) { // more than source size Field target_field; - Field source_field = column_variant->get_root_type()->get_default(); + auto default_column = column_variant->get_root_type()->create_column(); + default_column->insert_default(); + Field source_field; + default_column->get(0, source_field); target_column->get(i, target_field); EXPECT_EQ(target_field, source_field) << "target_field: " << target_field.get_type_name() @@ -3082,30 +3085,6 @@ TEST_F(ColumnVariantTest, get_field_info_all_types) { } } -TEST_F(ColumnVariantTest, field_visitor) { - // Test replacing scalar values in a flat array - { - Array array; - array.push_back(Field::create_field(Int64(1))); - array.push_back(Field::create_field(Int64(2))); - array.push_back(Field::create_field(Int64(3))); - - Field field = Field::create_field(std::move(array)); - Field replacement = Field::create_field(Int64(42)); - Field result = apply_visitor(FieldVisitorReplaceScalars(replacement, 0), field); - - EXPECT_EQ(result.get(), 42); - - Field replacement1 = Field::create_field(Int64(42)); - Field result1 = apply_visitor(FieldVisitorReplaceScalars(replacement, 1), field); - - EXPECT_EQ(result1.get().size(), 3); - EXPECT_EQ(result1.get()[0].get(), 42); - EXPECT_EQ(result1.get()[1].get(), 42); - EXPECT_EQ(result1.get()[2].get(), 42); - } -} - TEST_F(ColumnVariantTest, subcolumn_operations_coverage) { // Test insert_range_from { diff --git a/be/test/core/data_type/common_data_type_test.h b/be/test/core/data_type/common_data_type_test.h index d70d5df5da7acf..869ab4c33a8dba 100644 --- a/be/test/core/data_type/common_data_type_test.h +++ b/be/test/core/data_type/common_data_type_test.h @@ -145,7 +145,6 @@ class CommonDataTypeTest : public ::testing::Test { EXPECT_EQ(data_type->get_scale(), 0); } ASSERT_EQ(data_type->is_null_literal(), meta_info.is_null_literal); - ASSERT_EQ(data_type->get_default(), meta_info.default_field); } // create column assert with default field is simple and can be used for all DataType diff --git a/be/test/core/data_type/data_type_array_test.cpp b/be/test/core/data_type/data_type_array_test.cpp index 1613bba9d398cd..ebc6f3eedb8d42 100644 --- a/be/test/core/data_type/data_type_array_test.cpp +++ b/be/test/core/data_type/data_type_array_test.cpp @@ -333,14 +333,10 @@ class DataTypeArrayTest : public CommonDataTypeTest { TEST_F(DataTypeArrayTest, MetaInfoTest) { for (auto& type : array_types) { const auto* array_type = assert_cast(remove_nullable(type).get()); - auto nested_type = - assert_cast(remove_nullable(type).get())->get_nested_type(); auto arr_type_descriptor = type; auto col_meta = std::make_shared(); array_type->to_pb_column_meta(col_meta.get()); - Array a; - a.push_back(nested_type->get_default()); DataTypeMetaInfo arr_meta_info_to_assert = { .type_id = PrimitiveType::TYPE_ARRAY, @@ -354,7 +350,7 @@ TEST_F(DataTypeArrayTest, MetaInfoTest) { .scale = size_t(-1), .is_null_literal = false, .pColumnMeta = col_meta.get(), - .default_field = Field::create_field(a), + .default_field = Field::create_field(Array()), }; DataTypePtr arr = remove_nullable(type); meta_info_assert(arr, arr_meta_info_to_assert); diff --git a/be/test/core/data_type/data_type_datetime_v2_test.cpp b/be/test/core/data_type/data_type_datetime_v2_test.cpp index 02ae8d458b2583..5b29c52d95b646 100644 --- a/be/test/core/data_type/data_type_datetime_v2_test.cpp +++ b/be/test/core/data_type/data_type_datetime_v2_test.cpp @@ -123,23 +123,6 @@ TEST_F(DataTypeDateTimeV2Test, simple_func_test) { EXPECT_THROW(DataTypeTimeV2(7), Exception); } -TEST_F(DataTypeDateTimeV2Test, get_default) { - auto v = 0UL; - EXPECT_EQ(dt_datetime_v2_0.get_default(), - Field::create_field( - *(typename PrimitiveTypeTraits::CppType*)&v)); - EXPECT_EQ(dt_datetime_v2_5.get_default(), - Field::create_field( - *(typename PrimitiveTypeTraits::CppType*)&v)); - EXPECT_EQ(dt_datetime_v2_6.get_default(), - Field::create_field( - *(typename PrimitiveTypeTraits::CppType*)&v)); - EXPECT_EQ(dt_date_v2.get_default(), - Field::create_field( - *(typename PrimitiveTypeTraits::CppType*)&v)); - EXPECT_EQ(dt_time_v2_6.get_default(), Field::create_field(0.0)); -} - TEST_F(DataTypeDateTimeV2Test, get_field) { config::allow_zero_date = true; { diff --git a/be/test/core/data_type/data_type_decimal_test.cpp b/be/test/core/data_type/data_type_decimal_test.cpp index cef5eab6346489..22af5daa256495 100644 --- a/be/test/core/data_type/data_type_decimal_test.cpp +++ b/be/test/core/data_type/data_type_decimal_test.cpp @@ -488,20 +488,6 @@ TEST_F(DataTypeDecimalTest, to_pb_column_meta) { test_func(dt_decimal128v3_1, PGenericType::DECIMAL128I); test_func(dt_decimal256_1, PGenericType::DECIMAL256); } -TEST_F(DataTypeDecimalTest, get_default) { - auto test_func = [](auto dt) { - using DataType = decltype(dt); - using ColumnType = typename DataType::ColumnType; - auto default_field = dt.get_default(); - auto decimal_field = default_field.template get(); - EXPECT_EQ(decimal_field, typename ColumnType::value_type()); - }; - test_func(dt_decimal32_1); - test_func(dt_decimal64_1); - test_func(dt_decimal128v2); - test_func(dt_decimal128v3_1); - test_func(dt_decimal256_1); -} TEST_F(DataTypeDecimalTest, get_field) { TExprNode expr_node; expr_node.node_type = TExprNodeType::DECIMAL_LITERAL; diff --git a/be/test/core/data_type/data_type_insert_default_test.cpp b/be/test/core/data_type/data_type_insert_default_test.cpp new file mode 100644 index 00000000000000..1a7928139de659 --- /dev/null +++ b/be/test/core/data_type/data_type_insert_default_test.cpp @@ -0,0 +1,348 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include +#include + +#include "agent/be_exec_version_manager.h" +#include "core/data_type/data_type_agg_state.h" +#include "core/data_type/data_type_array.h" +#include "core/data_type/data_type_factory.hpp" +#include "core/data_type/data_type_fixed_length_object.h" +#include "core/data_type/data_type_map.h" +#include "core/data_type/data_type_nothing.h" +#include "core/data_type/data_type_nullable.h" +#include "core/data_type/data_type_struct.h" +#include "core/data_type/data_type_varbinary.h" +#include "core/data_type/data_type_variant.h" +#include "core/field.h" +#include "core/types.h" +#include "core/value/timestamptz_value.h" +#include "core/value/vdatetime_value.h" + +namespace doris { +namespace { + +Field get_default_field(const DataTypePtr& data_type) { + auto column = data_type->create_column(); + if (column->size() != 0) { + ADD_FAILURE() << "column should be empty before insert_default"; + return Field(); + } + + column->insert_default(); + if (column->size() != 1) { + ADD_FAILURE() << "column should contain one row after insert_default"; + return Field(); + } + + Field actual; + column->get(0, actual); + return actual; +} + +TEST(DataTypeInsertDefaultTest, AllTypeFamilies) { + auto make_simple_type = [](PrimitiveType type) { + return DataTypeFactory::instance().create_data_type(type, false); + }; + + auto int_type = make_simple_type(TYPE_INT); + auto nullable_int_type = std::make_shared(int_type); + auto nullable_string_type = std::make_shared(make_simple_type(TYPE_STRING)); + + { + SCOPED_TRACE("bool"); + auto actual = get_default_field(make_simple_type(TYPE_BOOLEAN)); + ASSERT_EQ(actual.get_type(), TYPE_BOOLEAN); + EXPECT_EQ(actual.get(), UInt8(0)); + } + + { + SCOPED_TRACE("tinyint"); + auto actual = get_default_field(make_simple_type(TYPE_TINYINT)); + ASSERT_EQ(actual.get_type(), TYPE_TINYINT); + EXPECT_EQ(actual.get(), Int8(0)); + } + + { + SCOPED_TRACE("smallint"); + auto actual = get_default_field(make_simple_type(TYPE_SMALLINT)); + ASSERT_EQ(actual.get_type(), TYPE_SMALLINT); + EXPECT_EQ(actual.get(), Int16(0)); + } + + { + SCOPED_TRACE("int"); + auto actual = get_default_field(make_simple_type(TYPE_INT)); + ASSERT_EQ(actual.get_type(), TYPE_INT); + EXPECT_EQ(actual.get(), Int32(0)); + } + + { + SCOPED_TRACE("bigint"); + auto actual = get_default_field(make_simple_type(TYPE_BIGINT)); + ASSERT_EQ(actual.get_type(), TYPE_BIGINT); + EXPECT_EQ(actual.get(), Int64(0)); + } + + { + SCOPED_TRACE("largeint"); + auto actual = get_default_field(make_simple_type(TYPE_LARGEINT)); + ASSERT_EQ(actual.get_type(), TYPE_LARGEINT); + EXPECT_EQ(actual.get(), Int128(0)); + } + + { + SCOPED_TRACE("float"); + auto actual = get_default_field(make_simple_type(TYPE_FLOAT)); + ASSERT_EQ(actual.get_type(), TYPE_FLOAT); + EXPECT_EQ(actual.get(), Float32(0)); + } + + { + SCOPED_TRACE("double"); + auto actual = get_default_field(make_simple_type(TYPE_DOUBLE)); + ASSERT_EQ(actual.get_type(), TYPE_DOUBLE); + EXPECT_EQ(actual.get(), Float64(0)); + } + + { + SCOPED_TRACE("decimalv2"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_DECIMALV2, false, 27, 9)); + ASSERT_EQ(actual.get_type(), TYPE_DECIMALV2); + EXPECT_EQ(actual.get(), DecimalV2Value()); + } + + { + SCOPED_TRACE("decimal32"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_DECIMAL32, false, 9, 2)); + ASSERT_EQ(actual.get_type(), TYPE_DECIMAL32); + EXPECT_EQ(actual.get(), Decimal32(0)); + } + + { + SCOPED_TRACE("decimal64"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_DECIMAL64, false, 18, 9)); + ASSERT_EQ(actual.get_type(), TYPE_DECIMAL64); + EXPECT_EQ(actual.get(), Decimal64(0)); + } + + { + SCOPED_TRACE("decimal128"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_DECIMAL128I, false, 38, 18)); + ASSERT_EQ(actual.get_type(), TYPE_DECIMAL128I); + EXPECT_EQ(actual.get(), Decimal128V3(0)); + } + + { + SCOPED_TRACE("decimal256"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_DECIMAL256, false, 76, 18)); + ASSERT_EQ(actual.get_type(), TYPE_DECIMAL256); + EXPECT_EQ(actual.get(), Decimal256(0)); + } + + { + SCOPED_TRACE("date"); + auto actual = get_default_field(make_simple_type(TYPE_DATE)); + ASSERT_EQ(actual.get_type(), TYPE_DATE); + EXPECT_EQ(actual.get(), VecDateTimeValue::DEFAULT_VALUE); + } + + { + SCOPED_TRACE("datetime"); + auto actual = get_default_field(make_simple_type(TYPE_DATETIME)); + ASSERT_EQ(actual.get_type(), TYPE_DATETIME); + EXPECT_EQ(actual.get(), VecDateTimeValue::DEFAULT_VALUE); + } + + { + SCOPED_TRACE("datev2"); + auto actual = get_default_field(make_simple_type(TYPE_DATEV2)); + ASSERT_EQ(actual.get_type(), TYPE_DATEV2); + EXPECT_EQ(actual.get(), DateV2Value::DEFAULT_VALUE); + } + + { + SCOPED_TRACE("datetimev2"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_DATETIMEV2, false, 0, 6)); + ASSERT_EQ(actual.get_type(), TYPE_DATETIMEV2); + EXPECT_EQ(actual.get(), DateV2Value::DEFAULT_VALUE); + } + + { + SCOPED_TRACE("timev2"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_TIMEV2, false, 0, 6)); + ASSERT_EQ(actual.get_type(), TYPE_TIMEV2); + EXPECT_EQ(actual.get(), Float64(0)); + } + + { + SCOPED_TRACE("timestamptz"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_TIMESTAMPTZ, false, 0, 6)); + ASSERT_EQ(actual.get_type(), TYPE_TIMESTAMPTZ); + EXPECT_EQ(actual.get(), TimestampTzValue::DEFAULT_VALUE); + } + + { + SCOPED_TRACE("ipv4"); + auto actual = get_default_field(make_simple_type(TYPE_IPV4)); + ASSERT_EQ(actual.get_type(), TYPE_IPV4); + EXPECT_EQ(actual.get(), IPv4(0)); + } + + { + SCOPED_TRACE("ipv6"); + auto actual = get_default_field(make_simple_type(TYPE_IPV6)); + ASSERT_EQ(actual.get_type(), TYPE_IPV6); + EXPECT_EQ(actual.get(), IPv6(0)); + } + + { + SCOPED_TRACE("char"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_CHAR, false, 8, 0)); + ASSERT_EQ(actual.get_type(), TYPE_STRING); + EXPECT_EQ(actual.get(), String()); + } + + { + SCOPED_TRACE("varchar"); + auto actual = get_default_field( + DataTypeFactory::instance().create_data_type(TYPE_VARCHAR, false, 32, 0)); + ASSERT_EQ(actual.get_type(), TYPE_STRING); + EXPECT_EQ(actual.get(), String()); + } + + { + SCOPED_TRACE("string"); + auto actual = get_default_field(make_simple_type(TYPE_STRING)); + ASSERT_EQ(actual.get_type(), TYPE_STRING); + EXPECT_EQ(actual.get(), String()); + } + + { + SCOPED_TRACE("varbinary"); + auto actual = get_default_field(std::make_shared()); + ASSERT_EQ(actual.get_type(), TYPE_VARBINARY); + EXPECT_EQ(actual.get(), StringView()); + } + + { + SCOPED_TRACE("jsonb"); + auto actual = get_default_field(make_simple_type(TYPE_JSONB)); + ASSERT_TRUE(actual.get_type() == TYPE_JSONB || is_string_type(actual.get_type())); + if (actual.get_type() == TYPE_JSONB) { + EXPECT_EQ(actual.get().get_size(), 0); + } else { + EXPECT_TRUE(actual.get().empty()); + } + } + + { + SCOPED_TRACE("bitmap"); + auto actual = get_default_field(make_simple_type(TYPE_BITMAP)); + ASSERT_EQ(actual.get_type(), TYPE_BITMAP); + EXPECT_EQ(actual.get().cardinality(), 0); + } + + { + SCOPED_TRACE("hll"); + auto actual = get_default_field(make_simple_type(TYPE_HLL)); + ASSERT_EQ(actual.get_type(), TYPE_HLL); + EXPECT_EQ(actual.get().estimate_cardinality(), 0); + } + + { + SCOPED_TRACE("quantile_state"); + auto actual = get_default_field(make_simple_type(TYPE_QUANTILE_STATE)); + QuantileState empty_state; + ASSERT_EQ(actual.get_type(), TYPE_QUANTILE_STATE); + EXPECT_EQ(actual.get().get_serialized_size(), + empty_state.get_serialized_size()); + } + + { + SCOPED_TRACE("variant"); + auto actual = get_default_field(std::make_shared()); + ASSERT_EQ(actual.get_type(), TYPE_NULL); + EXPECT_TRUE(actual.is_null()); + } + + { + SCOPED_TRACE("nothing"); + auto actual = get_default_field(std::make_shared()); + ASSERT_EQ(actual.get_type(), TYPE_NULL); + EXPECT_TRUE(actual.is_null()); + } + + { + SCOPED_TRACE("nullable"); + auto actual = get_default_field(nullable_int_type); + ASSERT_EQ(actual.get_type(), TYPE_NULL); + EXPECT_TRUE(actual.is_null()); + } + + { + SCOPED_TRACE("array>"); + auto actual = get_default_field(std::make_shared(nullable_int_type)); + ASSERT_EQ(actual.get_type(), TYPE_ARRAY); + EXPECT_TRUE(actual.get().empty()); + } + + { + SCOPED_TRACE("map,nullable>"); + auto actual = get_default_field( + std::make_shared(nullable_string_type, nullable_int_type)); + ASSERT_EQ(actual.get_type(), TYPE_MAP); + const auto& map = actual.get(); + ASSERT_EQ(map.size(), 2); + EXPECT_TRUE(map[0].get().empty()); + EXPECT_TRUE(map[1].get().empty()); + } + + { + SCOPED_TRACE("struct,nullable>"); + auto actual = get_default_field(std::make_shared( + DataTypes {nullable_int_type, nullable_string_type})); + ASSERT_EQ(actual.get_type(), TYPE_STRUCT); + const auto& tuple = actual.get(); + ASSERT_EQ(tuple.size(), 2); + EXPECT_TRUE(tuple[0].is_null()); + EXPECT_TRUE(tuple[1].is_null()); + } + + { + SCOPED_TRACE("agg_state"); + auto actual = get_default_field(std::make_shared( + DataTypes {int_type}, false, "count", BeExecVersionManager::get_newest_version())); + ASSERT_EQ(actual.get_type(), TYPE_STRING); + EXPECT_EQ(actual.get(), String(8, '\0')); + } +} + +} // namespace +} // namespace doris \ No newline at end of file diff --git a/be/test/core/data_type/data_type_jsonb_test.cpp b/be/test/core/data_type/data_type_jsonb_test.cpp index 84b0f44dc2736a..75404cad8e4eb5 100644 --- a/be/test/core/data_type/data_type_jsonb_test.cpp +++ b/be/test/core/data_type/data_type_jsonb_test.cpp @@ -263,12 +263,6 @@ TEST_F(DataTypeJsonbTest, simple_func_test) { EXPECT_TRUE(dt.equals(dt)); EXPECT_EQ(std::string(dt.get_family_name()), std::string("JSONB")); - - JsonBinaryValue jsonb_value; - THROW_IF_ERROR(jsonb_value.from_json_string("null")); - EXPECT_EQ(dt.get_default(), - Field::create_field( - JsonbField(jsonb_value.value(), cast_set(jsonb_value.size())))); }; test_func(dt_jsonb); EXPECT_EQ(dt_jsonb.get_primitive_type(), TYPE_JSONB); diff --git a/be/test/core/data_type/data_type_number_test.cpp b/be/test/core/data_type/data_type_number_test.cpp index 5b8885ac3f38c1..3a0182acde1756 100644 --- a/be/test/core/data_type/data_type_number_test.cpp +++ b/be/test/core/data_type/data_type_number_test.cpp @@ -149,13 +149,6 @@ TEST_F(DataTypeNumberTest, get_storage_field_type) { EXPECT_EQ(dt_uint8.get_storage_field_type(), doris::FieldType::OLAP_FIELD_TYPE_BOOL); } -TEST_F(DataTypeNumberTest, get_default) { - EXPECT_EQ(dt_int8.get_default(), Field::create_field(0)); - EXPECT_EQ(dt_int16.get_default(), Field::create_field(0)); - EXPECT_EQ(dt_int32.get_default(), Field::create_field(0)); - EXPECT_EQ(dt_int64.get_default(), Field::create_field(0)); - EXPECT_EQ(dt_int128.get_default(), Field::create_field(Int128(0))); -} template void test_int_field(const typename PrimitiveTypeTraits::DataType& dt) { TExprNode expr_node; diff --git a/be/test/core/data_type/data_type_string_test.cpp b/be/test/core/data_type/data_type_string_test.cpp index b6d3b246a5c835..a8bc0ff4c8f800 100644 --- a/be/test/core/data_type/data_type_string_test.cpp +++ b/be/test/core/data_type/data_type_string_test.cpp @@ -266,8 +266,6 @@ TEST_F(DataTypeStringTest, simple_func_test) { EXPECT_TRUE(dt.equals(dt)); EXPECT_EQ(std::string(dt.get_family_name()), std::string("String")); - - EXPECT_EQ(dt.get_default(), Field::create_field(String())); }; test_func(dt_str); EXPECT_EQ(dt_str.get_primitive_type(), TYPE_STRING); diff --git a/be/test/core/data_type/data_type_varbinary_test.cpp b/be/test/core/data_type/data_type_varbinary_test.cpp index e592118e6ee132..8a99377dec7c94 100644 --- a/be/test/core/data_type/data_type_varbinary_test.cpp +++ b/be/test/core/data_type/data_type_varbinary_test.cpp @@ -86,13 +86,6 @@ TEST_F(DataTypeVarbinaryTest, CreateColumnAndCheckColumn) { EXPECT_FALSE(dt.check_column(*wrong).ok()); } -TEST_F(DataTypeVarbinaryTest, GetDefaultField) { - DataTypeVarbinary dt; - Field def = dt.get_default(); - const auto& sv = def.get(); - EXPECT_EQ(sv.size(), 0U); -} - TEST_F(DataTypeVarbinaryTest, ToStringAndToStringBufferWritable) { DataTypeVarbinary dt; auto col = dt.create_column(); diff --git a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out index 6f6a385a359772..279077bc86a3d8 100644 --- a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out +++ b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_complex_type.out @@ -26,9 +26,9 @@ -- !sql -- 1 doris1 {"jsonk1":123,"jsonk2":456} [100, 200] {"a":1, "b":2} {"b":3} 3 0 -1 \N null [null] {"a":null, "b":null} {null:null} 5 1 +1 \N NULL [] {"a":null, "b":null} {} 5 1 2 doris2 {"jsonk2":333,"jsonk4":444} [300, 400] {"a":3, "b":4} {"a":2} 2 0 -2 \N null [null] {"a":null, "b":null} {null:null} 5 1 +2 \N NULL [] {"a":null, "b":null} {} 5 1 3 doris3 {"jsonk3":456,"jsonk5":789} [600, 400] {"a":2, "b":7} {"cccc":10} 4 0 -- !update_varchar -- @@ -58,8 +58,8 @@ -- !sql -- 1 doris1 {"jsonk1":123,"jsonk2":456} [100, 200] {"a":1, "b":2} {"b":3} 3 0 -1 \N null [null] {"a":null, "b":null} {null:null} 5 1 +1 \N NULL [] {"a":null, "b":null} {} 5 1 2 doris2 {"jsonk2":333,"jsonk4":444} [300, 400] {"a":3, "b":4} {"a":2} 2 0 -2 \N null [null] {"a":null, "b":null} {null:null} 5 1 +2 \N NULL [] {"a":null, "b":null} {} 5 1 3 doris3 {"jsonk3":456,"jsonk5":789} [600, 400] {"a":2, "b":7} {"cccc":10} 4 0