github-actions[bot] commented on code in PR #25138: URL: https://github.com/apache/doris/pull/25138#discussion_r1371960913
########## be/src/vec/exec/format/parquet/parquet_column_convert.h: ########## @@ -0,0 +1,665 @@ +// 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 "gutil/strings/numbers.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::BOOLEAN> { + using DataType = uint8; + 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 = ParquetInt96; + using ColumnType = ColumnVector<Int8>; +}; + +#define FOR_LOGICAL_NUMERIC_TYPES(M) \ + M(TypeIndex::Int8, Int8, Int32) \ + M(TypeIndex::Int16, Int16, Int32) \ + M(TypeIndex::Int32, Int32, Int32) \ + M(TypeIndex::Int64, Int64, 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_, size_t start_idx_ = 0) { + 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 ? -1 : 0; Review Comment: warning: 31 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp offset_days = t.day() == 31 ? -1 : 0; ^ ``` -- 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