yiguolei commented on code in PR #68664: URL: https://github.com/apache/doris/pull/68664#discussion_r4228893730
########## be/src/storage/storage_layout.h: ########## @@ -0,0 +1,159 @@ +// 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 <bit> +#include <cmath> +#include <cstdint> +#include <limits> +#include <type_traits> + +#include "common/cast_set.h" +#include "core/data_type/primitive_type.h" +#include "core/data_type/storage_field_type.h" +#include "core/decimal12.h" +#include "core/uint24.h" +#include "core/value/decimalv2_value.h" +#include "core/value/vdatetime_value.h" +#include "storage/field_type.h" +#include "storage/types.h" + +namespace doris { + +// How a compute-layer value becomes what a segment stores for FieldType FT: its own +// bytes, except for the V1 DATE, DATETIME and DECIMAL layouts and NaN, stored as the +// quiet NaN. The two types are PrimitiveTypeTraits<PT>::CppType and +// CppTypeTraits<FT>::CppType; the aliases inside are private shorthand. Declared only, +// so a FieldType without a specialisation is a compile error, not a silent byte copy. +template <FieldType FT> +struct StorageLayout; + +namespace storage_layout_detail { + +// A StorageValue is the PrimitiveValue's own bytes. +template <FieldType FT> +struct BitCast { +private: + using StorageValue = typename CppTypeTraits<FT>::CppType; + using PrimitiveValue = + typename PrimitiveTypeTraits<storage_field_type_to_primitive_type(FT)>::CppType; + static_assert(sizeof(StorageValue) == sizeof(PrimitiveValue)); + +public: + static StorageValue to_storage(const PrimitiveValue& value) { + return std::bit_cast<StorageValue>(value); + } +}; + +// Every NaN is stored as the quiet NaN, so equal values have equal stored bytes +// and the bloom filter / dictionary / key encodings that hash or compare bytes +// treat all NaNs as one value. +template <FieldType FT> +struct FloatingPoint { +private: + using StorageValue = typename CppTypeTraits<FT>::CppType; + using PrimitiveValue = + typename PrimitiveTypeTraits<storage_field_type_to_primitive_type(FT)>::CppType; + static_assert(std::is_floating_point_v<StorageValue>); + static_assert(std::is_same_v<StorageValue, PrimitiveValue>); + +public: + static StorageValue canonicalize_nan(StorageValue value) { Review Comment: 怎么感觉之前我们没处理过这个quite nan 啊 -- 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]
