This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 9d44918036 [Improve](data-type) Clean datatype uselesscode (#20145)
9d44918036 is described below
commit 9d449180361520ae7c3d257e10ac27ff63bb3266
Author: amory <[email protected]>
AuthorDate: Sun May 28 20:48:29 2023 +0800
[Improve](data-type) Clean datatype uselesscode (#20145)
* fix struct_export out data
* delete useless code with data type
---
be/src/vec/data_types/data_type.cpp | 5 -
be/src/vec/data_types/data_type.h | 40 +------
be/src/vec/data_types/data_type_array.h | 8 --
be/src/vec/data_types/data_type_bitmap.h | 4 -
be/src/vec/data_types/data_type_date.h | 1 -
be/src/vec/data_types/data_type_date_time.h | 1 -
be/src/vec/data_types/data_type_decimal.cpp | 8 --
be/src/vec/data_types/data_type_decimal.h | 2 -
.../vec/data_types/data_type_fixed_length_object.h | 1 -
be/src/vec/data_types/data_type_hll.h | 4 -
be/src/vec/data_types/data_type_jsonb.h | 2 -
be/src/vec/data_types/data_type_map.cpp | 7 +-
be/src/vec/data_types/data_type_map.h | 1 -
be/src/vec/data_types/data_type_nothing.h | 1 -
be/src/vec/data_types/data_type_nullable.h | 7 --
be/src/vec/data_types/data_type_number.h | 7 --
be/src/vec/data_types/data_type_number_base.h | 1 -
be/src/vec/data_types/data_type_quantilestate.h | 4 -
be/src/vec/data_types/data_type_string.h | 2 -
be/src/vec/data_types/data_type_time.h | 6 --
be/src/vec/data_types/data_type_time_v2.h | 2 -
be/test/CMakeLists.txt | 1 +
.../data_types/serde/data_type_to_string_test.cpp | 115 +++++++++++++++++++++
23 files changed, 123 insertions(+), 107 deletions(-)
diff --git a/be/src/vec/data_types/data_type.cpp
b/be/src/vec/data_types/data_type.cpp
index b049f73dfb..cf66b64f95 100644
--- a/be/src/vec/data_types/data_type.cpp
+++ b/be/src/vec/data_types/data_type.cpp
@@ -79,11 +79,6 @@ ColumnPtr
IDataType::create_column_const_with_default_value(size_t size) const {
return create_column_const(size, get_default());
}
-DataTypePtr IDataType::promote_numeric_type() const {
- LOG(FATAL) << fmt::format("Data type {} can't be promoted.", get_name());
- return nullptr;
-}
-
size_t IDataType::get_size_of_value_in_memory() const {
LOG(FATAL) << fmt::format("Value of type {} in memory is not of fixed
size.", get_name());
return 0;
diff --git a/be/src/vec/data_types/data_type.h
b/be/src/vec/data_types/data_type.h
index a088d6af25..6b10084e50 100644
--- a/be/src/vec/data_types/data_type.h
+++ b/be/src/vec/data_types/data_type.h
@@ -105,14 +105,6 @@ public:
virtual Field get_default() const = 0;
virtual Field get_field(const TExprNode& node) const = 0;
- /** The data type can be promoted in order to try to avoid overflows.
- * Data types which can be promoted are typically Number or Decimal data
types.
- */
- virtual bool can_be_promoted() const { return false; }
-
- /** Return the promoted numeric data type of the current data type. Throw
an exception if `can_be_promoted() == false`.
- */
- virtual DataTypePtr promote_numeric_type() const;
/** Directly insert default value into a column. Default implementation
use method IColumn::insert_default.
* This should be overridden if data type default value differs from
column default value (example: Enum data types).
@@ -135,11 +127,6 @@ public:
*/
virtual bool have_subtypes() const = 0;
- /** Can appear in table definition.
- * Counterexamples: Interval, Nothing.
- */
- virtual bool cannot_be_stored_in_tables() const { return false; }
-
/** In text formats that render "pretty" tables,
* is it better to align value right in table cell.
* Examples: numbers, even nullable.
@@ -158,18 +145,6 @@ public:
* The same for nullable of comparable types: they are comparable (but
not totally-comparable).
*/
virtual bool is_comparable() const { return false; }
-
- /** Does it make sense to use this type with COLLATE modifier in ORDER BY.
- * Example: String, but not FixedString.
- */
- virtual bool can_be_compared_with_collation() const { return false; }
-
- /** If the type is totally comparable (Ints, Date, DateTime, not nullable,
not floats)
- * and "simple" enough (not String, FixedString) to be used as version
number
- * (to select rows with maximum version).
- */
- virtual bool can_be_used_as_version() const { return false; }
-
/** Values of data type can be summed (possibly with overflow, within the
same data type).
* Example: numbers, even nullable. Not Date/DateTime. Not Enum.
* Enums can be passed to aggregate function 'sum', but the result is
Int64, not Enum, so they are not summable.
@@ -230,10 +205,6 @@ public:
*/
virtual size_t get_size_of_value_in_memory() const;
- /** Integers (not floats), Enum, String, FixedString.
- */
- virtual bool is_categorial() const { return false; }
-
virtual bool is_nullable() const { return false; }
/** Is this type can represent only NULL value? (It also implies
is_nullable)
@@ -314,10 +285,6 @@ struct WhichDataType {
bool is_float64() const { return idx == TypeIndex::Float64; }
bool is_float() const { return is_float32() || is_float64(); }
- bool is_enum8() const { return idx == TypeIndex::Enum8; }
- bool is_enum16() const { return idx == TypeIndex::Enum16; }
- bool is_enum() const { return is_enum8() || is_enum16(); }
-
bool is_date() const { return idx == TypeIndex::Date; }
bool is_date_time() const { return idx == TypeIndex::DateTime; }
bool is_date_v2() const { return idx == TypeIndex::DateV2; }
@@ -331,13 +298,11 @@ struct WhichDataType {
bool is_json() const { return idx == TypeIndex::JSONB; }
- bool is_uuid() const { return idx == TypeIndex::UUID; }
bool is_array() const { return idx == TypeIndex::Array; }
bool is_tuple() const { return idx == TypeIndex::Tuple; }
bool is_struct() const { return idx == TypeIndex::Struct; }
bool is_map() const { return idx == TypeIndex::Map; }
bool is_set() const { return idx == TypeIndex::Set; }
- bool is_interval() const { return idx == TypeIndex::Interval; }
bool is_nothing() const { return idx == TypeIndex::Nothing; }
bool is_nullable() const { return idx == TypeIndex::Nullable; }
@@ -364,9 +329,6 @@ inline bool is_date_or_datetime(const DataTypePtr&
data_type) {
inline bool is_date_v2_or_datetime_v2(const DataTypePtr& data_type) {
return WhichDataType(data_type).is_date_v2_or_datetime_v2();
}
-inline bool is_enum(const DataTypePtr& data_type) {
- return WhichDataType(data_type).is_enum();
-}
inline bool is_decimal(const DataTypePtr& data_type) {
return WhichDataType(data_type).is_decimal();
}
@@ -424,7 +386,7 @@ template <typename T>
bool is_columned_as_number(const T& data_type) {
WhichDataType which(data_type);
return which.is_int() || which.is_uint() || which.is_float() ||
which.is_date_or_datetime() ||
- which.is_uuid() || which.is_date_v2_or_datetime_v2();
+ which.is_date_v2_or_datetime_v2();
}
template <typename T>
diff --git a/be/src/vec/data_types/data_type_array.h
b/be/src/vec/data_types/data_type_array.h
index c33d976b53..a96ab2cdaa 100644
--- a/be/src/vec/data_types/data_type_array.h
+++ b/be/src/vec/data_types/data_type_array.h
@@ -82,23 +82,15 @@ public:
bool get_is_parametric() const override { return true; }
bool have_subtypes() const override { return true; }
- bool cannot_be_stored_in_tables() const override {
- return nested->cannot_be_stored_in_tables();
- }
bool text_can_contain_only_valid_utf8() const override {
return nested->text_can_contain_only_valid_utf8();
}
bool is_comparable() const override { return nested->is_comparable(); }
- bool can_be_compared_with_collation() const override {
- return nested->can_be_compared_with_collation();
- }
bool is_value_unambiguously_represented_in_contiguous_memory_region()
const override {
return
nested->is_value_unambiguously_represented_in_contiguous_memory_region();
}
- //SerializationPtr doGetDefaultSerialization() const override;
-
const DataTypePtr& get_nested_type() const { return nested; }
/// 1 for plain array, 2 for array of arrays and so on.
diff --git a/be/src/vec/data_types/data_type_bitmap.h
b/be/src/vec/data_types/data_type_bitmap.h
index b3197b946b..2579a68378 100644
--- a/be/src/vec/data_types/data_type_bitmap.h
+++ b/be/src/vec/data_types/data_type_bitmap.h
@@ -83,14 +83,10 @@ public:
}
bool have_maximum_size_of_value() const override { return false; }
- bool can_be_used_as_version() const override { return false; }
-
bool can_be_inside_nullable() const override { return true; }
bool equals(const IDataType& rhs) const override { return typeid(rhs) ==
typeid(*this); }
- bool is_categorial() const override { return
is_value_represented_by_integer(); }
-
bool can_be_inside_low_cardinality() const override { return false; }
std::string to_string(const IColumn& column, size_t row_num) const
override {
diff --git a/be/src/vec/data_types/data_type_date.h
b/be/src/vec/data_types/data_type_date.h
index dadab0dc8a..cbf0379658 100644
--- a/be/src/vec/data_types/data_type_date.h
+++ b/be/src/vec/data_types/data_type_date.h
@@ -54,7 +54,6 @@ public:
const char* get_family_name() const override { return "DateTime"; }
std::string do_get_name() const override { return "Date"; }
- bool can_be_used_as_version() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
bool equals(const IDataType& rhs) const override;
diff --git a/be/src/vec/data_types/data_type_date_time.h
b/be/src/vec/data_types/data_type_date_time.h
index cc280c9751..2e63bc99b7 100644
--- a/be/src/vec/data_types/data_type_date_time.h
+++ b/be/src/vec/data_types/data_type_date_time.h
@@ -78,7 +78,6 @@ public:
return TPrimitiveType::DATETIME;
}
- bool can_be_used_as_version() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
bool equals(const IDataType& rhs) const override;
diff --git a/be/src/vec/data_types/data_type_decimal.cpp
b/be/src/vec/data_types/data_type_decimal.cpp
index a588c1d0ae..c3bafba8aa 100644
--- a/be/src/vec/data_types/data_type_decimal.cpp
+++ b/be/src/vec/data_types/data_type_decimal.cpp
@@ -142,14 +142,6 @@ template <typename T>
Field DataTypeDecimal<T>::get_default() const {
return DecimalField(T(0), scale);
}
-
-template <typename T>
-DataTypePtr DataTypeDecimal<T>::promote_numeric_type() const {
- using PromotedType = std::conditional_t<IsDecimalV2<T>,
DataTypeDecimal<Decimal128>,
- DataTypeDecimal<Decimal128I>>;
- return std::make_shared<PromotedType>(PromotedType::max_precision(),
scale);
-}
-
template <typename T>
MutableColumnPtr DataTypeDecimal<T>::create_column() const {
if constexpr (IsDecimalV2<T>) {
diff --git a/be/src/vec/data_types/data_type_decimal.h
b/be/src/vec/data_types/data_type_decimal.h
index 30be57fbe3..43a9718651 100644
--- a/be/src/vec/data_types/data_type_decimal.h
+++ b/be/src/vec/data_types/data_type_decimal.h
@@ -232,8 +232,6 @@ public:
return DecimalField<T>(val, scale);
}
- bool can_be_promoted() const override { return true; }
- DataTypePtr promote_numeric_type() const override;
MutableColumnPtr create_column() const override;
bool equals(const IDataType& rhs) const override;
diff --git a/be/src/vec/data_types/data_type_fixed_length_object.h
b/be/src/vec/data_types/data_type_fixed_length_object.h
index f81d1dc6fa..286e7d9732 100644
--- a/be/src/vec/data_types/data_type_fixed_length_object.h
+++ b/be/src/vec/data_types/data_type_fixed_length_object.h
@@ -80,7 +80,6 @@ public:
bool get_is_parametric() const override { return false; }
bool have_subtypes() const override { return false; }
- bool is_categorial() const override { return
is_value_represented_by_integer(); }
bool can_be_inside_low_cardinality() const override { return false; }
DataTypeSerDeSPtr get_serde() const override {
return std::make_shared<DataTypeFixedLengthObjectSerDe>();
diff --git a/be/src/vec/data_types/data_type_hll.h
b/be/src/vec/data_types/data_type_hll.h
index 769d5a8036..75170242ec 100644
--- a/be/src/vec/data_types/data_type_hll.h
+++ b/be/src/vec/data_types/data_type_hll.h
@@ -81,14 +81,10 @@ public:
}
bool have_maximum_size_of_value() const override { return false; }
- bool can_be_used_as_version() const override { return false; }
-
bool can_be_inside_nullable() const override { return true; }
bool equals(const IDataType& rhs) const override { return typeid(rhs) ==
typeid(*this); }
- bool is_categorial() const override { return
is_value_represented_by_integer(); }
-
bool can_be_inside_low_cardinality() const override { return false; }
std::string to_string(const IColumn& column, size_t row_num) const
override { return "HLL()"; }
diff --git a/be/src/vec/data_types/data_type_jsonb.h
b/be/src/vec/data_types/data_type_jsonb.h
index 9cfa33f99d..03b9ca045f 100644
--- a/be/src/vec/data_types/data_type_jsonb.h
+++ b/be/src/vec/data_types/data_type_jsonb.h
@@ -83,11 +83,9 @@ public:
bool get_is_parametric() const override { return false; }
bool have_subtypes() const override { return false; }
bool is_comparable() const override { return false; }
- bool can_be_compared_with_collation() const override { return false; }
bool is_value_unambiguously_represented_in_contiguous_memory_region()
const override {
return true;
}
- bool is_categorial() const override { return false; }
bool can_be_inside_nullable() const override { return true; }
bool can_be_inside_low_cardinality() const override { return true; }
std::string to_string(const IColumn& column, size_t row_num) const
override;
diff --git a/be/src/vec/data_types/data_type_map.cpp
b/be/src/vec/data_types/data_type_map.cpp
index 0752ad813e..349236e3b5 100644
--- a/be/src/vec/data_types/data_type_map.cpp
+++ b/be/src/vec/data_types/data_type_map.cpp
@@ -27,6 +27,7 @@
#include "vec/columns/column.h"
#include "vec/columns/column_array.h"
+#include "vec/columns/column_const.h"
#include "vec/columns/column_map.h"
#include "vec/columns/column_nullable.h"
#include "vec/common/assert_cast.h"
@@ -53,7 +54,11 @@ Field DataTypeMap::get_default() const {
};
std::string DataTypeMap::to_string(const IColumn& column, size_t row_num)
const {
- const ColumnMap& map_column = assert_cast<const ColumnMap&>(column);
+ auto result = check_column_const_set_readability(column, row_num);
+ ColumnPtr ptr = result.first;
+ row_num = result.second;
+
+ const ColumnMap& map_column = assert_cast<const ColumnMap&>(*ptr);
const ColumnArray::Offsets64& offsets = map_column.get_offsets();
size_t offset = offsets[row_num - 1];
diff --git a/be/src/vec/data_types/data_type_map.h
b/be/src/vec/data_types/data_type_map.h
index 017c5a184c..f497ee821e 100644
--- a/be/src/vec/data_types/data_type_map.h
+++ b/be/src/vec/data_types/data_type_map.h
@@ -82,7 +82,6 @@ public:
bool is_comparable() const override {
return key_type->is_comparable() && value_type->is_comparable();
}
- bool can_be_compared_with_collation() const override { return false; }
bool is_value_unambiguously_represented_in_contiguous_memory_region()
const override {
return true;
}
diff --git a/be/src/vec/data_types/data_type_nothing.h
b/be/src/vec/data_types/data_type_nothing.h
index 039e4d5b30..2b311ac5fb 100644
--- a/be/src/vec/data_types/data_type_nothing.h
+++ b/be/src/vec/data_types/data_type_nothing.h
@@ -88,7 +88,6 @@ public:
}
bool have_subtypes() const override { return false; }
- bool cannot_be_stored_in_tables() const override { return true; }
DataTypeSerDeSPtr get_serde() const override {
LOG(FATAL) << get_name() << " not support serde";
};
diff --git a/be/src/vec/data_types/data_type_nullable.h
b/be/src/vec/data_types/data_type_nullable.h
index 734b31588b..0f7b55976a 100644
--- a/be/src/vec/data_types/data_type_nullable.h
+++ b/be/src/vec/data_types/data_type_nullable.h
@@ -91,9 +91,6 @@ public:
bool get_is_parametric() const override { return true; }
bool have_subtypes() const override { return true; }
- bool cannot_be_stored_in_tables() const override {
- return nested_data_type->cannot_be_stored_in_tables();
- }
bool should_align_right_in_pretty_formats() const override {
return nested_data_type->should_align_right_in_pretty_formats();
}
@@ -101,10 +98,6 @@ public:
return nested_data_type->text_can_contain_only_valid_utf8();
}
bool is_comparable() const override { return
nested_data_type->is_comparable(); }
- bool can_be_compared_with_collation() const override {
- return nested_data_type->can_be_compared_with_collation();
- }
- bool can_be_used_as_version() const override { return false; }
bool is_summable() const override { return
nested_data_type->is_summable(); }
bool can_be_used_in_boolean_context() const override {
return nested_data_type->can_be_used_in_boolean_context();
diff --git a/be/src/vec/data_types/data_type_number.h
b/be/src/vec/data_types/data_type_number.h
index fa3dd55459..09a0d1da5b 100644
--- a/be/src/vec/data_types/data_type_number.h
+++ b/be/src/vec/data_types/data_type_number.h
@@ -31,17 +31,10 @@ template <typename T>
class DataTypeNumber final : public DataTypeNumberBase<T> {
bool equals(const IDataType& rhs) const override { return typeid(rhs) ==
typeid(*this); }
- bool can_be_used_as_version() const override { return true; }
bool is_summable() const override { return true; }
bool can_be_used_in_bit_operations() const override { return true; }
bool can_be_used_in_boolean_context() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
-
- bool can_be_promoted() const override { return true; }
- DataTypePtr promote_numeric_type() const override {
- using PromotedType = DataTypeNumber<NearestFieldType<T>>;
- return std::make_shared<PromotedType>();
- }
};
using DataTypeUInt8 = DataTypeNumber<UInt8>;
diff --git a/be/src/vec/data_types/data_type_number_base.h
b/be/src/vec/data_types/data_type_number_base.h
index 14780542ba..2f8260c0bb 100644
--- a/be/src/vec/data_types/data_type_number_base.h
+++ b/be/src/vec/data_types/data_type_number_base.h
@@ -137,7 +137,6 @@ public:
}
bool have_maximum_size_of_value() const override { return true; }
size_t get_size_of_value_in_memory() const override { return sizeof(T); }
- bool is_categorial() const override { return
is_value_represented_by_integer(); }
bool can_be_inside_low_cardinality() const override { return true; }
void to_string(const IColumn& column, size_t row_num, BufferWritable&
ostr) const override;
diff --git a/be/src/vec/data_types/data_type_quantilestate.h
b/be/src/vec/data_types/data_type_quantilestate.h
index 4a779c1414..e4afebfd04 100644
--- a/be/src/vec/data_types/data_type_quantilestate.h
+++ b/be/src/vec/data_types/data_type_quantilestate.h
@@ -82,14 +82,10 @@ public:
}
bool have_maximum_size_of_value() const override { return false; }
- bool can_be_used_as_version() const override { return false; }
-
bool can_be_inside_nullable() const override { return true; }
bool equals(const IDataType& rhs) const override { return typeid(rhs) ==
typeid(*this); }
- bool is_categorial() const override { return
is_value_represented_by_integer(); }
-
bool can_be_inside_low_cardinality() const override { return false; }
std::string to_string(const IColumn& column, size_t row_num) const
override {
diff --git a/be/src/vec/data_types/data_type_string.h
b/be/src/vec/data_types/data_type_string.h
index 301b85bf11..9a867a7b8a 100644
--- a/be/src/vec/data_types/data_type_string.h
+++ b/be/src/vec/data_types/data_type_string.h
@@ -81,11 +81,9 @@ public:
bool get_is_parametric() const override { return false; }
bool have_subtypes() const override { return false; }
bool is_comparable() const override { return true; }
- bool can_be_compared_with_collation() const override { return true; }
bool is_value_unambiguously_represented_in_contiguous_memory_region()
const override {
return true;
}
- bool is_categorial() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
bool can_be_inside_low_cardinality() const override { return true; }
std::string to_string(const IColumn& column, size_t row_num) const
override;
diff --git a/be/src/vec/data_types/data_type_time.h
b/be/src/vec/data_types/data_type_time.h
index 17e4ebeb5e..0bc1b1aad8 100644
--- a/be/src/vec/data_types/data_type_time.h
+++ b/be/src/vec/data_types/data_type_time.h
@@ -62,17 +62,11 @@ public:
MutableColumnPtr create_column() const override;
- bool can_be_used_as_version() const override { return true; }
bool is_summable() const override { return true; }
bool can_be_used_in_bit_operations() const override { return true; }
bool can_be_used_in_boolean_context() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
- bool can_be_promoted() const override { return true; }
- DataTypePtr promote_numeric_type() const override {
- using PromotedType = DataTypeNumber<NearestFieldType<Float64>>;
- return std::make_shared<PromotedType>();
- }
DataTypeSerDeSPtr get_serde() const override { return
std::make_shared<DataTypeTimeSerDe>(); };
TypeIndex get_type_id() const override { return TypeIndex::Time; }
};
diff --git a/be/src/vec/data_types/data_type_time_v2.h
b/be/src/vec/data_types/data_type_time_v2.h
index ca7efef2ea..ebe5754bd1 100644
--- a/be/src/vec/data_types/data_type_time_v2.h
+++ b/be/src/vec/data_types/data_type_time_v2.h
@@ -65,7 +65,6 @@ public:
const char* get_family_name() const override { return "DateV2"; }
std::string do_get_name() const override { return "DateV2"; }
- bool can_be_used_as_version() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
DataTypeSerDeSPtr get_serde() const override { return
std::make_shared<DataTypeDateV2SerDe>(); }
@@ -118,7 +117,6 @@ public:
const char* get_family_name() const override { return "DateTimeV2"; }
std::string do_get_name() const override { return "DateTimeV2"; }
- bool can_be_used_as_version() const override { return true; }
bool can_be_inside_nullable() const override { return true; }
bool equals(const IDataType& rhs) const override;
diff --git a/be/test/CMakeLists.txt b/be/test/CMakeLists.txt
index d747a990f2..44e9e5164d 100644
--- a/be/test/CMakeLists.txt
+++ b/be/test/CMakeLists.txt
@@ -229,6 +229,7 @@ set(VEC_TEST_FILES
vec/columns/column_decimal_test.cpp
vec/columns/column_fixed_length_object_test.cpp
vec/data_types/complex_type_test.cpp
+ vec/data_types/serde/data_type_to_string_test.cpp
vec/data_types/serde/data_type_serde_pb_test.cpp
vec/data_types/serde/data_type_serde_arrow_test.cpp
vec/data_types/serde/data_type_serde_mysql_test.cpp
diff --git a/be/test/vec/data_types/serde/data_type_to_string_test.cpp
b/be/test/vec/data_types/serde/data_type_to_string_test.cpp
new file mode 100644
index 0000000000..fe2e05d10a
--- /dev/null
+++ b/be/test/vec/data_types/serde/data_type_to_string_test.cpp
@@ -0,0 +1,115 @@
+// 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 <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#include "vec/columns/column_const.h"
+#include "vec/core/field.h"
+#include "vec/data_types/data_type_array.h"
+#include "vec/data_types/data_type_factory.hpp"
+#include "vec/data_types/data_type_map.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/data_types/data_type_struct.h"
+
+namespace doris::vectorized {
+
+struct DataTypeTestCases {
+ FieldVector field_values;
+ std::vector<String> expect_values;
+};
+
+TEST(ToStringMethodTest, DataTypeToStringTest) {
+ // prepare field
+ DataTypeTestCases cases;
+ DataTypes data_types;
+ std::vector<TypeIndex> type_ids = {TypeIndex::Int16, TypeIndex::String,
TypeIndex::Decimal32};
+ Array a1, a2;
+ a1.push_back(UInt64(123));
+ a1.push_back(Null());
+ a1.push_back(UInt64(12345678));
+ a1.push_back(UInt64(0));
+ a2.push_back(String("hello amory"));
+ a2.push_back("NULL");
+ a2.push_back(String("cute amory"));
+ a2.push_back(Null());
+ Map m;
+ m.push_back(a1);
+ m.push_back(a2);
+
+ Tuple t;
+ t.push_back(Int128(12345454342));
+ t.push_back(String("amory cute"));
+ t.push_back(UInt64(0));
+
+ cases.field_values = {UInt64(12),
+ String(" hello amory , cute amory "),
+ DecimalField<Decimal32>(-12345678, 0),
+ a1,
+ a2,
+ t,
+ m};
+ cases.expect_values = {"12",
+ " hello amory , cute amory ",
+ "-12345678",
+ "[123, NULL, 12345678, 0]",
+ "['hello amory', 'NULL', 'cute amory', 'NULL']",
+ "{12345454342, amory cute, 0}",
+ "{123:\"hello amory\", null:\"NULL\",
12345678:\"cute amory\", 0:null}"};
+
+ for (const auto id : type_ids) {
+ const auto data_type =
DataTypeFactory::instance().create_data_type(id);
+ data_types.push_back(data_type);
+ }
+
+ // complex type
+ DataTypePtr n1 =
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt32>());
+ DataTypePtr n3 =
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt128>());
+ DataTypePtr s1 =
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>());
+ DataTypePtr u1 =
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>());
+
+ DataTypePtr a = std::make_shared<DataTypeArray>(u1);
+ data_types.push_back(a);
+ DataTypePtr au = std::make_shared<DataTypeArray>(s1);
+ data_types.push_back(au);
+ DataTypes dataTypes;
+ dataTypes.push_back(n3);
+ dataTypes.push_back(s1);
+ dataTypes.push_back(u1);
+
+ // data_type_struct
+ DataTypePtr s = std::make_shared<DataTypeStruct>(dataTypes);
+ data_types.push_back(s);
+
+ DataTypePtr mt = std::make_shared<DataTypeMap>(u1, s1);
+ data_types.push_back(mt);
+
+ for (int i = 0; i < data_types.size(); ++i) {
+ DataTypePtr data_type = data_types[i];
+ std::cout << i << " : " << data_type->get_name() << std::endl;
+ const auto field = cases.field_values[i];
+ ColumnPtr col = data_type->create_column_const(1, field);
+ std::cout << "col name:" << col->get_name() << std::endl;
+ std::string to = data_type->to_string(*col, 1);
+ std::string expect = cases.expect_values[i];
+ // std::cout << "expect: " << expect << " to : " << to <<
std::endl;
+ ASSERT_EQ(cases.expect_values[i], to);
+ }
+}
+} // namespace doris::vectorized
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]