eldenmoon commented on code in PR #65561: URL: https://github.com/apache/doris/pull/65561#discussion_r3654136951
########## be/src/core/value/variant/variant_metadata_builder.cpp: ########## @@ -0,0 +1,294 @@ +// 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 <parallel_hashmap/phmap.h> + +#include <algorithm> +#include <cstdint> +#include <deque> +#include <functional> +#include <limits> +#include <ranges> +#include <utility> + +#include "common/exception.h" +#include "core/value/variant/variant_block_builder.h" +#include "core/value/variant/variant_encoded_block.h" +#include "core/value/variant/variant_encoding.h" +#include "core/value/variant/variant_tracked_storage.h" +#include "util/utf8_check.h" + +namespace doris { +namespace { + +constexpr uint32_t INVALID_INDEX = std::numeric_limits<uint32_t>::max(); + +uint8_t minimum_unsigned_width(uint64_t value) { + if (value <= std::numeric_limits<uint8_t>::max()) { + return 1; + } + if (value <= std::numeric_limits<uint16_t>::max()) { + return 2; + } + if (value <= 0xFFFFFFU) { + return 3; + } + return 4; +} + +void validate_utf8_string_ref(StringRef value, const char* description) { + if (value.data == nullptr && value.size != 0) { + throw Exception(ErrorCode::INVALID_ARGUMENT, "Variant {} has a null data pointer", + description); + } + if (value.size != 0 && !validate_utf8(value.data, value.size)) { + throw Exception(ErrorCode::INVALID_ARGUMENT, "Variant {} is not valid UTF-8", description); + } +} + +template <typename String> +void append_unsigned(String& output, uint64_t value, uint8_t width) { + for (uint8_t byte = 0; byte < width; ++byte) { + output.push_back(static_cast<char>(value >> (byte * 8))); + } +} + +} // namespace + +struct VariantMetadataBuilder::Impl { + using KeyMapValue = std::pair<const StringRef, uint32_t>; Review Comment: 放到了variant_batch_builder -- 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]
