SteNicholas commented on code in PR #479: URL: https://github.com/apache/paimon-cpp/pull/479#discussion_r4415697319
########## test/test_data/lance/append_ltz_python_compat.db/append_ltz_python_compat/README.md: ########## @@ -0,0 +1,62 @@ +<!-- + 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. +--> Review Comment: Removed the license header from both new fixture READMEs, `append_ltz_python_compat` and `append_ltz_java_compat`, so they match the other fixture READMEs. `test_data/*` is already excluded from the RAT check. ########## src/paimon/core/utils/nested_projection_utils.h: ########## @@ -128,6 +128,15 @@ class PAIMON_EXPORT NestedProjectionUtils { const std::shared_ptr<arrow::Array>& array, const std::shared_ptr<arrow::DataType>& read_type, arrow::MemoryPool* pool); + /// Relabel a TIMESTAMP in `data` with the zone `read_type` asks for, only when both sides + /// have a zone and the same unit. A zoned value is an instant since the epoch, so only the + /// type changes. STRUCT children are matched by name and LIST/FIXED_SIZE_LIST elements are + /// followed; every other difference, a unit change included, is left as is. + /// @return `data` itself when no TIMESTAMP is relabelled, otherwise a shallow copy. + static std::shared_ptr<arrow::ArrayData> AlignTimestampTimezones( + const std::shared_ptr<arrow::ArrayData>& data, + const std::shared_ptr<arrow::DataType>& read_type); + Review Comment: Done. `AlignTimestampTimezones` now takes and returns `std::shared_ptr<arrow::Array>`, like the other methods of `NestedProjectionUtils`, and returns the input array itself when nothing is relabelled. The `ArrayData` recursion is kept as a file-local helper, and both readers now pass the array directly. ########## src/paimon/core/utils/nested_projection_utils.cpp: ########## @@ -840,4 +840,65 @@ Result<std::shared_ptr<arrow::Array>> NestedProjectionUtils::AlignArrayToReadTyp } } +std::shared_ptr<arrow::ArrayData> NestedProjectionUtils::AlignTimestampTimezones( + const std::shared_ptr<arrow::ArrayData>& data, + const std::shared_ptr<arrow::DataType>& read_type) { + const std::shared_ptr<arrow::DataType>& type = data->type; + if (type->id() == arrow::Type::TIMESTAMP && read_type->id() == arrow::Type::TIMESTAMP) { + const auto& stored = checked_cast<const arrow::TimestampType&>(*type); + const auto& wanted = checked_cast<const arrow::TimestampType&>(*read_type); + if (stored.unit() != wanted.unit() || stored.timezone().empty() || + wanted.timezone().empty() || stored.timezone() == wanted.timezone()) { + return data; + } + std::shared_ptr<arrow::ArrayData> retyped = data->Copy(); + retyped->type = arrow::timestamp(wanted.unit(), wanted.timezone()); + return retyped; + } + if (type->id() == arrow::Type::STRUCT && read_type->id() == arrow::Type::STRUCT) { + const auto& wanted_struct = checked_cast<const arrow::StructType&>(*read_type); + arrow::FieldVector fields = type->fields(); + std::shared_ptr<arrow::ArrayData> retyped; + for (int32_t i = 0; i < static_cast<int32_t>(data->child_data.size()); ++i) { + const int32_t index = wanted_struct.GetFieldIndex(fields[i]->name()); + if (index < 0) { + continue; + } + std::shared_ptr<arrow::ArrayData> child = + AlignTimestampTimezones(data->child_data[i], wanted_struct.field(index)->type()); + if (child == data->child_data[i]) { + continue; + } + if (retyped == nullptr) { + retyped = data->Copy(); + } + retyped->child_data[i] = child; + fields[i] = fields[i]->WithType(child->type); + } + if (retyped == nullptr) { + return data; + } + retyped->type = arrow::struct_(fields); + return retyped; + } + if ((type->id() == arrow::Type::LIST || type->id() == arrow::Type::FIXED_SIZE_LIST) && + type->id() == read_type->id() && !data->child_data.empty()) { + std::shared_ptr<arrow::ArrayData> values = + AlignTimestampTimezones(data->child_data[0], read_type->field(0)->type()); + if (values == data->child_data[0]) { + return data; + } + std::shared_ptr<arrow::ArrayData> retyped = data->Copy(); + retyped->child_data[0] = values; + const std::shared_ptr<arrow::Field> value_field = type->field(0)->WithType(values->type); + retyped->type = type->id() == arrow::Type::LIST + ? arrow::list(value_field) + : arrow::fixed_size_list( + value_field, + checked_cast<const arrow::FixedSizeListType&>(*type).list_size()); + return retyped; + } + return data; Review Comment: Added the MAP branch, which follows both keys and values. `AlignTimestampTimezonesRelabelsZonedLeavesOfSameUnit` now covers a `MAP<LTZ, LTZ>` child, sliced input included, and a fixed-size list child for the existing FIXED_SIZE_LIST branch. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
