HuaHuaY commented on code in PR #50252: URL: https://github.com/apache/arrow/pull/50252#discussion_r4256886077
########## cpp/src/parquet/variant/builder.h: ########## @@ -0,0 +1,331 @@ +// 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. + +#pragma once + +#include <cstdint> +#include <memory> +#include <string_view> +#include <vector> + +#include "arrow/buffer.h" +#include "arrow/extension/parquet_variant.h" +#include "arrow/memory_pool.h" +#include "arrow/type_fwd.h" +#include "parquet/platform.h" + +namespace parquet::variant { + +using ::arrow::Array; +using ::arrow::BinaryViewArray; +using ::arrow::Buffer; +using ::arrow::DataType; +using ::arrow::MemoryPool; +using ::arrow::StructArray; +using ::arrow::extension::VariantArray; + +class VariantMetadataView; +class VariantObjectBuilder; +class VariantListBuilder; +class VariantValueRowBuilder; + +struct PARQUET_EXPORT EncodedVariantValue { + std::shared_ptr<Buffer> metadata; + std::shared_ptr<Buffer> value; +}; + +class PARQUET_EXPORT VariantBuilder { + public: + explicit VariantBuilder(MemoryPool* pool = ::arrow::default_memory_pool(), + bool validate = true); + ~VariantBuilder(); + VariantBuilder(const VariantBuilder&) = delete; + VariantBuilder& operator=(const VariantBuilder&) = delete; + VariantBuilder(VariantBuilder&&) noexcept; + VariantBuilder& operator=(VariantBuilder&&) noexcept; + + void ReserveFieldNames(int64_t capacity); + uint32_t AddFieldName(std::string_view name); + + void AppendVariantNull(); Review Comment: I have decided to expose the metadata builder from `builder.cc` in the header file and pass it as an argument to `StartObject` and `StartList`, rather than maintaining the metadata construction logic internally within `VariantBuilder`. As for whether to convert the `Set*` methods into static methods, I will reconsider that later in the context of the `VariantValueRowBuilder` implementation. I also considered modifying `StartObject` and `StartList` to accept callback functions as arguments. This would eliminate the need for conventions—enforced only via comments—prohibiting modification of the external builder during construction (whereas `arrow-rs` prevents this behavior using `&mut`, C++ lacks such convenient syntax). However, this change would require the return types of `StartObject` and `StartList` to become `std::optional`, so I have decided not to implement this for now. -- 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]
