diff --git a/be/src/core/data_type/data_type.cpp b/be/src/core/data_type/data_type.cpp index 2fc6cd14a6cb71..a11c17a6cd24f7 100644 --- a/be/src/core/data_type/data_type.cpp +++ b/be/src/core/data_type/data_type.cpp @@ -60,7 +60,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 36014eeb574410..8d73c9036b13a6 100644 --- a/be/src/core/data_type/data_type.h +++ b/be/src/core/data_type/data_type.h @@ -124,11 +124,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 a923ee47734245..c30cabe26c745b 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 a1c67ab8979de6..3722e97a1fa7a9 100644 --- a/be/src/core/data_type/data_type_decimal.cpp +++ b/be/src/core/data_type/data_type_decimal.cpp @@ -206,11 +206,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 f81619a491d912..0aac381d16fab8 100644 --- a/be/src/core/data_type/data_type_decimal.h +++ b/be/src/core/data_type/data_type_decimal.h @@ -243,8 +243,6 @@ class DataTypeDecimal final : public IDataType, public DecimalScaleInfo { 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 225cfa5ecb10b8..5e373921ed66a5 100644 --- a/be/src/core/data_type/data_type_jsonb.cpp +++ b/be/src/core/data_type/data_type_jsonb.cpp @@ -34,17 +34,6 @@ class IColumn; } // namespace doris namespace doris { -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 bfe97d85ed293b..7cd866d2c621cd 100644 --- a/be/src/core/data_type/data_type_jsonb.h +++ b/be/src/core/data_type/data_type_jsonb.h @@ -63,8 +63,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 3a83848d82e96d..0932bf47c218bd 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 75848208b075b3..365dd86c4ee154 100644 --- a/be/src/core/data_type/data_type_nullable.cpp +++ b/be/src/core/data_type/data_type_nullable.cpp @@ -142,10 +142,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 ffae13424d00de..dcd167bce1df0d 100644 --- a/be/src/core/data_type/data_type_number_base.cpp +++ b/be/src/core/data_type/data_type_number_base.cpp @@ -70,11 +70,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 fe03348381a8f6..cc87f8d6b041af 100644 --- a/be/src/core/data_type/data_type_number_base.h +++ b/be/src/core/data_type/data_type_number_base.h @@ -119,8 +119,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 871e91112e3473..2fa6d3e99d8f5b 100644 --- a/be/src/core/data_type/data_type_string.cpp +++ b/be/src/core/data_type/data_type_string.cpp @@ -43,10 +43,6 @@ namespace doris { -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 fa50fa6e72d593..0770899d661129 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 581d161491a87e..7fc31fe54f9b04 100644 --- a/be/src/core/data_type/data_type_varbinary.cpp +++ b/be/src/core/data_type/data_type_varbinary.cpp @@ -41,10 +41,6 @@ namespace doris { -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 d4353b9c858b8e..02fb0ed31556b8 100644 --- a/be/src/core/data_type/data_type_variant.h +++ b/be/src/core/data_type/data_type_variant.h @@ -72,7 +72,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 c417733c8d17ca..7b97ecfc081167 100644 --- a/be/src/storage/partial_update_info.cpp +++ b/be/src/storage/partial_update_info.cpp @@ -448,7 +448,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, @@ -618,7 +618,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); @@ -724,7 +724,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 6bacf1541b1eeb..6802092c74995e 100644 --- a/be/src/storage/tablet/base_tablet.cpp +++ b/be/src/storage/tablet/base_tablet.cpp @@ -1073,7 +1073,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, @@ -1125,7 +1125,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 9825f836186eb6..469ed9dd24d1ad 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() 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 2510513ffd7e6c..dedc6eda9ecbdb 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 810f0c0a66f948..2d9fbb8b78d618 100644 --- a/be/test/core/data_type/data_type_decimal_test.cpp +++ b/be/test/core/data_type/data_type_decimal_test.cpp @@ -460,20 +460,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 47d0198b9eaf5f..4eb3187e5ba080 100644 --- a/be/test/core/data_type/data_type_jsonb_test.cpp +++ b/be/test/core/data_type/data_type_jsonb_test.cpp @@ -241,12 +241,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 07c2e9f749a202..7b8d6839a2d55a 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 34d418889c4cf0..a477db7e46e4d2 100644 --- a/be/test/core/data_type/data_type_string_test.cpp +++ b/be/test/core/data_type/data_type_string_test.cpp @@ -244,8 +244,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 373867c2f4e1f9..d71710ceb25ce0 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