Coverage Report

Created: 2026-03-13 05:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/function_hash.cpp
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/ClickHouse/ClickHouse/blob/master/src/Functions/FunctionHash.cpp
19
// and modified by Doris
20
21
#include "exprs/function/function_hash.h"
22
23
#include "common/status.h"
24
#include "core/assert_cast.h"
25
#include "core/column/column.h"
26
#include "core/column/column_const.h"
27
#include "core/column/column_string.h"
28
#include "core/column/column_varbinary.h"
29
#include "core/column/column_vector.h"
30
#include "core/data_type/data_type.h"
31
#include "core/data_type/data_type_number.h"
32
#include "core/field.h"
33
#include "exec/common/template_helpers.hpp"
34
#include "exprs/function/function_helpers.h"
35
#include "exprs/function/function_variadic_arguments.h"
36
#include "exprs/function/simple_function_factory.h"
37
#include "util/hash/murmur_hash3.h"
38
#include "util/hash_util.hpp"
39
40
namespace doris {
41
#include "common/compile_check_begin.h"
42
constexpr uint64_t emtpy_value = 0xe28dbde7fe22e41c;
43
44
template <PrimitiveType ReturnType, bool is_mmh64_v2 = false>
45
struct MurmurHash3Impl {
46
    static constexpr auto get_name() {
47
        if constexpr (ReturnType == TYPE_INT) {
48
            return "murmur_hash3_32";
49
        } else if constexpr (is_mmh64_v2) {
50
            return "murmur_hash3_64_v2";
51
        } else {
52
            return "murmur_hash3_64";
53
        }
54
    }
55
    static constexpr auto name = get_name();
56
57
0
    static Status empty_apply(IColumn& icolumn, size_t input_rows_count) {
58
0
        ColumnVector<ReturnType>& vec_to = assert_cast<ColumnVector<ReturnType>&>(icolumn);
59
0
        vec_to.get_data().assign(
60
0
                input_rows_count,
61
0
                static_cast<typename PrimitiveTypeTraits<ReturnType>::CppType>(emtpy_value));
62
0
        return Status::OK();
63
0
    }
Unexecuted instantiation: _ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE5ELb0EE11empty_applyERNS_7IColumnEm
Unexecuted instantiation: _ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb0EE11empty_applyERNS_7IColumnEm
Unexecuted instantiation: _ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb1EE11empty_applyERNS_7IColumnEm
64
65
    static Status first_apply(const IDataType* type, const IColumn* column, size_t input_rows_count,
66
50
                              IColumn& icolumn) {
67
50
        return execute<true>(type, column, input_rows_count, icolumn);
68
50
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE5ELb0EE11first_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
66
23
                              IColumn& icolumn) {
67
23
        return execute<true>(type, column, input_rows_count, icolumn);
68
23
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb0EE11first_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
66
23
                              IColumn& icolumn) {
67
23
        return execute<true>(type, column, input_rows_count, icolumn);
68
23
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb1EE11first_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
66
4
                              IColumn& icolumn) {
67
4
        return execute<true>(type, column, input_rows_count, icolumn);
68
4
    }
69
70
    static Status combine_apply(const IDataType* type, const IColumn* column,
71
10
                                size_t input_rows_count, IColumn& icolumn) {
72
10
        return execute<false>(type, column, input_rows_count, icolumn);
73
10
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE5ELb0EE13combine_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
71
5
                                size_t input_rows_count, IColumn& icolumn) {
72
5
        return execute<false>(type, column, input_rows_count, icolumn);
73
5
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb0EE13combine_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
71
5
                                size_t input_rows_count, IColumn& icolumn) {
72
5
        return execute<false>(type, column, input_rows_count, icolumn);
73
5
    }
Unexecuted instantiation: _ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb1EE13combine_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
74
75
    template <bool first>
76
    static Status execute(const IDataType* type, const IColumn* column, size_t input_rows_count,
77
60
                          IColumn& col_to) {
78
60
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
79
60
        if constexpr (first) {
80
50
            if constexpr (ReturnType == TYPE_INT) {
81
23
                to_column.insert_many_vals(static_cast<Int32>(HashUtil::MURMUR3_32_SEED),
82
23
                                           input_rows_count);
83
27
            } else {
84
27
                to_column.insert_many_defaults(input_rows_count);
85
27
            }
86
50
        }
87
60
        auto& col_to_data = to_column.get_data();
88
60
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
89
60
            const typename ColumnString::Chars& data = col_from->get_chars();
90
60
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
91
60
            size_t size = offsets.size();
92
60
            ColumnString::Offset current_offset = 0;
93
202
            for (size_t i = 0; i < size; ++i) {
94
142
                if constexpr (ReturnType == TYPE_INT) {
95
68
                    col_to_data[i] = HashUtil::murmur_hash3_32(
96
68
                            reinterpret_cast<const char*>(&data[current_offset]),
97
68
                            offsets[i] - current_offset, col_to_data[i]);
98
74
                } else {
99
74
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
100
74
                            reinterpret_cast<const char*>(&data[current_offset]),
101
74
                            offsets[i] - current_offset, col_to_data[i]);
102
74
                }
103
142
                current_offset = offsets[i];
104
142
            }
105
60
        } else if (const ColumnConst* col_from_const =
106
0
                           check_and_get_column_const_string_or_fixedstring(column)) {
107
0
            auto value = col_from_const->get_value<TYPE_STRING>();
108
0
            for (size_t i = 0; i < input_rows_count; ++i) {
109
0
                if constexpr (ReturnType == TYPE_INT) {
110
0
                    col_to_data[i] =
111
0
                            HashUtil::murmur_hash3_32(value.data(), value.size(), col_to_data[i]);
112
0
                } else {
113
0
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
114
0
                            value.data(), value.size(), col_to_data[i]);
115
0
                }
116
0
            }
117
0
        } else {
118
0
            DCHECK(false);
119
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
120
0
                                        column->get_name(), name);
121
0
        }
122
60
        return Status::OK();
123
60
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE5ELb0EE7executeILb1EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
77
23
                          IColumn& col_to) {
78
23
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
79
23
        if constexpr (first) {
80
23
            if constexpr (ReturnType == TYPE_INT) {
81
23
                to_column.insert_many_vals(static_cast<Int32>(HashUtil::MURMUR3_32_SEED),
82
23
                                           input_rows_count);
83
            } else {
84
                to_column.insert_many_defaults(input_rows_count);
85
            }
86
23
        }
87
23
        auto& col_to_data = to_column.get_data();
88
23
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
89
23
            const typename ColumnString::Chars& data = col_from->get_chars();
90
23
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
91
23
            size_t size = offsets.size();
92
23
            ColumnString::Offset current_offset = 0;
93
83
            for (size_t i = 0; i < size; ++i) {
94
60
                if constexpr (ReturnType == TYPE_INT) {
95
60
                    col_to_data[i] = HashUtil::murmur_hash3_32(
96
60
                            reinterpret_cast<const char*>(&data[current_offset]),
97
60
                            offsets[i] - current_offset, col_to_data[i]);
98
                } else {
99
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
100
                            reinterpret_cast<const char*>(&data[current_offset]),
101
                            offsets[i] - current_offset, col_to_data[i]);
102
                }
103
60
                current_offset = offsets[i];
104
60
            }
105
23
        } else if (const ColumnConst* col_from_const =
106
0
                           check_and_get_column_const_string_or_fixedstring(column)) {
107
0
            auto value = col_from_const->get_value<TYPE_STRING>();
108
0
            for (size_t i = 0; i < input_rows_count; ++i) {
109
0
                if constexpr (ReturnType == TYPE_INT) {
110
0
                    col_to_data[i] =
111
0
                            HashUtil::murmur_hash3_32(value.data(), value.size(), col_to_data[i]);
112
                } else {
113
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
114
                            value.data(), value.size(), col_to_data[i]);
115
                }
116
0
            }
117
0
        } else {
118
0
            DCHECK(false);
119
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
120
0
                                        column->get_name(), name);
121
0
        }
122
23
        return Status::OK();
123
23
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE5ELb0EE7executeILb0EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
77
5
                          IColumn& col_to) {
78
5
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
79
        if constexpr (first) {
80
            if constexpr (ReturnType == TYPE_INT) {
81
                to_column.insert_many_vals(static_cast<Int32>(HashUtil::MURMUR3_32_SEED),
82
                                           input_rows_count);
83
            } else {
84
                to_column.insert_many_defaults(input_rows_count);
85
            }
86
        }
87
5
        auto& col_to_data = to_column.get_data();
88
5
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
89
5
            const typename ColumnString::Chars& data = col_from->get_chars();
90
5
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
91
5
            size_t size = offsets.size();
92
5
            ColumnString::Offset current_offset = 0;
93
13
            for (size_t i = 0; i < size; ++i) {
94
8
                if constexpr (ReturnType == TYPE_INT) {
95
8
                    col_to_data[i] = HashUtil::murmur_hash3_32(
96
8
                            reinterpret_cast<const char*>(&data[current_offset]),
97
8
                            offsets[i] - current_offset, col_to_data[i]);
98
                } else {
99
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
100
                            reinterpret_cast<const char*>(&data[current_offset]),
101
                            offsets[i] - current_offset, col_to_data[i]);
102
                }
103
8
                current_offset = offsets[i];
104
8
            }
105
5
        } else if (const ColumnConst* col_from_const =
106
0
                           check_and_get_column_const_string_or_fixedstring(column)) {
107
0
            auto value = col_from_const->get_value<TYPE_STRING>();
108
0
            for (size_t i = 0; i < input_rows_count; ++i) {
109
0
                if constexpr (ReturnType == TYPE_INT) {
110
0
                    col_to_data[i] =
111
0
                            HashUtil::murmur_hash3_32(value.data(), value.size(), col_to_data[i]);
112
                } else {
113
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
114
                            value.data(), value.size(), col_to_data[i]);
115
                }
116
0
            }
117
0
        } else {
118
0
            DCHECK(false);
119
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
120
0
                                        column->get_name(), name);
121
0
        }
122
5
        return Status::OK();
123
5
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb0EE7executeILb1EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
77
23
                          IColumn& col_to) {
78
23
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
79
23
        if constexpr (first) {
80
            if constexpr (ReturnType == TYPE_INT) {
81
                to_column.insert_many_vals(static_cast<Int32>(HashUtil::MURMUR3_32_SEED),
82
                                           input_rows_count);
83
23
            } else {
84
23
                to_column.insert_many_defaults(input_rows_count);
85
23
            }
86
23
        }
87
23
        auto& col_to_data = to_column.get_data();
88
23
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
89
23
            const typename ColumnString::Chars& data = col_from->get_chars();
90
23
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
91
23
            size_t size = offsets.size();
92
23
            ColumnString::Offset current_offset = 0;
93
83
            for (size_t i = 0; i < size; ++i) {
94
                if constexpr (ReturnType == TYPE_INT) {
95
                    col_to_data[i] = HashUtil::murmur_hash3_32(
96
                            reinterpret_cast<const char*>(&data[current_offset]),
97
                            offsets[i] - current_offset, col_to_data[i]);
98
60
                } else {
99
60
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
100
60
                            reinterpret_cast<const char*>(&data[current_offset]),
101
60
                            offsets[i] - current_offset, col_to_data[i]);
102
60
                }
103
60
                current_offset = offsets[i];
104
60
            }
105
23
        } else if (const ColumnConst* col_from_const =
106
0
                           check_and_get_column_const_string_or_fixedstring(column)) {
107
0
            auto value = col_from_const->get_value<TYPE_STRING>();
108
0
            for (size_t i = 0; i < input_rows_count; ++i) {
109
                if constexpr (ReturnType == TYPE_INT) {
110
                    col_to_data[i] =
111
                            HashUtil::murmur_hash3_32(value.data(), value.size(), col_to_data[i]);
112
0
                } else {
113
0
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
114
0
                            value.data(), value.size(), col_to_data[i]);
115
0
                }
116
0
            }
117
0
        } else {
118
0
            DCHECK(false);
119
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
120
0
                                        column->get_name(), name);
121
0
        }
122
23
        return Status::OK();
123
23
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb0EE7executeILb0EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
77
5
                          IColumn& col_to) {
78
5
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
79
        if constexpr (first) {
80
            if constexpr (ReturnType == TYPE_INT) {
81
                to_column.insert_many_vals(static_cast<Int32>(HashUtil::MURMUR3_32_SEED),
82
                                           input_rows_count);
83
            } else {
84
                to_column.insert_many_defaults(input_rows_count);
85
            }
86
        }
87
5
        auto& col_to_data = to_column.get_data();
88
5
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
89
5
            const typename ColumnString::Chars& data = col_from->get_chars();
90
5
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
91
5
            size_t size = offsets.size();
92
5
            ColumnString::Offset current_offset = 0;
93
13
            for (size_t i = 0; i < size; ++i) {
94
                if constexpr (ReturnType == TYPE_INT) {
95
                    col_to_data[i] = HashUtil::murmur_hash3_32(
96
                            reinterpret_cast<const char*>(&data[current_offset]),
97
                            offsets[i] - current_offset, col_to_data[i]);
98
8
                } else {
99
8
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
100
8
                            reinterpret_cast<const char*>(&data[current_offset]),
101
8
                            offsets[i] - current_offset, col_to_data[i]);
102
8
                }
103
8
                current_offset = offsets[i];
104
8
            }
105
5
        } else if (const ColumnConst* col_from_const =
106
0
                           check_and_get_column_const_string_or_fixedstring(column)) {
107
0
            auto value = col_from_const->get_value<TYPE_STRING>();
108
0
            for (size_t i = 0; i < input_rows_count; ++i) {
109
                if constexpr (ReturnType == TYPE_INT) {
110
                    col_to_data[i] =
111
                            HashUtil::murmur_hash3_32(value.data(), value.size(), col_to_data[i]);
112
0
                } else {
113
0
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
114
0
                            value.data(), value.size(), col_to_data[i]);
115
0
                }
116
0
            }
117
0
        } else {
118
0
            DCHECK(false);
119
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
120
0
                                        column->get_name(), name);
121
0
        }
122
5
        return Status::OK();
123
5
    }
_ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb1EE7executeILb1EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
77
4
                          IColumn& col_to) {
78
4
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
79
4
        if constexpr (first) {
80
            if constexpr (ReturnType == TYPE_INT) {
81
                to_column.insert_many_vals(static_cast<Int32>(HashUtil::MURMUR3_32_SEED),
82
                                           input_rows_count);
83
4
            } else {
84
4
                to_column.insert_many_defaults(input_rows_count);
85
4
            }
86
4
        }
87
4
        auto& col_to_data = to_column.get_data();
88
4
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
89
4
            const typename ColumnString::Chars& data = col_from->get_chars();
90
4
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
91
4
            size_t size = offsets.size();
92
4
            ColumnString::Offset current_offset = 0;
93
10
            for (size_t i = 0; i < size; ++i) {
94
                if constexpr (ReturnType == TYPE_INT) {
95
                    col_to_data[i] = HashUtil::murmur_hash3_32(
96
                            reinterpret_cast<const char*>(&data[current_offset]),
97
                            offsets[i] - current_offset, col_to_data[i]);
98
6
                } else {
99
6
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
100
6
                            reinterpret_cast<const char*>(&data[current_offset]),
101
6
                            offsets[i] - current_offset, col_to_data[i]);
102
6
                }
103
6
                current_offset = offsets[i];
104
6
            }
105
4
        } else if (const ColumnConst* col_from_const =
106
0
                           check_and_get_column_const_string_or_fixedstring(column)) {
107
0
            auto value = col_from_const->get_value<TYPE_STRING>();
108
0
            for (size_t i = 0; i < input_rows_count; ++i) {
109
                if constexpr (ReturnType == TYPE_INT) {
110
                    col_to_data[i] =
111
                            HashUtil::murmur_hash3_32(value.data(), value.size(), col_to_data[i]);
112
0
                } else {
113
0
                    col_to_data[i] = HashUtil::murmur_hash3_64<is_mmh64_v2>(
114
0
                            value.data(), value.size(), col_to_data[i]);
115
0
                }
116
0
            }
117
0
        } else {
118
0
            DCHECK(false);
119
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
120
0
                                        column->get_name(), name);
121
0
        }
122
4
        return Status::OK();
123
4
    }
Unexecuted instantiation: _ZN5doris15MurmurHash3ImplILNS_13PrimitiveTypeE6ELb1EE7executeILb0EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
124
};
125
126
using FunctionMurmurHash3_32 =
127
        FunctionVariadicArgumentsBase<DataTypeInt32, MurmurHash3Impl<TYPE_INT>>;
128
using FunctionMurmurHash3_64 =
129
        FunctionVariadicArgumentsBase<DataTypeInt64, MurmurHash3Impl<TYPE_BIGINT>>;
130
using FunctionMurmurHash3_64_V2 =
131
        FunctionVariadicArgumentsBase<DataTypeInt64, MurmurHash3Impl<TYPE_BIGINT, true>>;
132
133
#ifdef BE_TEST
134
const char* murmur_hash3_get_name_type_int_for_test() {
135
    return MurmurHash3Impl<TYPE_INT>::get_name();
136
}
137
138
const char* murmur_hash3_get_name_type_bigint_for_test() {
139
    return MurmurHash3Impl<TYPE_BIGINT>::get_name();
140
}
141
142
const char* murmur_hash3_get_name_type_bigint_v2_for_test() {
143
    return MurmurHash3Impl<TYPE_BIGINT, true>::get_name();
144
}
145
#endif
146
147
template <PrimitiveType ReturnType>
148
struct XxHashImpl {
149
    static constexpr auto name = ReturnType == TYPE_INT ? "xxhash_32" : "xxhash_64";
150
151
0
    static Status empty_apply(IColumn& icolumn, size_t input_rows_count) {
152
0
        ColumnVector<ReturnType>& vec_to = assert_cast<ColumnVector<ReturnType>&>(icolumn);
153
0
        vec_to.get_data().assign(
154
0
                input_rows_count,
155
0
                static_cast<typename PrimitiveTypeTraits<ReturnType>::CppType>(emtpy_value));
156
0
        return Status::OK();
157
0
    }
Unexecuted instantiation: _ZN5doris10XxHashImplILNS_13PrimitiveTypeE5EE11empty_applyERNS_7IColumnEm
Unexecuted instantiation: _ZN5doris10XxHashImplILNS_13PrimitiveTypeE6EE11empty_applyERNS_7IColumnEm
158
159
    static Status first_apply(const IDataType* type, const IColumn* column, size_t input_rows_count,
160
1.81k
                              IColumn& icolumn) {
161
1.81k
        return execute<true>(type, column, input_rows_count, icolumn);
162
1.81k
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE5EE11first_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
160
70
                              IColumn& icolumn) {
161
70
        return execute<true>(type, column, input_rows_count, icolumn);
162
70
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE6EE11first_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
160
1.74k
                              IColumn& icolumn) {
161
1.74k
        return execute<true>(type, column, input_rows_count, icolumn);
162
1.74k
    }
163
164
    static Status combine_apply(const IDataType* type, const IColumn* column,
165
26
                                size_t input_rows_count, IColumn& icolumn) {
166
26
        return execute<false>(type, column, input_rows_count, icolumn);
167
26
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE5EE13combine_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
165
12
                                size_t input_rows_count, IColumn& icolumn) {
166
12
        return execute<false>(type, column, input_rows_count, icolumn);
167
12
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE6EE13combine_applyEPKNS_9IDataTypeEPKNS_7IColumnEmRS6_
Line
Count
Source
165
14
                                size_t input_rows_count, IColumn& icolumn) {
166
14
        return execute<false>(type, column, input_rows_count, icolumn);
167
14
    }
168
169
    template <bool first>
170
    static Status execute(const IDataType* type, const IColumn* column, size_t input_rows_count,
171
1.84k
                          IColumn& col_to) {
172
1.84k
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
173
1.84k
        if constexpr (first) {
174
1.81k
            to_column.insert_many_defaults(input_rows_count);
175
1.81k
        }
176
1.84k
        auto& col_to_data = to_column.get_data();
177
1.84k
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
178
1.82k
            const typename ColumnString::Chars& data = col_from->get_chars();
179
1.82k
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
180
1.82k
            size_t size = offsets.size();
181
1.82k
            ColumnString::Offset current_offset = 0;
182
128k
            for (size_t i = 0; i < size; ++i) {
183
126k
                if constexpr (ReturnType == TYPE_INT) {
184
399
                    col_to_data[i] = HashUtil::xxHash32WithSeed(
185
399
                            reinterpret_cast<const char*>(&data[current_offset]),
186
399
                            offsets[i] - current_offset, col_to_data[i]);
187
125k
                } else {
188
125k
                    col_to_data[i] = HashUtil::xxHash64WithSeed(
189
125k
                            reinterpret_cast<const char*>(&data[current_offset]),
190
125k
                            offsets[i] - current_offset, col_to_data[i]);
191
125k
                }
192
126k
                current_offset = offsets[i];
193
126k
            }
194
1.82k
        } else if (const ColumnConst* col_from_const =
195
24
                           check_and_get_column_const_string_or_fixedstring(column)) {
196
0
            auto value = col_from_const->get_value<TYPE_STRING>();
197
0
            for (size_t i = 0; i < input_rows_count; ++i) {
198
0
                if constexpr (ReturnType == TYPE_INT) {
199
0
                    col_to_data[i] =
200
0
                            HashUtil::xxHash32WithSeed(value.data(), value.size(), col_to_data[i]);
201
0
                } else {
202
0
                    col_to_data[i] =
203
0
                            HashUtil::xxHash64WithSeed(value.data(), value.size(), col_to_data[i]);
204
0
                }
205
0
            }
206
24
        } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(column)) {
207
108
            for (size_t i = 0; i < input_rows_count; ++i) {
208
84
                auto data_ref = vb_col->get_data_at(i);
209
84
                if constexpr (ReturnType == TYPE_INT) {
210
42
                    col_to_data[i] = HashUtil::xxHash32WithSeed(data_ref.data, data_ref.size,
211
42
                                                                col_to_data[i]);
212
42
                } else {
213
42
                    col_to_data[i] = HashUtil::xxHash64WithSeed(data_ref.data, data_ref.size,
214
42
                                                                col_to_data[i]);
215
42
                }
216
84
            }
217
24
        } else {
218
0
            DCHECK(false);
219
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
220
0
                                        column->get_name(), name);
221
0
        }
222
1.84k
        return Status::OK();
223
1.84k
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE5EE7executeILb1EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
171
70
                          IColumn& col_to) {
172
70
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
173
70
        if constexpr (first) {
174
70
            to_column.insert_many_defaults(input_rows_count);
175
70
        }
176
70
        auto& col_to_data = to_column.get_data();
177
70
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
178
63
            const typename ColumnString::Chars& data = col_from->get_chars();
179
63
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
180
63
            size_t size = offsets.size();
181
63
            ColumnString::Offset current_offset = 0;
182
444
            for (size_t i = 0; i < size; ++i) {
183
381
                if constexpr (ReturnType == TYPE_INT) {
184
381
                    col_to_data[i] = HashUtil::xxHash32WithSeed(
185
381
                            reinterpret_cast<const char*>(&data[current_offset]),
186
381
                            offsets[i] - current_offset, col_to_data[i]);
187
                } else {
188
                    col_to_data[i] = HashUtil::xxHash64WithSeed(
189
                            reinterpret_cast<const char*>(&data[current_offset]),
190
                            offsets[i] - current_offset, col_to_data[i]);
191
                }
192
381
                current_offset = offsets[i];
193
381
            }
194
63
        } else if (const ColumnConst* col_from_const =
195
7
                           check_and_get_column_const_string_or_fixedstring(column)) {
196
0
            auto value = col_from_const->get_value<TYPE_STRING>();
197
0
            for (size_t i = 0; i < input_rows_count; ++i) {
198
0
                if constexpr (ReturnType == TYPE_INT) {
199
0
                    col_to_data[i] =
200
0
                            HashUtil::xxHash32WithSeed(value.data(), value.size(), col_to_data[i]);
201
                } else {
202
                    col_to_data[i] =
203
                            HashUtil::xxHash64WithSeed(value.data(), value.size(), col_to_data[i]);
204
                }
205
0
            }
206
7
        } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(column)) {
207
33
            for (size_t i = 0; i < input_rows_count; ++i) {
208
26
                auto data_ref = vb_col->get_data_at(i);
209
26
                if constexpr (ReturnType == TYPE_INT) {
210
26
                    col_to_data[i] = HashUtil::xxHash32WithSeed(data_ref.data, data_ref.size,
211
26
                                                                col_to_data[i]);
212
                } else {
213
                    col_to_data[i] = HashUtil::xxHash64WithSeed(data_ref.data, data_ref.size,
214
                                                                col_to_data[i]);
215
                }
216
26
            }
217
7
        } else {
218
0
            DCHECK(false);
219
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
220
0
                                        column->get_name(), name);
221
0
        }
222
70
        return Status::OK();
223
70
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE5EE7executeILb0EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
171
12
                          IColumn& col_to) {
172
12
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
173
        if constexpr (first) {
174
            to_column.insert_many_defaults(input_rows_count);
175
        }
176
12
        auto& col_to_data = to_column.get_data();
177
12
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
178
7
            const typename ColumnString::Chars& data = col_from->get_chars();
179
7
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
180
7
            size_t size = offsets.size();
181
7
            ColumnString::Offset current_offset = 0;
182
25
            for (size_t i = 0; i < size; ++i) {
183
18
                if constexpr (ReturnType == TYPE_INT) {
184
18
                    col_to_data[i] = HashUtil::xxHash32WithSeed(
185
18
                            reinterpret_cast<const char*>(&data[current_offset]),
186
18
                            offsets[i] - current_offset, col_to_data[i]);
187
                } else {
188
                    col_to_data[i] = HashUtil::xxHash64WithSeed(
189
                            reinterpret_cast<const char*>(&data[current_offset]),
190
                            offsets[i] - current_offset, col_to_data[i]);
191
                }
192
18
                current_offset = offsets[i];
193
18
            }
194
7
        } else if (const ColumnConst* col_from_const =
195
5
                           check_and_get_column_const_string_or_fixedstring(column)) {
196
0
            auto value = col_from_const->get_value<TYPE_STRING>();
197
0
            for (size_t i = 0; i < input_rows_count; ++i) {
198
0
                if constexpr (ReturnType == TYPE_INT) {
199
0
                    col_to_data[i] =
200
0
                            HashUtil::xxHash32WithSeed(value.data(), value.size(), col_to_data[i]);
201
                } else {
202
                    col_to_data[i] =
203
                            HashUtil::xxHash64WithSeed(value.data(), value.size(), col_to_data[i]);
204
                }
205
0
            }
206
5
        } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(column)) {
207
21
            for (size_t i = 0; i < input_rows_count; ++i) {
208
16
                auto data_ref = vb_col->get_data_at(i);
209
16
                if constexpr (ReturnType == TYPE_INT) {
210
16
                    col_to_data[i] = HashUtil::xxHash32WithSeed(data_ref.data, data_ref.size,
211
16
                                                                col_to_data[i]);
212
                } else {
213
                    col_to_data[i] = HashUtil::xxHash64WithSeed(data_ref.data, data_ref.size,
214
                                                                col_to_data[i]);
215
                }
216
16
            }
217
5
        } else {
218
0
            DCHECK(false);
219
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
220
0
                                        column->get_name(), name);
221
0
        }
222
12
        return Status::OK();
223
12
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE6EE7executeILb1EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
171
1.74k
                          IColumn& col_to) {
172
1.74k
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
173
1.74k
        if constexpr (first) {
174
1.74k
            to_column.insert_many_defaults(input_rows_count);
175
1.74k
        }
176
1.74k
        auto& col_to_data = to_column.get_data();
177
1.74k
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
178
1.74k
            const typename ColumnString::Chars& data = col_from->get_chars();
179
1.74k
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
180
1.74k
            size_t size = offsets.size();
181
1.74k
            ColumnString::Offset current_offset = 0;
182
127k
            for (size_t i = 0; i < size; ++i) {
183
                if constexpr (ReturnType == TYPE_INT) {
184
                    col_to_data[i] = HashUtil::xxHash32WithSeed(
185
                            reinterpret_cast<const char*>(&data[current_offset]),
186
                            offsets[i] - current_offset, col_to_data[i]);
187
125k
                } else {
188
125k
                    col_to_data[i] = HashUtil::xxHash64WithSeed(
189
125k
                            reinterpret_cast<const char*>(&data[current_offset]),
190
125k
                            offsets[i] - current_offset, col_to_data[i]);
191
125k
                }
192
125k
                current_offset = offsets[i];
193
125k
            }
194
1.74k
        } else if (const ColumnConst* col_from_const =
195
7
                           check_and_get_column_const_string_or_fixedstring(column)) {
196
0
            auto value = col_from_const->get_value<TYPE_STRING>();
197
0
            for (size_t i = 0; i < input_rows_count; ++i) {
198
                if constexpr (ReturnType == TYPE_INT) {
199
                    col_to_data[i] =
200
                            HashUtil::xxHash32WithSeed(value.data(), value.size(), col_to_data[i]);
201
0
                } else {
202
0
                    col_to_data[i] =
203
0
                            HashUtil::xxHash64WithSeed(value.data(), value.size(), col_to_data[i]);
204
0
                }
205
0
            }
206
7
        } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(column)) {
207
33
            for (size_t i = 0; i < input_rows_count; ++i) {
208
26
                auto data_ref = vb_col->get_data_at(i);
209
                if constexpr (ReturnType == TYPE_INT) {
210
                    col_to_data[i] = HashUtil::xxHash32WithSeed(data_ref.data, data_ref.size,
211
                                                                col_to_data[i]);
212
26
                } else {
213
26
                    col_to_data[i] = HashUtil::xxHash64WithSeed(data_ref.data, data_ref.size,
214
26
                                                                col_to_data[i]);
215
26
                }
216
26
            }
217
7
        } else {
218
0
            DCHECK(false);
219
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
220
0
                                        column->get_name(), name);
221
0
        }
222
1.74k
        return Status::OK();
223
1.74k
    }
_ZN5doris10XxHashImplILNS_13PrimitiveTypeE6EE7executeILb0EEENS_6StatusEPKNS_9IDataTypeEPKNS_7IColumnEmRS8_
Line
Count
Source
171
14
                          IColumn& col_to) {
172
14
        auto& to_column = assert_cast<ColumnVector<ReturnType>&>(col_to);
173
        if constexpr (first) {
174
            to_column.insert_many_defaults(input_rows_count);
175
        }
176
14
        auto& col_to_data = to_column.get_data();
177
14
        if (const auto* col_from = check_and_get_column<ColumnString>(column)) {
178
9
            const typename ColumnString::Chars& data = col_from->get_chars();
179
9
            const typename ColumnString::Offsets& offsets = col_from->get_offsets();
180
9
            size_t size = offsets.size();
181
9
            ColumnString::Offset current_offset = 0;
182
29
            for (size_t i = 0; i < size; ++i) {
183
                if constexpr (ReturnType == TYPE_INT) {
184
                    col_to_data[i] = HashUtil::xxHash32WithSeed(
185
                            reinterpret_cast<const char*>(&data[current_offset]),
186
                            offsets[i] - current_offset, col_to_data[i]);
187
20
                } else {
188
20
                    col_to_data[i] = HashUtil::xxHash64WithSeed(
189
20
                            reinterpret_cast<const char*>(&data[current_offset]),
190
20
                            offsets[i] - current_offset, col_to_data[i]);
191
20
                }
192
20
                current_offset = offsets[i];
193
20
            }
194
9
        } else if (const ColumnConst* col_from_const =
195
5
                           check_and_get_column_const_string_or_fixedstring(column)) {
196
0
            auto value = col_from_const->get_value<TYPE_STRING>();
197
0
            for (size_t i = 0; i < input_rows_count; ++i) {
198
                if constexpr (ReturnType == TYPE_INT) {
199
                    col_to_data[i] =
200
                            HashUtil::xxHash32WithSeed(value.data(), value.size(), col_to_data[i]);
201
0
                } else {
202
0
                    col_to_data[i] =
203
0
                            HashUtil::xxHash64WithSeed(value.data(), value.size(), col_to_data[i]);
204
0
                }
205
0
            }
206
5
        } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(column)) {
207
21
            for (size_t i = 0; i < input_rows_count; ++i) {
208
16
                auto data_ref = vb_col->get_data_at(i);
209
                if constexpr (ReturnType == TYPE_INT) {
210
                    col_to_data[i] = HashUtil::xxHash32WithSeed(data_ref.data, data_ref.size,
211
                                                                col_to_data[i]);
212
16
                } else {
213
16
                    col_to_data[i] = HashUtil::xxHash64WithSeed(data_ref.data, data_ref.size,
214
16
                                                                col_to_data[i]);
215
16
                }
216
16
            }
217
5
        } else {
218
0
            DCHECK(false);
219
0
            return Status::NotSupported("Illegal column {} of argument of function {}",
220
0
                                        column->get_name(), name);
221
0
        }
222
14
        return Status::OK();
223
14
    }
224
};
225
226
using FunctionXxHash_32 = FunctionVariadicArgumentsBase<DataTypeInt32, XxHashImpl<TYPE_INT>>;
227
using FunctionXxHash_64 = FunctionVariadicArgumentsBase<DataTypeInt64, XxHashImpl<TYPE_BIGINT>>;
228
229
8
void register_function_hash(SimpleFunctionFactory& factory) {
230
8
    factory.register_function<FunctionMurmurHash3_32>();
231
8
    factory.register_function<FunctionMurmurHash3_64>();
232
8
    factory.register_function<FunctionMurmurHash3_64_V2>();
233
8
    factory.register_function<FunctionXxHash_32>();
234
8
    factory.register_function<FunctionXxHash_64>();
235
8
    factory.register_alias("xxhash_64", "xxhash3_64");
236
8
}
237
} // namespace doris