Coverage Report

Created: 2026-03-31 07:03

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