AshinGau commented on code in PR #25138:
URL: https://github.com/apache/doris/pull/25138#discussion_r1365036251


##########
be/src/vec/exec/format/parquet/parquet_column_convert.h:
##########
@@ -0,0 +1,623 @@
+// 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 <gen_cpp/PlanNodes_types.h>
+#include <gen_cpp/Types_types.h>
+#include <gen_cpp/parquet_types.h>
+
+#include <algorithm>
+#include <functional>
+#include <ostream>
+#include <utility>
+
+#include "common/compiler_util.h" // IWYU pragma: keep
+#include "common/status.h"
+#include "gen_cpp/descriptors.pb.h"
+#include "gutil/endian.h"
+#include "io/file_factory.h"
+#include "olap/olap_common.h"
+#include "util/coding.h"
+#include "util/slice.h"
+#include "vec/columns/column_string.h"
+#include "vec/columns/column_vector.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type.h"
+#include "vec/data_types/data_type_factory.hpp"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/data_types/data_type_string.h"
+#include "vec/exec/format/format_common.h"
+#include "vec/exec/format/parquet/decoder.h"
+#include "vec/exec/format/parquet/parquet_common.h"
+namespace doris::vectorized {
+
+namespace ParquetConvert {
+
+template <tparquet::Type::type ParquetType>
+struct PhysicalTypeTraits {};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::INT32> {
+    using DataType = int32_t;
+    using ColumnType = ColumnVector<DataType>;
+};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::INT64> {
+    using DataType = int64_t;
+    using ColumnType = ColumnVector<DataType>;
+};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::FLOAT> {
+    using DataType = float;
+    using ColumnType = ColumnVector<DataType>;
+};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::DOUBLE> {
+    using DataType = double;
+    using ColumnType = ColumnVector<DataType>;
+};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::BYTE_ARRAY> {
+    using DataType = String;
+    using ColumnType = ColumnString;
+};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::FIXED_LEN_BYTE_ARRAY> {
+    using DataType = String;
+    using ColumnType = ColumnString;
+};
+
+template <>
+struct PhysicalTypeTraits<tparquet::Type::INT96> {
+    using DataType = Int128;
+    using ColumnType = ColumnVector<DataType>;
+};
+
+#define FOR_LOGICAL_NUMERIC_TYPES(M)        \
+    M(TypeIndex::Int8, Int8, Int32)         \
+    M(TypeIndex::UInt8, UInt8, Int32)       \
+    M(TypeIndex::Int16, Int16, Int32)       \
+    M(TypeIndex::UInt16, UInt16, Int32)     \
+    M(TypeIndex::Int32, Int32, Int32)       \
+    M(TypeIndex::UInt32, UInt32, Int32)     \
+    M(TypeIndex::Int64, Int64, Int64)       \
+    M(TypeIndex::UInt64, UInt64, Int64)     \
+    M(TypeIndex::Float32, Float32, Float32) \
+    M(TypeIndex::Float64, Float64, Float64)
+
+#define FOR_LOGICAL_DECIMAL_TYPES(M)             \
+    M(TypeIndex::Decimal32, Decimal32, Int32)    \
+    M(TypeIndex::Decimal64, Decimal64, Int64)    \
+    M(TypeIndex::Decimal128, Decimal128, Int128) \
+    M(TypeIndex::Decimal128I, Decimal128, Int128)
+
+struct ConvertParams {
+    // schema.logicalType.TIMESTAMP.isAdjustedToUTC == false
+    static const cctz::time_zone utc0;
+    // schema.logicalType.TIMESTAMP.isAdjustedToUTC == true, we should set the 
time zone
+    cctz::time_zone* ctz = nullptr;
+    size_t offset_days = 0;
+    int64_t second_mask = 1;
+    int64_t scale_to_nano_factor = 1;
+    DecimalScaleParams decimal_scale;
+    FieldSchema* field_schema = nullptr;
+    size_t start_idx = 0;
+
+    void init(FieldSchema* field_schema_, cctz::time_zone* ctz_) {
+        field_schema = field_schema_;
+        if (ctz_ != nullptr) {
+            ctz = ctz_;
+        }
+        const auto& schema = field_schema->parquet_schema;
+        if (schema.__isset.logicalType && 
schema.logicalType.__isset.TIMESTAMP) {
+            const auto& timestamp_info = schema.logicalType.TIMESTAMP;
+            if (!timestamp_info.isAdjustedToUTC) {
+                // should set timezone to utc+0
+                ctz = const_cast<cctz::time_zone*>(&utc0);
+            }
+            const auto& time_unit = timestamp_info.unit;
+            if (time_unit.__isset.MILLIS) {
+                second_mask = 1000;
+                scale_to_nano_factor = 1000000;
+            } else if (time_unit.__isset.MICROS) {
+                second_mask = 1000000;
+                scale_to_nano_factor = 1000;
+            } else if (time_unit.__isset.NANOS) {
+                second_mask = 1000000000;
+                scale_to_nano_factor = 1;
+            }
+        } else if (schema.__isset.converted_type) {
+            const auto& converted_type = schema.converted_type;
+            if (converted_type == tparquet::ConvertedType::TIMESTAMP_MILLIS) {
+                second_mask = 1000;
+                scale_to_nano_factor = 1000000;
+            } else if (converted_type == 
tparquet::ConvertedType::TIMESTAMP_MICROS) {
+                second_mask = 1000000;
+                scale_to_nano_factor = 1000;
+            }
+        }
+
+        if (ctz) {
+            VecDateTimeValue t;
+            t.from_unixtime(0, *ctz);
+            offset_days = t.day() == 31 ? 0 : 1;
+        }
+    }
+
+    template <typename DecimalPrimitiveType>
+    void init_decimal_converter(DataTypePtr& data_type) {
+        if (field_schema == nullptr || decimal_scale.scale_type != 
DecimalScaleParams::NOT_INIT) {
+            return;
+        }
+        auto scale = field_schema->parquet_schema.scale;
+        auto* decimal_type = 
static_cast<DataTypeDecimal<Decimal<DecimalPrimitiveType>>*>(
+                const_cast<IDataType*>(remove_nullable(data_type).get()));
+        auto dest_scale = decimal_type->get_scale();
+        if (dest_scale > scale) {
+            decimal_scale.scale_type = DecimalScaleParams::SCALE_UP;
+            decimal_scale.scale_factor =
+                    
DecimalScaleParams::get_scale_factor<DecimalPrimitiveType>(dest_scale - scale);
+        } else if (dest_scale < scale) {
+            decimal_scale.scale_type = DecimalScaleParams::SCALE_DOWN;
+            decimal_scale.scale_factor =
+                    
DecimalScaleParams::get_scale_factor<DecimalPrimitiveType>(scale - dest_scale);
+        } else {
+            decimal_scale.scale_type = DecimalScaleParams::NO_SCALE;
+            decimal_scale.scale_factor = 1;
+        }
+    }
+};
+
+Status convert_data_type_from_parquet(tparquet::Type::type parquet_type, 
PrimitiveType,
+                                      vectorized::DataTypePtr& ans_data_type, 
DataTypePtr& src_type,
+                                      bool* need_convert);
+
+struct ColumnConvert {
+    virtual Status convert(const IColumn* src_col, IColumn* dst_col) { return 
Status::OK(); }
+
+    virtual ~ColumnConvert() = default;
+
+    void convert_null(const IColumn** src_col, IColumn** dst_col) const {

Review Comment:
   Why use double `**`(pointer of pointer)? We'd better use `IColumn& col` as 
the parameter, or `MutableColumnPtr& col` to stand the column to be altered.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to