[refactor](be) refactor predicate function creator (#7054)

Refactor predicate function creator, make MinMaxFunction/HybridSet/BloomFilter
use a unified interface through template to get function.
This commit is contained in:
Pxl
2021-11-24 10:39:29 +08:00
committed by GitHub
parent d3c020b3cb
commit a74fdf184c
15 changed files with 278 additions and 288 deletions

View File

@ -62,7 +62,6 @@ add_library(Exprs
udf_builtins.cpp
utility_functions.cpp
info_func.cpp
hybrid_set.cpp
json_functions.cpp
operators.cpp
hll_hash_function.cpp

View File

@ -27,50 +27,6 @@
namespace doris {
IBloomFilterFuncBase* IBloomFilterFuncBase::create_bloom_filter(MemTracker* tracker,
PrimitiveType type) {
switch (type) {
case TYPE_BOOLEAN:
return new BloomFilterFunc<TYPE_BOOLEAN, CurrentBloomFilterAdaptor>(tracker);
case TYPE_TINYINT:
return new BloomFilterFunc<TYPE_TINYINT, CurrentBloomFilterAdaptor>(tracker);
case TYPE_SMALLINT:
return new BloomFilterFunc<TYPE_SMALLINT, CurrentBloomFilterAdaptor>(tracker);
case TYPE_INT:
return new BloomFilterFunc<TYPE_INT, CurrentBloomFilterAdaptor>(tracker);
case TYPE_BIGINT:
return new BloomFilterFunc<TYPE_BIGINT, CurrentBloomFilterAdaptor>(tracker);
case TYPE_LARGEINT:
return new BloomFilterFunc<TYPE_LARGEINT, CurrentBloomFilterAdaptor>(tracker);
case TYPE_FLOAT:
return new BloomFilterFunc<TYPE_FLOAT, CurrentBloomFilterAdaptor>(tracker);
case TYPE_DOUBLE:
return new BloomFilterFunc<TYPE_DOUBLE, CurrentBloomFilterAdaptor>(tracker);
case TYPE_DECIMALV2:
return new BloomFilterFunc<TYPE_DECIMALV2, CurrentBloomFilterAdaptor>(tracker);
case TYPE_TIME:
return new BloomFilterFunc<TYPE_TIME, CurrentBloomFilterAdaptor>(tracker);
case TYPE_DATE:
return new BloomFilterFunc<TYPE_DATE, CurrentBloomFilterAdaptor>(tracker);
case TYPE_DATETIME:
return new BloomFilterFunc<TYPE_DATETIME, CurrentBloomFilterAdaptor>(tracker);
case TYPE_CHAR:
return new BloomFilterFunc<TYPE_CHAR, CurrentBloomFilterAdaptor>(tracker);
case TYPE_VARCHAR:
return new BloomFilterFunc<TYPE_VARCHAR, CurrentBloomFilterAdaptor>(tracker);
case TYPE_STRING:
return new BloomFilterFunc<TYPE_STRING, CurrentBloomFilterAdaptor>(tracker);
default:
DCHECK(false) << "Invalid type.";
}
return nullptr;
}
BloomFilterPredicate::BloomFilterPredicate(const TExprNode& node)
: Predicate(node),
_is_prepare(false),

View File

@ -90,8 +90,6 @@ public:
virtual Status get_data(char** data, int* len) = 0;
virtual MemTracker* tracker() = 0;
virtual void light_copy(IBloomFilterFuncBase* other) = 0;
static IBloomFilterFuncBase* create_bloom_filter(MemTracker* tracker, PrimitiveType type);
};
template <class BloomFilterAdaptor>

View File

@ -0,0 +1,124 @@
// 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 "exprs/bloomfilter_predicate.h"
#include "exprs/hybrid_set.h"
#include "exprs/minmax_predicate.h"
#include "runtime/mem_tracker.h"
namespace doris {
class MinmaxFunctionTraits {
public:
using BasePtr = MinMaxFuncBase*;
template <PrimitiveType type>
static BasePtr get_function([[maybe_unused]] MemTracker* tracker) {
return new (std::nothrow) MinMaxNumFunc<typename PrimitiveTypeTraits<type>::CppType>();
};
};
class HybridSetTraits {
public:
using BasePtr = HybridSetBase*;
template <PrimitiveType type>
static BasePtr get_function([[maybe_unused]] MemTracker* tracker) {
using CppType = typename PrimitiveTypeTraits<type>::CppType;
using Set = std::conditional_t<std::is_same_v<CppType, StringValue>, StringValueSet,
HybridSet<CppType>>;
return new (std::nothrow) Set();
};
};
class BloomFilterTraits {
public:
using BasePtr = IBloomFilterFuncBase*;
template <PrimitiveType type>
static BasePtr get_function(MemTracker* tracker) {
return new BloomFilterFunc<type, CurrentBloomFilterAdaptor>(tracker);
};
};
template <class Traits>
class PredicateFunctionCreator {
public:
template <PrimitiveType type>
static typename Traits::BasePtr create(MemTracker* tracker = nullptr) {
return Traits::template get_function<type>(tracker);
}
};
template <class Traits>
typename Traits::BasePtr create_predicate_function(PrimitiveType type,
MemTracker* tracker = nullptr) {
using Creator = PredicateFunctionCreator<Traits>;
switch (type) {
case TYPE_BOOLEAN:
return Creator::template create<TYPE_BOOLEAN>(tracker);
case TYPE_TINYINT:
return Creator::template create<TYPE_TINYINT>(tracker);
case TYPE_SMALLINT:
return Creator::template create<TYPE_SMALLINT>(tracker);
case TYPE_INT:
return Creator::template create<TYPE_INT>(tracker);
case TYPE_BIGINT:
return Creator::template create<TYPE_BIGINT>(tracker);
case TYPE_LARGEINT:
return Creator::template create<TYPE_LARGEINT>(tracker);
case TYPE_FLOAT:
return Creator::template create<TYPE_FLOAT>(tracker);
case TYPE_DOUBLE:
return Creator::template create<TYPE_DOUBLE>(tracker);
case TYPE_DECIMALV2:
return Creator::template create<TYPE_DECIMALV2>(tracker);
case TYPE_DATE:
return Creator::template create<TYPE_DATE>(tracker);
case TYPE_DATETIME:
return Creator::template create<TYPE_DATETIME>(tracker);
case TYPE_CHAR:
return Creator::template create<TYPE_CHAR>(tracker);
case TYPE_VARCHAR:
return Creator::template create<TYPE_VARCHAR>(tracker);
case TYPE_STRING:
return Creator::template create<TYPE_STRING>(tracker);
default:
DCHECK(false) << "Invalid type.";
}
return nullptr;
}
inline auto create_minmax_filter(PrimitiveType type) {
return create_predicate_function<MinmaxFunctionTraits>(type);
}
inline auto create_set(PrimitiveType type) {
return create_predicate_function<HybridSetTraits>(type);
}
inline auto create_bloom_filter(MemTracker* tracker, PrimitiveType type) {
return create_predicate_function<BloomFilterTraits>(type, tracker);
}
} // namespace doris

View File

@ -22,6 +22,7 @@
#include "common/object_pool.h"
#include "common/status.h"
#include "exprs/create_predicate_function.h"
#include "exprs/hybrid_set.h"
#include "runtime/datetime_value.h"
#include "runtime/primitive_type.h"
@ -40,7 +41,7 @@ public:
typename std::unordered_map<uint64_t, HybridSetBase*>::const_iterator it = _map.find(dst);
if (it == _map.end()) {
_set_ptr = _pool.add(HybridSetBase::create_set(_type));
_set_ptr = _pool.add(create_set(_type));
std::pair<uint64_t, HybridSetBase*> insert_pair(dst, _set_ptr);
_map.insert(insert_pair);
*is_add_buckets = true;

View File

@ -1,68 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "exprs/hybrid_set.h"
namespace doris {
HybridSetBase* HybridSetBase::create_set(PrimitiveType type) {
switch (type) {
case TYPE_BOOLEAN:
return new (std::nothrow) HybridSet<bool>();
case TYPE_TINYINT:
return new (std::nothrow) HybridSet<int8_t>();
case TYPE_SMALLINT:
return new (std::nothrow) HybridSet<int16_t>();
case TYPE_INT:
return new (std::nothrow) HybridSet<int32_t>();
case TYPE_BIGINT:
return new (std::nothrow) HybridSet<int64_t>();
case TYPE_LARGEINT:
return new (std::nothrow) HybridSet<__int128>();
case TYPE_FLOAT:
return new (std::nothrow) HybridSet<float>();
case TYPE_TIME:
case TYPE_DOUBLE:
return new (std::nothrow) HybridSet<double>();
case TYPE_DECIMALV2:
return new (std::nothrow) HybridSet<DecimalV2Value>();
case TYPE_DATE:
case TYPE_DATETIME:
return new (std::nothrow) HybridSet<DateTimeValue>();
case TYPE_CHAR:
case TYPE_VARCHAR:
case TYPE_STRING:
return new (std::nothrow) StringValueSet();
default:
DCHECK(false) << "Invalid type.";
}
return nullptr;
}
} // namespace doris

View File

@ -45,8 +45,6 @@ public:
virtual bool find(void* data) = 0;
// use in vectorize execute engine
virtual bool find(void* data, size_t) = 0;
static HybridSetBase* create_set(PrimitiveType type);
class IteratorBase {
public:
IteratorBase() {}

View File

@ -85,7 +85,8 @@ Status InPredicate::prepare(RuntimeState* state, const RowDescriptor& row_desc,
if (_children.size() < 1) {
return Status::InternalError("no Function operator in.");
}
_hybrid_set.reset(HybridSetBase::create_set(_children[0]->type().type));
_hybrid_set.reset(create_set(_children[0]->type().type));
if (nullptr == _hybrid_set.get()) {
return Status::InternalError("Unknown column type.");
}

View File

@ -21,6 +21,7 @@
#include <string>
#include <unordered_set>
#include "exprs/create_predicate_function.h"
#include "exprs/hybrid_set.h"
#include "exprs/predicate.h"
#include "runtime/raw_value.h"

View File

@ -0,0 +1,116 @@
// 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 "common/object_pool.h"
#include "runtime/primitive_type.h"
#include "runtime/type_limit.h"
namespace doris {
// only used in Runtime Filter
class MinMaxFuncBase {
public:
virtual void insert(const void* data) = 0;
virtual bool find(void* data) = 0;
virtual bool is_empty() = 0;
virtual void* get_max() = 0;
virtual void* get_min() = 0;
// assign minmax data
virtual Status assign(void* min_data, void* max_data) = 0;
// merge from other minmax_func
virtual Status merge(MinMaxFuncBase* minmax_func, ObjectPool* pool) = 0;
};
template <class T>
class MinMaxNumFunc : public MinMaxFuncBase {
public:
MinMaxNumFunc() = default;
~MinMaxNumFunc() = default;
virtual void insert(const void* data) {
if (data == nullptr) return;
const T val_data = *reinterpret_cast<const T*>(data);
if (_empty) {
_min = val_data;
_max = val_data;
_empty = false;
return;
}
if (val_data < _min) {
_min = val_data;
} else if (val_data > _max) {
_max = val_data;
}
}
virtual bool find(void* data) {
if (data == nullptr) {
return false;
}
T val_data = *reinterpret_cast<T*>(data);
return val_data >= _min && val_data <= _max;
}
Status merge(MinMaxFuncBase* minmax_func, ObjectPool* pool) {
if constexpr (std::is_same_v<T, StringValue>) {
MinMaxNumFunc<T>* other_minmax = static_cast<MinMaxNumFunc<T>*>(minmax_func);
if (other_minmax->_min < _min) {
auto& other_min = other_minmax->_min;
auto str = pool->add(new std::string(other_min.ptr, other_min.len));
_min.ptr = str->data();
_min.len = str->length();
}
if (other_minmax->_max > _max) {
auto& other_max = other_minmax->_max;
auto str = pool->add(new std::string(other_max.ptr, other_max.len));
_max.ptr = str->data();
_max.len = str->length();
}
} else {
MinMaxNumFunc<T>* other_minmax = static_cast<MinMaxNumFunc<T>*>(minmax_func);
if (other_minmax->_min < _min) {
_min = other_minmax->_min;
}
if (other_minmax->_max > _max) {
_max = other_minmax->_max;
}
}
return Status::OK();
}
virtual bool is_empty() { return _empty; }
virtual void* get_max() { return &_max; }
virtual void* get_min() { return &_min; }
virtual Status assign(void* min_data, void* max_data) {
_min = *(T*)min_data;
_max = *(T*)max_data;
return Status::OK();
}
private:
T _max = type_limit<T>::min();
T _min = type_limit<T>::max();
// we use _empty to avoid compare twice
bool _empty = true;
};
}

View File

@ -24,11 +24,13 @@
#include "exec/hash_join_node.h"
#include "exprs/binary_predicate.h"
#include "exprs/bloomfilter_predicate.h"
#include "exprs/create_predicate_function.h"
#include "exprs/expr.h"
#include "exprs/expr_context.h"
#include "exprs/hybrid_set.h"
#include "exprs/in_predicate.h"
#include "exprs/literal.h"
#include "exprs/minmax_predicate.h"
#include "exprs/predicate.h"
#include "gen_cpp/internal_service.pb.h"
#include "gen_cpp/types.pb.h"
@ -40,145 +42,6 @@
#include "util/string_parser.hpp"
namespace doris {
// only used in Runtime Filter
class MinMaxFuncBase {
public:
virtual void insert(const void* data) = 0;
virtual bool find(void* data) = 0;
virtual bool is_empty() = 0;
virtual void* get_max() = 0;
virtual void* get_min() = 0;
// assign minmax data
virtual Status assign(void* min_data, void* max_data) = 0;
// merge from other minmax_func
virtual Status merge(MinMaxFuncBase* minmax_func, ObjectPool* pool) = 0;
// create min-max filter function
static MinMaxFuncBase* create_minmax_filter(PrimitiveType type);
};
template <class T>
class MinMaxNumFunc : public MinMaxFuncBase {
public:
MinMaxNumFunc() = default;
~MinMaxNumFunc() = default;
virtual void insert(const void* data) {
if (data == nullptr) return;
const T val_data = *reinterpret_cast<const T*>(data);
if (_empty) {
_min = val_data;
_max = val_data;
_empty = false;
return;
}
if (val_data < _min) {
_min = val_data;
} else if (val_data > _max) {
_max = val_data;
}
}
virtual bool find(void* data) {
if (data == nullptr) {
return false;
}
T val_data = *reinterpret_cast<T*>(data);
return val_data >= _min && val_data <= _max;
}
Status merge(MinMaxFuncBase* minmax_func, ObjectPool* pool) {
if constexpr (std::is_same_v<T, StringValue>) {
MinMaxNumFunc<T>* other_minmax = static_cast<MinMaxNumFunc<T>*>(minmax_func);
if (other_minmax->_min < _min) {
auto& other_min = other_minmax->_min;
auto str = pool->add(new std::string(other_min.ptr, other_min.len));
_min.ptr = str->data();
_min.len = str->length();
}
if (other_minmax->_max > _max) {
auto& other_max = other_minmax->_max;
auto str = pool->add(new std::string(other_max.ptr, other_max.len));
_max.ptr = str->data();
_max.len = str->length();
}
} else {
MinMaxNumFunc<T>* other_minmax = static_cast<MinMaxNumFunc<T>*>(minmax_func);
if (other_minmax->_min < _min) {
_min = other_minmax->_min;
}
if (other_minmax->_max > _max) {
_max = other_minmax->_max;
}
}
return Status::OK();
}
virtual bool is_empty() { return _empty; }
virtual void* get_max() { return &_max; }
virtual void* get_min() { return &_min; }
virtual Status assign(void* min_data, void* max_data) {
_min = *(T*)min_data;
_max = *(T*)max_data;
return Status::OK();
}
private:
T _max = type_limit<T>::min();
T _min = type_limit<T>::max();
// we use _empty to avoid compare twice
bool _empty = true;
};
MinMaxFuncBase* MinMaxFuncBase::create_minmax_filter(PrimitiveType type) {
switch (type) {
case TYPE_BOOLEAN:
return new (std::nothrow) MinMaxNumFunc<bool>();
case TYPE_TINYINT:
return new (std::nothrow) MinMaxNumFunc<int8_t>();
case TYPE_SMALLINT:
return new (std::nothrow) MinMaxNumFunc<int16_t>();
case TYPE_INT:
return new (std::nothrow) MinMaxNumFunc<int32_t>();
case TYPE_BIGINT:
return new (std::nothrow) MinMaxNumFunc<int64_t>();
case TYPE_LARGEINT:
return new (std::nothrow) MinMaxNumFunc<__int128>();
case TYPE_FLOAT:
return new (std::nothrow) MinMaxNumFunc<float>();
case TYPE_TIME:
case TYPE_DOUBLE:
return new (std::nothrow) MinMaxNumFunc<double>();
case TYPE_DECIMALV2:
return new (std::nothrow) MinMaxNumFunc<DecimalV2Value>();
case TYPE_DATE:
case TYPE_DATETIME:
return new (std::nothrow) MinMaxNumFunc<DateTimeValue>();
case TYPE_CHAR:
case TYPE_VARCHAR:
case TYPE_STRING:
return new (std::nothrow) MinMaxNumFunc<StringValue>();
default:
DCHECK(false) << "Invalid type.";
}
return nullptr;
}
// PrimitiveType->TExprNodeType
// TODO: use constexpr if we use c++14
TExprNodeType::type get_expr_node_type(PrimitiveType type) {
@ -463,16 +326,15 @@ public:
Status init(const RuntimeFilterParams* params) {
switch (_filter_type) {
case RuntimeFilterType::IN_FILTER: {
_hybrid_set.reset(HybridSetBase::create_set(_column_return_type));
_hybrid_set.reset(create_set(_column_return_type));
break;
}
case RuntimeFilterType::MINMAX_FILTER: {
_minmax_func.reset(MinMaxFuncBase::create_minmax_filter(_column_return_type));
_minmax_func.reset(create_minmax_filter(_column_return_type));
break;
}
case RuntimeFilterType::BLOOM_FILTER: {
_bloomfilter_func.reset(
IBloomFilterFuncBase::create_bloom_filter(_tracker, _column_return_type));
_bloomfilter_func.reset(create_bloom_filter(_tracker, _column_return_type));
return _bloomfilter_func->init_with_fixed_length(params->bloom_filter_size);
}
default:
@ -594,8 +456,7 @@ public:
DCHECK(_tracker != nullptr);
// we won't use this class to insert or find any data
// so any type is ok
_bloomfilter_func.reset(
IBloomFilterFuncBase::create_bloom_filter(_tracker, PrimitiveType::TYPE_INT));
_bloomfilter_func.reset(create_bloom_filter(_tracker, PrimitiveType::TYPE_INT));
return _bloomfilter_func->assign(data, bloom_filter->filter_length());
}
@ -604,7 +465,7 @@ public:
Status assign(const PMinMaxFilter* minmax_filter) {
DCHECK(_tracker != nullptr);
PrimitiveType type = to_primitive_type(minmax_filter->column_type());
_minmax_func.reset(MinMaxFuncBase::create_minmax_filter(type));
_minmax_func.reset(create_minmax_filter(type));
switch (type) {
case TYPE_BOOLEAN: {
bool min_val;

View File

@ -17,6 +17,8 @@
#include "olap/bloom_filter_predicate.h"
#include "exprs/create_predicate_function.h"
#define APPLY_FOR_PRIMTYPE(M) \
M(TYPE_TINYINT) \
M(TYPE_SMALLINT) \
@ -37,23 +39,21 @@ ColumnPredicate* BloomFilterColumnPredicateFactory::create_column_predicate(
FieldType type) {
std::shared_ptr<IBloomFilterFuncBase> filter;
switch (type) {
#define M(NAME) \
case OLAP_FIELD_##NAME: { \
filter.reset(IBloomFilterFuncBase::create_bloom_filter(bloom_filter->tracker(), NAME)); \
filter->light_copy(bloom_filter.get()); \
return new BloomFilterColumnPredicate<NAME>(column_id, filter); \
#define M(NAME) \
case OLAP_FIELD_##NAME: { \
filter.reset(create_bloom_filter(bloom_filter->tracker(), NAME)); \
filter->light_copy(bloom_filter.get()); \
return new BloomFilterColumnPredicate<NAME>(column_id, filter); \
}
APPLY_FOR_PRIMTYPE(M)
#undef M
case OLAP_FIELD_TYPE_DECIMAL: {
filter.reset(
IBloomFilterFuncBase::create_bloom_filter(bloom_filter->tracker(), TYPE_DECIMALV2));
filter.reset(create_bloom_filter(bloom_filter->tracker(), TYPE_DECIMALV2));
filter->light_copy(bloom_filter.get());
return new BloomFilterColumnPredicate<TYPE_DECIMALV2>(column_id, filter);
}
case OLAP_FIELD_TYPE_BOOL: {
filter.reset(
IBloomFilterFuncBase::create_bloom_filter(bloom_filter->tracker(), TYPE_BOOLEAN));
filter.reset(create_bloom_filter(bloom_filter->tracker(), TYPE_BOOLEAN));
filter->light_copy(bloom_filter.get());
return new BloomFilterColumnPredicate<TYPE_BOOLEAN>(column_id, filter);
}

View File

@ -18,6 +18,7 @@
#include <string>
#include "exprs/bloomfilter_predicate.h"
#include "exprs/create_predicate_function.h"
#include "gtest/gtest.h"
#include "runtime/string_value.h"
@ -32,7 +33,7 @@ public:
TEST_F(BloomFilterPredicateTest, bloom_filter_func_int_test) {
auto tracker = MemTracker::CreateTracker();
std::unique_ptr<IBloomFilterFuncBase> func(
IBloomFilterFuncBase::create_bloom_filter(tracker.get(), PrimitiveType::TYPE_INT));
create_bloom_filter(tracker.get(), PrimitiveType::TYPE_INT));
ASSERT_TRUE(func->init(1024, 0.05).ok());
const int data_size = 1024;
int data[data_size];
@ -54,7 +55,7 @@ TEST_F(BloomFilterPredicateTest, bloom_filter_func_int_test) {
TEST_F(BloomFilterPredicateTest, bloom_filter_func_stringval_test) {
auto tracker = MemTracker::CreateTracker();
std::unique_ptr<IBloomFilterFuncBase> func(
IBloomFilterFuncBase::create_bloom_filter(tracker.get(), PrimitiveType::TYPE_VARCHAR));
create_bloom_filter(tracker.get(), PrimitiveType::TYPE_VARCHAR));
ASSERT_TRUE(func->init(1024, 0.05).ok());
ObjectPool obj_pool;
const int data_size = 1024;
@ -73,7 +74,7 @@ TEST_F(BloomFilterPredicateTest, bloom_filter_func_stringval_test) {
ASSERT_FALSE(func->find((const void*)&not_exist_val));
// test fixed char
func.reset(IBloomFilterFuncBase::create_bloom_filter(tracker.get(), PrimitiveType::TYPE_CHAR));
func.reset(create_bloom_filter(tracker.get(), PrimitiveType::TYPE_CHAR));
ASSERT_TRUE(func->init(1024, 0.05).ok());
auto varchar_true_str = obj_pool.add(new std::string("true"));
@ -105,7 +106,7 @@ TEST_F(BloomFilterPredicateTest, bloom_filter_func_stringval_test) {
TEST_F(BloomFilterPredicateTest, bloom_filter_size_test) {
auto tracker = MemTracker::CreateTracker();
std::unique_ptr<IBloomFilterFuncBase> func(
IBloomFilterFuncBase::create_bloom_filter(tracker.get(), PrimitiveType::TYPE_VARCHAR));
create_bloom_filter(tracker.get(), PrimitiveType::TYPE_VARCHAR));
int length = 4096;
func->init_with_fixed_length(4096);
char* data = nullptr;

View File

@ -22,6 +22,7 @@
#include <string>
#include "common/configbase.h"
#include "exprs/create_predicate_function.h"
#include "util/logging.h"
namespace doris {
@ -35,7 +36,7 @@ protected:
};
TEST_F(HybridSetTest, bool) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_BOOLEAN);
HybridSetBase* set = create_set(TYPE_BOOLEAN);
bool a = true;
set->insert(&a);
a = false;
@ -60,7 +61,7 @@ TEST_F(HybridSetTest, bool) {
}
TEST_F(HybridSetTest, tinyint) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_TINYINT);
HybridSetBase* set = create_set(TYPE_TINYINT);
int8_t a = 0;
set->insert(&a);
a = 1;
@ -97,7 +98,7 @@ TEST_F(HybridSetTest, tinyint) {
ASSERT_FALSE(set->find(&a));
}
TEST_F(HybridSetTest, smallint) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_SMALLINT);
HybridSetBase* set = create_set(TYPE_SMALLINT);
int16_t a = 0;
set->insert(&a);
a = 1;
@ -133,7 +134,7 @@ TEST_F(HybridSetTest, smallint) {
ASSERT_FALSE(set->find(&a));
}
TEST_F(HybridSetTest, int) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_INT);
HybridSetBase* set = create_set(TYPE_INT);
int32_t a = 0;
set->insert(&a);
a = 1;
@ -169,7 +170,7 @@ TEST_F(HybridSetTest, int) {
ASSERT_FALSE(set->find(&a));
}
TEST_F(HybridSetTest, bigint) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_BIGINT);
HybridSetBase* set = create_set(TYPE_BIGINT);
int64_t a = 0;
set->insert(&a);
a = 1;
@ -205,7 +206,7 @@ TEST_F(HybridSetTest, bigint) {
ASSERT_FALSE(set->find(&a));
}
TEST_F(HybridSetTest, float) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_FLOAT);
HybridSetBase* set = create_set(TYPE_FLOAT);
float a = 0;
set->insert(&a);
a = 1.1;
@ -241,7 +242,7 @@ TEST_F(HybridSetTest, float) {
ASSERT_FALSE(set->find(&a));
}
TEST_F(HybridSetTest, double) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_DOUBLE);
HybridSetBase* set = create_set(TYPE_DOUBLE);
double a = 0;
set->insert(&a);
a = 1.1;
@ -277,7 +278,7 @@ TEST_F(HybridSetTest, double) {
ASSERT_FALSE(set->find(&a));
}
TEST_F(HybridSetTest, string) {
HybridSetBase* set = HybridSetBase::create_set(TYPE_VARCHAR);
HybridSetBase* set = create_set(TYPE_VARCHAR);
StringValue a;
char buf[100];
@ -329,7 +330,7 @@ TEST_F(HybridSetTest, string) {
TEST_F(HybridSetTest, timestamp) {
CpuInfo::init();
HybridSetBase* set = HybridSetBase::create_set(TYPE_DATETIME);
HybridSetBase* set = create_set(TYPE_DATETIME);
char s1[] = "2012-01-20 01:10:01";
char s2[] = "1990-10-20 10:10:10.123456 ";
char s3[] = " 1990-10-20 10:10:10.123456";

View File

@ -19,6 +19,7 @@
#include <gtest/gtest.h>
#include <time.h>
#include "exprs/create_predicate_function.h"
#include "olap/bloom_filter_predicate.h"
#include "olap/column_predicate.h"
#include "olap/field.h"
@ -91,7 +92,7 @@ TEST_F(TestBloomFilterColumnPredicate, FLOAT_COLUMN) {
auto tracker = MemTracker::CreateTracker(-1, "OlapScanner");
std::shared_ptr<IBloomFilterFuncBase> bloom_filter(
IBloomFilterFuncBase::create_bloom_filter(tracker.get(), PrimitiveType::TYPE_FLOAT));
create_bloom_filter(tracker.get(), PrimitiveType::TYPE_FLOAT));
bloom_filter->init(4096, 0.05);
float value = 4.1;