eldenmoon commented on code in PR #65561: URL: https://github.com/apache/doris/pull/65561#discussion_r3619307380
########## be/src/core/value/variant/variant_block_builder.h: ########## @@ -0,0 +1,252 @@ +// 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 <array> +#include <cstddef> +#include <cstdint> +#include <memory> + +#include "core/string_ref.h" +#include "core/value/variant/variant_encoded_block.h" +#include "core/value/variant/variant_metadata.h" +#include "core/value/variant/variant_tracked_storage.h" +#include "core/value/variant/variant_value.h" + +namespace doris { + +class VariantScalarEncodingPlan; +class VariantCollectionCore; + +// Internal dictionary owner for one VariantBlockBuilder encoding unit. Rows collect temporary key +// ids first; seal() fixes the sorted dictionary and id remap for the completed block. +class VariantMetadataBuilder { +public: + VariantMetadataBuilder(); + ~VariantMetadataBuilder(); + + VariantMetadataBuilder(const VariantMetadataBuilder&) = delete; + VariantMetadataBuilder& operator=(const VariantMetadataBuilder&) = delete; + VariantMetadataBuilder(VariantMetadataBuilder&&) = delete; + VariantMetadataBuilder& operator=(VariantMetadataBuilder&&) = delete; + + uint32_t register_key(StringRef key); + void seal(); + + bool is_sealed() const noexcept; + size_t num_keys() const noexcept; + uint32_t final_id(uint32_t temporary_id) const; + StringRef encoded_metadata() const; + VariantMetadataRef metadata_ref() const; + +private: + friend class VariantBlockBuilder; + friend class VariantCollectionCore; + + void _begin_row(); + void _retain_key(uint32_t temporary_id) noexcept; + void _complete_row() noexcept; + void _abort_row(const uint32_t* temporary_ids, size_t count, bool was_collecting) noexcept; + void _reserve_keys(size_t count); + VariantTrackedString _take_encoded_metadata() noexcept; + StringRef _temporary_key(uint32_t temporary_id) const noexcept; + size_t _key_capacity() const noexcept; + size_t _key_capacity_growths() const noexcept; + + struct Impl; + std::unique_ptr<Impl> _impl; +}; + +// Collects a block through one stack-only active Row at a time. The implementation owns one +// metadata dictionary and one set of block-level scalar/node/container/child/row-root arenas. +// The shared scalar/node/container/child scratch for the complete encoding unit stays within its +// uint32 index/offset domain. Row and its scopes never own per-row heap containers and must not +// outlive this builder. +class VariantBlockBuilder { Review Comment: 改名成VariantBatchBuilder -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
