This is an automated email from the ASF dual-hosted git repository.

zhangstar333 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 bd1afe04105 [Refactor](type) Refactor misleading type descriptor 
operator eq (#48529)
bd1afe04105 is described below

commit bd1afe041057c736bbc523f2c5d44e9c768a29cb
Author: zclllyybb <zhaochan...@selectdb.com>
AuthorDate: Mon Mar 10 12:00:59 2025 +0800

    [Refactor](type) Refactor misleading type descriptor operator eq (#48529)
    
    ### What problem does this PR solve?
    Problem Summary:
    Refactor misleading type descriptor operator eq
---
 be/src/runtime/types.h                             | 20 +++----
 .../exec/format/parquet/parquet_column_convert.cpp | 66 ++++++++++++----------
 be/src/vec/sink/vtablet_block_convertor.cpp        |  2 +-
 3 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/be/src/runtime/types.h b/be/src/runtime/types.h
index f38a0f0ed07..15568d7d8ce 100644
--- a/be/src/runtime/types.h
+++ b/be/src/runtime/types.h
@@ -169,20 +169,14 @@ struct TypeDescriptor {
         return result;
     }
 
+    template <PrimitiveType o>
+    bool is() const {
+        return this->type == o;
+    }
+
     bool operator==(const TypeDescriptor& o) const {
-        if (type != o.type) {
-            return false;
-        }
-        if (children != o.children) {
-            return false;
-        }
-        if (type == TYPE_CHAR) {
-            return len == o.len;
-        }
-        if (type == TYPE_DECIMALV2) {
-            return precision == o.precision && scale == o.scale;
-        }
-        return true;
+        return type == o.type && len == o.len && precision == o.precision && 
scale == o.scale &&
+               result_is_nullable == o.result_is_nullable && contains_nulls == 
o.contains_nulls;
     }
 
     bool operator!=(const TypeDescriptor& other) const { return !(*this == 
other); }
diff --git a/be/src/vec/exec/format/parquet/parquet_column_convert.cpp 
b/be/src/vec/exec/format/parquet/parquet_column_convert.cpp
index a48fe4960ee..04f2bad8d81 100644
--- a/be/src/vec/exec/format/parquet/parquet_column_convert.cpp
+++ b/be/src/vec/exec/format/parquet/parquet_column_convert.cpp
@@ -120,7 +120,7 @@ ColumnPtr 
PhysicalToLogicalConverter::get_physical_column(tparquet::Type::type s
         // In order to share null map between parquet converted src column and 
dst column to avoid copying. It is very tricky that will
         // call mutable function 
`doris_nullable_column->get_null_map_column_ptr()` which will set 
`_need_update_has_null = true`.
         // Because some operations such as agg will call `has_null()` to set 
`_need_update_has_null = false`.
-        auto doris_nullable_column = const_cast<ColumnNullable*>(
+        auto* doris_nullable_column = const_cast<ColumnNullable*>(
                 static_cast<const ColumnNullable*>(dst_logical_column.get()));
         return ColumnNullable::create(_cached_src_physical_column,
                                       
doris_nullable_column->get_null_map_column_ptr());
@@ -168,7 +168,8 @@ static void get_decimal_converter(FieldSchema* 
field_schema, TypeDescriptor src_
             FOR_LOGICAL_DECIMAL_TYPES(DISPATCH)
 #undef DISPATCH
         default:
-            physical_converter.reset(new 
UnsupportedConverter(src_physical_type, src_logical_type));
+            physical_converter =
+                    std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
         }
     } else if (src_physical_type == tparquet::Type::BYTE_ARRAY) {
         switch (src_logical_primitive) {
@@ -192,7 +193,8 @@ static void get_decimal_converter(FieldSchema* 
field_schema, TypeDescriptor src_
             FOR_LOGICAL_DECIMAL_TYPES(DISPATCH)
 #undef DISPATCH
         default:
-            physical_converter.reset(new 
UnsupportedConverter(src_physical_type, src_logical_type));
+            physical_converter =
+                    std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
         }
     } else if (src_physical_type == tparquet::Type::INT32 ||
                src_physical_type == tparquet::Type::INT64) {
@@ -232,10 +234,12 @@ static void get_decimal_converter(FieldSchema* 
field_schema, TypeDescriptor src_
             FOR_LOGICAL_DECIMAL_TYPES(DISPATCH)
 #undef DISPATCH
         default:
-            physical_converter.reset(new 
UnsupportedConverter(src_physical_type, src_logical_type));
+            physical_converter =
+                    std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
         }
     } else {
-        physical_converter.reset(new UnsupportedConverter(src_physical_type, 
src_logical_type));
+        physical_converter =
+                std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
     }
 }
 
@@ -254,48 +258,52 @@ std::unique_ptr<PhysicalToLogicalConverter> 
PhysicalToLogicalConverter::get_conv
     PrimitiveType src_logical_primitive = src_logical_type.type;
 
     if (field_schema->is_type_compatibility) {
-        if (src_logical_type == TYPE_SMALLINT) {
-            physical_converter.reset(new 
UnsignedIntegerConverter<TYPE_SMALLINT>());
-        } else if (src_logical_type == TYPE_INT) {
-            physical_converter.reset(new UnsignedIntegerConverter<TYPE_INT>());
-        } else if (src_logical_type == TYPE_BIGINT) {
-            physical_converter.reset(new 
UnsignedIntegerConverter<TYPE_BIGINT>());
-        } else if (src_logical_type == TYPE_LARGEINT) {
-            physical_converter.reset(new 
UnsignedIntegerConverter<TYPE_LARGEINT>());
+        if (src_logical_type.is<TYPE_SMALLINT>()) {
+            physical_converter = 
std::make_unique<UnsignedIntegerConverter<TYPE_SMALLINT>>();
+        } else if (src_logical_type.is<TYPE_INT>()) {
+            physical_converter = 
std::make_unique<UnsignedIntegerConverter<TYPE_INT>>();
+        } else if (src_logical_type.is<TYPE_BIGINT>()) {
+            physical_converter = 
std::make_unique<UnsignedIntegerConverter<TYPE_BIGINT>>();
+        } else if (src_logical_type.is<TYPE_LARGEINT>()) {
+            physical_converter = 
std::make_unique<UnsignedIntegerConverter<TYPE_LARGEINT>>();
         } else {
-            physical_converter.reset(new 
UnsupportedConverter(src_physical_type, src_logical_type));
+            physical_converter =
+                    std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
         }
     } else if (is_parquet_native_type(src_logical_primitive)) {
         if (is_string_type(src_logical_primitive) &&
             src_physical_type == tparquet::Type::FIXED_LEN_BYTE_ARRAY) {
             // for FixedSizeBinary
-            physical_converter.reset(new 
FixedSizeBinaryConverter(parquet_schema.type_length));
+            physical_converter =
+                    
std::make_unique<FixedSizeBinaryConverter>(parquet_schema.type_length);
         } else {
-            physical_converter.reset(new ConsistentPhysicalConverter());
+            physical_converter = 
std::make_unique<ConsistentPhysicalConverter>();
         }
-    } else if (src_logical_type == TYPE_TINYINT) {
-        physical_converter.reset(new 
LittleIntPhysicalConverter<TYPE_TINYINT>());
-    } else if (src_logical_type == TYPE_SMALLINT) {
-        physical_converter.reset(new 
LittleIntPhysicalConverter<TYPE_SMALLINT>);
+    } else if (src_logical_type.is<TYPE_TINYINT>()) {
+        physical_converter = 
std::make_unique<LittleIntPhysicalConverter<TYPE_TINYINT>>();
+    } else if (src_logical_type.is<TYPE_SMALLINT>()) {
+        physical_converter = 
std::make_unique<LittleIntPhysicalConverter<TYPE_SMALLINT>>();
     } else if (is_decimal_type(src_logical_primitive)) {
         get_decimal_converter(field_schema, src_logical_type, dst_logical_type,
                               convert_params.get(), physical_converter);
-    } else if (src_logical_type == TYPE_DATEV2) {
-        physical_converter.reset(new Int32ToDate());
-    } else if (src_logical_type == TYPE_DATETIMEV2) {
+    } else if (src_logical_type.is<TYPE_DATEV2>()) {
+        physical_converter = std::make_unique<Int32ToDate>();
+    } else if (src_logical_type.is<TYPE_DATETIMEV2>()) {
         if (src_physical_type == tparquet::Type::INT96) {
             // int96 only stores nanoseconds in standard parquet file
             convert_params->reset_time_scale_if_missing(9);
-            physical_converter.reset(new Int96toTimestamp());
+            physical_converter = std::make_unique<Int96toTimestamp>();
         } else if (src_physical_type == tparquet::Type::INT64) {
             convert_params->reset_time_scale_if_missing(
                     remove_nullable(dst_logical_type)->get_scale());
-            physical_converter.reset(new Int64ToTimestamp());
+            physical_converter = std::make_unique<Int64ToTimestamp>();
         } else {
-            physical_converter.reset(new 
UnsupportedConverter(src_physical_type, src_logical_type));
+            physical_converter =
+                    std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
         }
     } else {
-        physical_converter.reset(new UnsupportedConverter(src_physical_type, 
src_logical_type));
+        physical_converter =
+                std::make_unique<UnsupportedConverter>(src_physical_type, 
src_logical_type);
     }
 
     if (physical_converter->support()) {
@@ -303,9 +311,9 @@ std::unique_ptr<PhysicalToLogicalConverter> 
PhysicalToLogicalConverter::get_conv
         physical_converter->_logical_converter = 
converter::ColumnTypeConverter::get_converter(
                 src_logical_type, dst_logical_type, 
converter::FileFormat::PARQUET);
         if (!physical_converter->_logical_converter->support()) {
-            physical_converter.reset(new UnsupportedConverter(
+            physical_converter = std::make_unique<UnsupportedConverter>(
                     "Unsupported type change: " +
-                    physical_converter->_logical_converter->get_error_msg()));
+                    physical_converter->_logical_converter->get_error_msg());
         }
     }
     return physical_converter;
diff --git a/be/src/vec/sink/vtablet_block_convertor.cpp 
b/be/src/vec/sink/vtablet_block_convertor.cpp
index 466902a4f90..a9d0749e851 100644
--- a/be/src/vec/sink/vtablet_block_convertor.cpp
+++ b/be/src/vec/sink/vtablet_block_convertor.cpp
@@ -438,7 +438,7 @@ Status OlapTableBlockConvertor::_internal_validate_column(
     // Only two case:
     // 1. column is nullable but the desc is not nullable
     // 2. desc->type is BITMAP
-    if ((!is_nullable || type == TYPE_OBJECT) && column_ptr) {
+    if ((!is_nullable || type.is<TYPE_OBJECT>()) && column_ptr) {
         for (int j = 0; j < row_count; ++j) {
             auto row = rows ? (*rows)[j] : j;
             if (null_map[j] && !_filter_map[row]) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to