Coverage Report

Created: 2025-10-01 20:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/runtime/raw_value.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/apache/impala/blob/branch-2.9.0/be/src/runtime/raw-value.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <string>
24
25
#include "common/consts.h"
26
#include "common/logging.h"
27
#include "runtime/define_primitive_type.h"
28
#include "runtime/types.h"
29
#include "util/hash_util.hpp"
30
#include "util/types.h"
31
#include "vec/common/string_ref.h"
32
33
namespace doris {
34
#include "common/compile_check_begin.h"
35
class SlotDescriptor;
36
37
// Useful utility functions for runtime values (which are passed around as void*).
38
class RawValue {
39
public:
40
    // Same as the up function, only use in vec exec engine.
41
    static uint32_t zlib_crc32(const void* value, size_t len, const PrimitiveType& type,
42
                               uint32_t seed);
43
};
44
45
// NOTE: this is just for split data, decimal use old doris hash function
46
// Because crc32 hardware is not equal with zlib crc32
47
inline uint32_t RawValue::zlib_crc32(const void* v, size_t len, const PrimitiveType& type,
48
10
                                     uint32_t seed) {
49
    // Hash_combine with v = 0
50
10
    if (v == nullptr) {
51
0
        uint32_t value = 0x9e3779b9;
52
0
        return seed ^ (value + (seed << 6) + (seed >> 2));
53
0
    }
54
55
10
    switch (type) {
56
0
    case TYPE_VARCHAR:
57
0
    case TYPE_HLL:
58
0
    case TYPE_STRING:
59
0
    case TYPE_CHAR: {
60
0
        return HashUtil::zlib_crc_hash(v, (uint32_t)len, seed);
61
0
    }
62
63
0
    case TYPE_BOOLEAN:
64
0
    case TYPE_TINYINT:
65
0
        return HashUtil::zlib_crc_hash(v, 1, seed);
66
0
    case TYPE_SMALLINT:
67
0
        return HashUtil::zlib_crc_hash(v, 2, seed);
68
0
    case TYPE_INT:
69
0
        return HashUtil::zlib_crc_hash(v, 4, seed);
70
0
    case TYPE_BIGINT:
71
0
        return HashUtil::zlib_crc_hash(v, 8, seed);
72
0
    case TYPE_LARGEINT:
73
0
        return HashUtil::zlib_crc_hash(v, 16, seed);
74
0
    case TYPE_FLOAT:
75
0
        return HashUtil::zlib_crc_hash(v, 4, seed);
76
0
    case TYPE_DOUBLE:
77
0
        return HashUtil::zlib_crc_hash(v, 8, seed);
78
0
    case TYPE_DATE:
79
0
    case TYPE_DATETIME: {
80
0
        auto* date_val = (const VecDateTimeValue*)v;
81
0
        char buf[64];
82
0
        int date_len = date_val->to_buffer(buf);
83
0
        return HashUtil::zlib_crc_hash(buf, date_len, seed);
84
0
    }
85
86
0
    case TYPE_DATEV2: {
87
0
        return HashUtil::zlib_crc_hash(v, 4, seed);
88
0
    }
89
90
0
    case TYPE_DATETIMEV2: {
91
0
        return HashUtil::zlib_crc_hash(v, 8, seed);
92
0
    }
93
94
0
    case TYPE_DECIMALV2: {
95
0
        const DecimalV2Value* dec_val = (const DecimalV2Value*)v;
96
0
        int64_t int_val = dec_val->int_value();
97
0
        int32_t frac_val = dec_val->frac_value();
98
0
        seed = HashUtil::zlib_crc_hash(&int_val, sizeof(int_val), seed);
99
0
        return HashUtil::zlib_crc_hash(&frac_val, sizeof(frac_val), seed);
100
0
    }
101
0
    case TYPE_DECIMAL32:
102
0
        return HashUtil::zlib_crc_hash(v, 4, seed);
103
0
    case TYPE_DECIMAL64:
104
0
        return HashUtil::zlib_crc_hash(v, 8, seed);
105
0
    case TYPE_DECIMAL128I:
106
0
        return HashUtil::zlib_crc_hash(v, 16, seed);
107
4
    case TYPE_DECIMAL256:
108
4
        return HashUtil::zlib_crc_hash(v, 32, seed);
109
3
    case TYPE_IPV4:
110
3
        return HashUtil::zlib_crc_hash(v, 4, seed);
111
3
    case TYPE_IPV6:
112
3
        return HashUtil::zlib_crc_hash(v, 16, seed);
113
0
    default:
114
0
        DCHECK(false) << "invalid type: " << type;
115
0
        return 0;
116
10
    }
117
10
}
118
#include "common/compile_check_end.h"
119
} // namespace doris