[Refactor](predicate) Use primitive type as template argument for predicate (#11647)
This commit is contained in:
@ -61,7 +61,7 @@ public:
|
||||
uint16_t size) const override;
|
||||
|
||||
private:
|
||||
template <bool is_nullable, typename file_type = void>
|
||||
template <bool is_nullable>
|
||||
uint16_t evaluate(const vectorized::IColumn& column, const uint8_t* null_map, uint16_t* sel,
|
||||
uint16_t size) const {
|
||||
if constexpr (is_nullable) {
|
||||
@ -83,21 +83,6 @@ private:
|
||||
}
|
||||
} else {
|
||||
uint24_t tmp_uint24_value;
|
||||
auto get_column_data = [](const vectorized::IColumn& column) {
|
||||
if constexpr (std::is_same_v<file_type, uint24_t> &&
|
||||
T == PrimitiveType::TYPE_DATE) {
|
||||
return reinterpret_cast<const vectorized::PredicateColumnType<uint32_t>*>(
|
||||
&column)
|
||||
->get_data()
|
||||
.data();
|
||||
} else {
|
||||
return reinterpret_cast<const vectorized::PredicateColumnType<file_type>*>(
|
||||
&column)
|
||||
->get_data()
|
||||
.data();
|
||||
}
|
||||
};
|
||||
|
||||
auto get_cell_value = [&tmp_uint24_value](auto& data) {
|
||||
if constexpr (std::is_same_v<std::decay_t<decltype(data)>, uint32_t> &&
|
||||
T == PrimitiveType::TYPE_DATE) {
|
||||
@ -108,7 +93,10 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
auto pred_col_data = get_column_data(column);
|
||||
auto pred_col_data =
|
||||
reinterpret_cast<const vectorized::PredicateColumnType<T>*>(&column)
|
||||
->get_data()
|
||||
.data();
|
||||
for (uint16_t i = 0; i < size; i++) {
|
||||
uint16_t idx = sel[i];
|
||||
sel[new_size] = idx;
|
||||
@ -159,17 +147,16 @@ template <PrimitiveType T>
|
||||
uint16_t BloomFilterColumnPredicate<T>::evaluate(const vectorized::IColumn& column, uint16_t* sel,
|
||||
uint16_t size) const {
|
||||
uint16_t new_size = 0;
|
||||
using FT = typename PredicatePrimitiveTypeTraits<T>::PredicateFieldType;
|
||||
if (!_enable_pred) {
|
||||
return size;
|
||||
}
|
||||
if (column.is_nullable()) {
|
||||
auto* nullable_col = reinterpret_cast<const vectorized::ColumnNullable*>(&column);
|
||||
auto& null_map_data = nullable_col->get_null_map_column().get_data();
|
||||
new_size = evaluate<true, FT>(nullable_col->get_nested_column(), null_map_data.data(), sel,
|
||||
size);
|
||||
new_size =
|
||||
evaluate<true>(nullable_col->get_nested_column(), null_map_data.data(), sel, size);
|
||||
} else {
|
||||
new_size = evaluate<false, FT>(column, nullptr, sel, size);
|
||||
new_size = evaluate<false>(column, nullptr, sel, size);
|
||||
}
|
||||
// If the pass rate is very high, for example > 50%, then the bloomfilter is useless.
|
||||
// Some bloomfilter is useless, for example ssb 4.3, it consumes a lot of cpu but it is
|
||||
|
||||
@ -24,9 +24,11 @@
|
||||
|
||||
namespace doris {
|
||||
|
||||
template <class T, PredicateType PT>
|
||||
template <PrimitiveType Type, PredicateType PT>
|
||||
class ComparisonPredicateBase : public ColumnPredicate {
|
||||
public:
|
||||
using T = std::conditional_t<Type == TYPE_DATE, uint24_t,
|
||||
typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType>;
|
||||
ComparisonPredicateBase(uint32_t column_id, const T& value, bool opposite = false)
|
||||
: ColumnPredicate(column_id, opposite), _value(value) {
|
||||
if constexpr (std::is_same_v<T, uint24_t>) {
|
||||
@ -186,7 +188,7 @@ public:
|
||||
LOG(FATAL) << "column_dictionary must use StringValue predicate.";
|
||||
}
|
||||
} else {
|
||||
auto* data_array = reinterpret_cast<const vectorized::PredicateColumnType<TReal>&>(
|
||||
auto* data_array = reinterpret_cast<const vectorized::PredicateColumnType<Type>&>(
|
||||
nested_column)
|
||||
.get_data()
|
||||
.data();
|
||||
@ -209,7 +211,7 @@ public:
|
||||
}
|
||||
} else {
|
||||
auto* data_array =
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<TReal>>(
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<Type>>(
|
||||
column)
|
||||
->get_data()
|
||||
.data();
|
||||
@ -236,7 +238,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
using TReal = std::conditional_t<std::is_same_v<T, uint24_t>, uint32_t, T>;
|
||||
using TReal = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType;
|
||||
|
||||
template <typename LeftT, typename RightT>
|
||||
bool _operator(const LeftT& lhs, const RightT& rhs) const {
|
||||
@ -389,7 +391,7 @@ private:
|
||||
}
|
||||
} else {
|
||||
auto* data_array =
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<TReal>>(column)
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<Type>>(column)
|
||||
->get_data()
|
||||
.data();
|
||||
|
||||
@ -436,7 +438,7 @@ private:
|
||||
}
|
||||
} else {
|
||||
auto* data_array =
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<TReal>>(column)
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<Type>>(column)
|
||||
->get_data()
|
||||
.data();
|
||||
|
||||
@ -448,17 +450,4 @@ private:
|
||||
TReal _value_real;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using EqualPredicate = ComparisonPredicateBase<T, PredicateType::EQ>;
|
||||
template <class T>
|
||||
using NotEqualPredicate = ComparisonPredicateBase<T, PredicateType::NE>;
|
||||
template <class T>
|
||||
using LessPredicate = ComparisonPredicateBase<T, PredicateType::LT>;
|
||||
template <class T>
|
||||
using LessEqualPredicate = ComparisonPredicateBase<T, PredicateType::LE>;
|
||||
template <class T>
|
||||
using GreaterPredicate = ComparisonPredicateBase<T, PredicateType::GT>;
|
||||
template <class T>
|
||||
using GreaterEqualPredicate = ComparisonPredicateBase<T, PredicateType::GE>;
|
||||
|
||||
} //namespace doris
|
||||
|
||||
@ -76,9 +76,11 @@ struct equal_to<doris::uint24_t> {
|
||||
|
||||
namespace doris {
|
||||
|
||||
template <class T, PredicateType PT>
|
||||
template <PrimitiveType Type, PredicateType PT>
|
||||
class InListPredicateBase : public ColumnPredicate {
|
||||
public:
|
||||
using T = std::conditional_t<Type == TYPE_DATE, uint24_t,
|
||||
typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType>;
|
||||
InListPredicateBase(uint32_t column_id, phmap::flat_hash_set<T>&& values,
|
||||
bool is_opposite = false)
|
||||
: ColumnPredicate(column_id, is_opposite), _values(std::move(values)) {}
|
||||
@ -238,7 +240,7 @@ private:
|
||||
|
||||
if constexpr (std::is_same_v<T, uint24_t>) {
|
||||
auto* nested_col_ptr =
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<uint32_t>>(
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<TYPE_DATE>>(
|
||||
column);
|
||||
auto& data_array = nested_col_ptr->get_data();
|
||||
|
||||
@ -299,7 +301,7 @@ private:
|
||||
}
|
||||
} else {
|
||||
auto* nested_col_ptr =
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<T>>(column);
|
||||
vectorized::check_and_get_column<vectorized::PredicateColumnType<Type>>(column);
|
||||
auto& data_array = nested_col_ptr->get_data();
|
||||
|
||||
for (uint16_t i = 0; i < size; i++) {
|
||||
@ -334,10 +336,4 @@ private:
|
||||
mutable std::vector<vectorized::UInt8> _value_in_dict_flags;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using InListPredicate = InListPredicateBase<T, PredicateType::IN_LIST>;
|
||||
|
||||
template <class T>
|
||||
using NotInListPredicate = InListPredicateBase<T, PredicateType::NOT_IN_LIST>;
|
||||
|
||||
} //namespace doris
|
||||
|
||||
@ -96,7 +96,7 @@ uint16_t LikeColumnPredicate<is_vectorized>::evaluate(const vectorized::IColumn&
|
||||
}
|
||||
} else {
|
||||
auto* data_array = vectorized::check_and_get_column<
|
||||
vectorized::PredicateColumnType<StringValue>>(column)
|
||||
vectorized::PredicateColumnType<TYPE_STRING>>(column)
|
||||
->get_data()
|
||||
.data();
|
||||
for (uint16_t i = 0; i != size; i++) {
|
||||
@ -129,7 +129,7 @@ uint16_t LikeColumnPredicate<is_vectorized>::evaluate(const vectorized::IColumn&
|
||||
}
|
||||
} else {
|
||||
auto* data_array = vectorized::check_and_get_column<
|
||||
vectorized::PredicateColumnType<StringValue>>(column)
|
||||
vectorized::PredicateColumnType<TYPE_STRING>>(column)
|
||||
->get_data()
|
||||
.data();
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ public:
|
||||
virtual ~PredicateCreator() = default;
|
||||
};
|
||||
|
||||
template <typename CppType, PredicateType PT, typename ConditionType>
|
||||
template <PrimitiveType Type, typename CppType, PredicateType PT, typename ConditionType>
|
||||
class IntegerPredicateCreator : public PredicateCreator<ConditionType> {
|
||||
public:
|
||||
ColumnPredicate* create(const TabletColumn& column, int index, const ConditionType& conditions,
|
||||
@ -47,10 +47,10 @@ public:
|
||||
for (const auto& condition : conditions) {
|
||||
values.insert(convert(condition));
|
||||
}
|
||||
return new InListPredicateBase<CppType, PT>(index, std::move(values), opposite);
|
||||
return new InListPredicateBase<Type, PT>(index, std::move(values), opposite);
|
||||
} else {
|
||||
static_assert(PredicateTypeTraits::is_comparison(PT));
|
||||
return new ComparisonPredicateBase<CppType, PT>(index, convert(conditions), opposite);
|
||||
return new ComparisonPredicateBase<Type, PT>(index, convert(conditions), opposite);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CppType, PredicateType PT, typename ConditionType>
|
||||
template <PrimitiveType Type, typename CppType, PredicateType PT, typename ConditionType>
|
||||
class DecimalPredicateCreator : public PredicateCreator<ConditionType> {
|
||||
public:
|
||||
ColumnPredicate* create(const TabletColumn& column, int index, const ConditionType& conditions,
|
||||
@ -72,11 +72,11 @@ public:
|
||||
for (const auto& condition : conditions) {
|
||||
values.insert(convert(column, condition));
|
||||
}
|
||||
return new InListPredicateBase<CppType, PT>(index, std::move(values), opposite);
|
||||
return new InListPredicateBase<Type, PT>(index, std::move(values), opposite);
|
||||
} else {
|
||||
static_assert(PredicateTypeTraits::is_comparison(PT));
|
||||
return new ComparisonPredicateBase<CppType, PT>(index, convert(column, conditions),
|
||||
opposite);
|
||||
return new ComparisonPredicateBase<Type, PT>(index, convert(column, conditions),
|
||||
opposite);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
template <PredicateType PT, typename ConditionType>
|
||||
template <PrimitiveType Type, PredicateType PT, typename ConditionType>
|
||||
class StringPredicateCreator : public PredicateCreator<ConditionType> {
|
||||
public:
|
||||
StringPredicateCreator(bool should_padding) : _should_padding(should_padding) {};
|
||||
@ -101,11 +101,11 @@ public:
|
||||
for (const auto& condition : conditions) {
|
||||
values.insert(convert(column, condition, pool));
|
||||
}
|
||||
return new InListPredicateBase<StringValue, PT>(index, std::move(values), opposite);
|
||||
return new InListPredicateBase<Type, PT>(index, std::move(values), opposite);
|
||||
} else {
|
||||
static_assert(PredicateTypeTraits::is_comparison(PT));
|
||||
return new ComparisonPredicateBase<StringValue, PT>(
|
||||
index, convert(column, conditions, pool), opposite);
|
||||
return new ComparisonPredicateBase<Type, PT>(index, convert(column, conditions, pool),
|
||||
opposite);
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CppType, PredicateType PT, typename ConditionType>
|
||||
template <PrimitiveType Type, typename CppType, PredicateType PT, typename ConditionType>
|
||||
struct CustomPredicateCreator : public PredicateCreator<ConditionType> {
|
||||
public:
|
||||
CustomPredicateCreator(const std::function<CppType(const std::string& condition)>& convert)
|
||||
@ -138,10 +138,10 @@ public:
|
||||
for (const auto& condition : conditions) {
|
||||
values.insert(_convert(condition));
|
||||
}
|
||||
return new InListPredicateBase<CppType, PT>(index, std::move(values), opposite);
|
||||
return new InListPredicateBase<Type, PT>(index, std::move(values), opposite);
|
||||
} else {
|
||||
static_assert(PredicateTypeTraits::is_comparison(PT));
|
||||
return new ComparisonPredicateBase<CppType, PT>(index, _convert(conditions), opposite);
|
||||
return new ComparisonPredicateBase<Type, PT>(index, _convert(conditions), opposite);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,22 +153,25 @@ template <PredicateType PT, typename ConditionType>
|
||||
inline std::unique_ptr<PredicateCreator<ConditionType>> get_creator(const FieldType& type) {
|
||||
switch (type) {
|
||||
case OLAP_FIELD_TYPE_TINYINT: {
|
||||
return std::make_unique<IntegerPredicateCreator<int8_t, PT, ConditionType>>();
|
||||
return std::make_unique<IntegerPredicateCreator<TYPE_TINYINT, int8_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_SMALLINT: {
|
||||
return std::make_unique<IntegerPredicateCreator<int16_t, PT, ConditionType>>();
|
||||
return std::make_unique<
|
||||
IntegerPredicateCreator<TYPE_SMALLINT, int16_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_INT: {
|
||||
return std::make_unique<IntegerPredicateCreator<int32_t, PT, ConditionType>>();
|
||||
return std::make_unique<IntegerPredicateCreator<TYPE_INT, int32_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_BIGINT: {
|
||||
return std::make_unique<IntegerPredicateCreator<int64_t, PT, ConditionType>>();
|
||||
return std::make_unique<IntegerPredicateCreator<TYPE_BIGINT, int64_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_LARGEINT: {
|
||||
return std::make_unique<IntegerPredicateCreator<int128_t, PT, ConditionType>>();
|
||||
return std::make_unique<
|
||||
IntegerPredicateCreator<TYPE_LARGEINT, int128_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DECIMAL: {
|
||||
return std::make_unique<CustomPredicateCreator<decimal12_t, PT, ConditionType>>(
|
||||
return std::make_unique<
|
||||
CustomPredicateCreator<TYPE_DECIMALV2, decimal12_t, PT, ConditionType>>(
|
||||
[](const std::string& condition) {
|
||||
decimal12_t value = {0, 0};
|
||||
value.from_string(condition);
|
||||
@ -176,39 +179,43 @@ inline std::unique_ptr<PredicateCreator<ConditionType>> get_creator(const FieldT
|
||||
});
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DECIMAL32: {
|
||||
return std::make_unique<DecimalPredicateCreator<int32_t, PT, ConditionType>>();
|
||||
return std::make_unique<
|
||||
DecimalPredicateCreator<TYPE_DECIMAL32, int32_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DECIMAL64: {
|
||||
return std::make_unique<DecimalPredicateCreator<int64_t, PT, ConditionType>>();
|
||||
return std::make_unique<
|
||||
DecimalPredicateCreator<TYPE_DECIMAL64, int64_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DECIMAL128: {
|
||||
return std::make_unique<DecimalPredicateCreator<int128_t, PT, ConditionType>>();
|
||||
return std::make_unique<
|
||||
DecimalPredicateCreator<TYPE_DECIMAL128, int128_t, PT, ConditionType>>();
|
||||
}
|
||||
case OLAP_FIELD_TYPE_CHAR: {
|
||||
return std::make_unique<StringPredicateCreator<PT, ConditionType>>(true);
|
||||
return std::make_unique<StringPredicateCreator<TYPE_CHAR, PT, ConditionType>>(true);
|
||||
}
|
||||
case OLAP_FIELD_TYPE_VARCHAR:
|
||||
case OLAP_FIELD_TYPE_STRING: {
|
||||
return std::make_unique<StringPredicateCreator<PT, ConditionType>>(false);
|
||||
return std::make_unique<StringPredicateCreator<TYPE_STRING, PT, ConditionType>>(false);
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DATE: {
|
||||
return std::make_unique<CustomPredicateCreator<uint24_t, PT, ConditionType>>(
|
||||
return std::make_unique<CustomPredicateCreator<TYPE_DATE, uint24_t, PT, ConditionType>>(
|
||||
timestamp_from_date);
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DATEV2: {
|
||||
return std::make_unique<CustomPredicateCreator<uint32_t, PT, ConditionType>>(
|
||||
return std::make_unique<CustomPredicateCreator<TYPE_DATEV2, uint32_t, PT, ConditionType>>(
|
||||
timestamp_from_date_v2);
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DATETIME: {
|
||||
return std::make_unique<CustomPredicateCreator<uint64_t, PT, ConditionType>>(
|
||||
return std::make_unique<CustomPredicateCreator<TYPE_DATETIME, uint64_t, PT, ConditionType>>(
|
||||
timestamp_from_datetime);
|
||||
}
|
||||
case OLAP_FIELD_TYPE_DATETIMEV2: {
|
||||
return std::make_unique<CustomPredicateCreator<uint64_t, PT, ConditionType>>(
|
||||
return std::make_unique<
|
||||
CustomPredicateCreator<TYPE_DATETIMEV2, uint64_t, PT, ConditionType>>(
|
||||
timestamp_from_datetime_v2);
|
||||
}
|
||||
case OLAP_FIELD_TYPE_BOOL: {
|
||||
return std::make_unique<CustomPredicateCreator<bool, PT, ConditionType>>(
|
||||
return std::make_unique<CustomPredicateCreator<TYPE_BOOLEAN, bool, PT, ConditionType>>(
|
||||
[](const std::string& condition) {
|
||||
int32_t ivalue = 0;
|
||||
auto result = std::from_chars(condition.data(),
|
||||
|
||||
@ -127,40 +127,40 @@ vectorized::IColumn::MutablePtr Schema::get_predicate_column_nullable_ptr(FieldT
|
||||
vectorized::IColumn::MutablePtr Schema::get_predicate_column_ptr(FieldType type) {
|
||||
switch (type) {
|
||||
case OLAP_FIELD_TYPE_BOOL:
|
||||
return doris::vectorized::PredicateColumnType<bool>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_BOOLEAN>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_TINYINT:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int8>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_TINYINT>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_SMALLINT:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int16>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_SMALLINT>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_INT:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int32>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_INT>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_FLOAT:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Float32>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_FLOAT>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_DOUBLE:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Float64>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DOUBLE>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_BIGINT:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int64>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_BIGINT>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_LARGEINT:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int128>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_LARGEINT>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_DATE:
|
||||
return doris::vectorized::PredicateColumnType<uint32_t>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DATE>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_DATEV2:
|
||||
return doris::vectorized::PredicateColumnType<uint32_t>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DATEV2>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_DATETIMEV2:
|
||||
return doris::vectorized::PredicateColumnType<uint64_t>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DATETIMEV2>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_DATETIME:
|
||||
return doris::vectorized::PredicateColumnType<uint64_t>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DATETIME>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_CHAR:
|
||||
case OLAP_FIELD_TYPE_VARCHAR:
|
||||
@ -168,16 +168,16 @@ vectorized::IColumn::MutablePtr Schema::get_predicate_column_ptr(FieldType type)
|
||||
if (config::enable_low_cardinality_optimize) {
|
||||
return doris::vectorized::ColumnDictionary<doris::vectorized::Int32>::create(type);
|
||||
}
|
||||
return doris::vectorized::PredicateColumnType<StringValue>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_STRING>::create();
|
||||
|
||||
case OLAP_FIELD_TYPE_DECIMAL:
|
||||
return doris::vectorized::PredicateColumnType<decimal12_t>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DECIMALV2>::create();
|
||||
case OLAP_FIELD_TYPE_DECIMAL32:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int32>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DECIMAL32>::create();
|
||||
case OLAP_FIELD_TYPE_DECIMAL64:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int64>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DECIMAL64>::create();
|
||||
case OLAP_FIELD_TYPE_DECIMAL128:
|
||||
return doris::vectorized::PredicateColumnType<doris::vectorized::Int128>::create();
|
||||
return doris::vectorized::PredicateColumnType<TYPE_DECIMAL128>::create();
|
||||
|
||||
default:
|
||||
LOG(FATAL) << "Unexpected type when choosing predicate column, type=" << type;
|
||||
|
||||
@ -221,7 +221,7 @@ struct PredicatePrimitiveTypeTraits<TYPE_DECIMALV2> {
|
||||
|
||||
template <>
|
||||
struct PredicatePrimitiveTypeTraits<TYPE_DATE> {
|
||||
using PredicateFieldType = uint24_t;
|
||||
using PredicateFieldType = uint32_t;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@ -257,7 +257,7 @@ public:
|
||||
bool is_dict_code_converted() const { return _dict_code_converted; }
|
||||
|
||||
MutableColumnPtr convert_to_predicate_column_if_dictionary() override {
|
||||
auto res = vectorized::PredicateColumnType<StringValue>::create();
|
||||
auto res = vectorized::PredicateColumnType<TYPE_STRING>::create();
|
||||
res->reserve(_reserve_size);
|
||||
for (size_t i = 0; i < _codes.size(); ++i) {
|
||||
auto& code = reinterpret_cast<T&>(_codes[i]);
|
||||
|
||||
@ -34,12 +34,13 @@ namespace doris::vectorized {
|
||||
*
|
||||
* T = predicate column type
|
||||
*/
|
||||
template <typename T>
|
||||
class PredicateColumnType final : public COWHelper<IColumn, PredicateColumnType<T>> {
|
||||
template <PrimitiveType Type>
|
||||
class PredicateColumnType final : public COWHelper<IColumn, PredicateColumnType<Type>> {
|
||||
private:
|
||||
PredicateColumnType() {}
|
||||
PredicateColumnType(const size_t n) : data(n) {}
|
||||
friend class COWHelper<IColumn, PredicateColumnType<T>>;
|
||||
friend class COWHelper<IColumn, PredicateColumnType<Type>>;
|
||||
using T = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType;
|
||||
|
||||
PredicateColumnType(const PredicateColumnType& src) : data(src.data.begin(), src.data.end()) {}
|
||||
|
||||
@ -241,9 +242,7 @@ public:
|
||||
insert_many_in_copy_way(data_ptr, num);
|
||||
} else if constexpr (std::is_same_v<T, StringValue>) {
|
||||
// here is unreachable, just for compilation to be able to pass
|
||||
} else if constexpr (std::is_same_v<
|
||||
T,
|
||||
uint32_t>) { // todo(wb) a trick type judge here,need refactor
|
||||
} else if constexpr (Type == TYPE_DATE) {
|
||||
insert_many_date(data_ptr, num);
|
||||
} else {
|
||||
insert_many_default_type(data_ptr, num);
|
||||
@ -484,6 +483,5 @@ private:
|
||||
// manages the memory for slice's data(For string type)
|
||||
std::unique_ptr<MemPool> _pool;
|
||||
};
|
||||
using ColumnStringValue = PredicateColumnType<StringValue>;
|
||||
|
||||
} // namespace doris::vectorized
|
||||
|
||||
@ -76,7 +76,8 @@ TEST_F(BlockColumnPredicateTest, SINGLE_COLUMN) {
|
||||
}
|
||||
float value = 5.0;
|
||||
|
||||
std::unique_ptr<ColumnPredicate> pred(new EqualPredicate<float>(0, value));
|
||||
std::unique_ptr<ColumnPredicate> pred(
|
||||
new ComparisonPredicateBase<TYPE_FLOAT, PredicateType::EQ>(0, value));
|
||||
SingleColumnBlockPredicate single_column_block_pred(pred.get());
|
||||
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -94,12 +95,13 @@ TEST_F(BlockColumnPredicateTest, SINGLE_COLUMN) {
|
||||
|
||||
TEST_F(BlockColumnPredicateTest, SINGLE_COLUMN_VEC) {
|
||||
vectorized::MutableColumns block;
|
||||
block.push_back(vectorized::PredicateColumnType<int>::create());
|
||||
block.push_back(vectorized::PredicateColumnType<TYPE_INT>::create());
|
||||
|
||||
int value = 5;
|
||||
int rows = 10;
|
||||
int col_idx = 0;
|
||||
std::unique_ptr<ColumnPredicate> pred(new EqualPredicate<int>(col_idx, value));
|
||||
std::unique_ptr<ColumnPredicate> pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(col_idx, value));
|
||||
SingleColumnBlockPredicate single_column_block_pred(pred.get());
|
||||
|
||||
uint16_t sel_idx[rows];
|
||||
@ -113,7 +115,8 @@ TEST_F(BlockColumnPredicateTest, SINGLE_COLUMN_VEC) {
|
||||
|
||||
selected_size = single_column_block_pred.evaluate(block, sel_idx, selected_size);
|
||||
EXPECT_EQ(selected_size, 1);
|
||||
auto* pred_col = reinterpret_cast<vectorized::PredicateColumnType<int>*>(block[col_idx].get());
|
||||
auto* pred_col =
|
||||
reinterpret_cast<vectorized::PredicateColumnType<TYPE_INT>*>(block[col_idx].get());
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[0]], value);
|
||||
}
|
||||
|
||||
@ -128,8 +131,10 @@ TEST_F(BlockColumnPredicateTest, AND_MUTI_COLUMN) {
|
||||
}
|
||||
double less_value = 5.0;
|
||||
double great_value = 3.0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<double>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<double>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::GT>(0, great_value));
|
||||
auto single_less_pred = new SingleColumnBlockPredicate(less_pred.get());
|
||||
auto single_great_pred = new SingleColumnBlockPredicate(great_pred.get());
|
||||
|
||||
@ -152,14 +157,16 @@ TEST_F(BlockColumnPredicateTest, AND_MUTI_COLUMN) {
|
||||
|
||||
TEST_F(BlockColumnPredicateTest, AND_MUTI_COLUMN_VEC) {
|
||||
vectorized::MutableColumns block;
|
||||
block.push_back(vectorized::PredicateColumnType<int>::create());
|
||||
block.push_back(vectorized::PredicateColumnType<TYPE_INT>::create());
|
||||
|
||||
int less_value = 5;
|
||||
int great_value = 3;
|
||||
int rows = 10;
|
||||
int col_idx = 0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<int>(col_idx, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<int>(col_idx, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(col_idx, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::GT>(col_idx, great_value));
|
||||
auto single_less_pred = new SingleColumnBlockPredicate(less_pred.get());
|
||||
auto single_great_pred = new SingleColumnBlockPredicate(great_pred.get());
|
||||
|
||||
@ -178,7 +185,8 @@ TEST_F(BlockColumnPredicateTest, AND_MUTI_COLUMN_VEC) {
|
||||
|
||||
selected_size = and_block_column_pred.evaluate(block, sel_idx, selected_size);
|
||||
EXPECT_EQ(selected_size, 1);
|
||||
auto* pred_col = reinterpret_cast<vectorized::PredicateColumnType<int>*>(block[col_idx].get());
|
||||
auto* pred_col =
|
||||
reinterpret_cast<vectorized::PredicateColumnType<TYPE_INT>*>(block[col_idx].get());
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[0]], 4);
|
||||
}
|
||||
|
||||
@ -193,8 +201,10 @@ TEST_F(BlockColumnPredicateTest, OR_MUTI_COLUMN) {
|
||||
}
|
||||
double less_value = 5.0;
|
||||
double great_value = 3.0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<double>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<double>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::GT>(0, great_value));
|
||||
auto single_less_pred = new SingleColumnBlockPredicate(less_pred.get());
|
||||
auto single_great_pred = new SingleColumnBlockPredicate(great_pred.get());
|
||||
|
||||
@ -217,14 +227,16 @@ TEST_F(BlockColumnPredicateTest, OR_MUTI_COLUMN) {
|
||||
|
||||
TEST_F(BlockColumnPredicateTest, OR_MUTI_COLUMN_VEC) {
|
||||
vectorized::MutableColumns block;
|
||||
block.push_back(vectorized::PredicateColumnType<int>::create());
|
||||
block.push_back(vectorized::PredicateColumnType<TYPE_INT>::create());
|
||||
|
||||
int less_value = 5;
|
||||
int great_value = 3;
|
||||
int rows = 10;
|
||||
int col_idx = 0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<int>(col_idx, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<int>(col_idx, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(col_idx, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::GT>(col_idx, great_value));
|
||||
auto single_less_pred = new SingleColumnBlockPredicate(less_pred.get());
|
||||
auto single_great_pred = new SingleColumnBlockPredicate(great_pred.get());
|
||||
|
||||
@ -243,7 +255,8 @@ TEST_F(BlockColumnPredicateTest, OR_MUTI_COLUMN_VEC) {
|
||||
|
||||
selected_size = or_block_column_pred.evaluate(block, sel_idx, selected_size);
|
||||
EXPECT_EQ(selected_size, 10);
|
||||
auto* pred_col = reinterpret_cast<vectorized::PredicateColumnType<int>*>(block[col_idx].get());
|
||||
auto* pred_col =
|
||||
reinterpret_cast<vectorized::PredicateColumnType<TYPE_INT>*>(block[col_idx].get());
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[0]], 0);
|
||||
}
|
||||
|
||||
@ -258,9 +271,12 @@ TEST_F(BlockColumnPredicateTest, OR_AND_MUTI_COLUMN) {
|
||||
}
|
||||
double less_value = 5.0;
|
||||
double great_value = 3.0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<double>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<double>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(new LessPredicate<double>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::GT>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, great_value));
|
||||
|
||||
init_row_block(tablet_schema, size);
|
||||
ColumnBlock col_block = _row_block->column_block(0);
|
||||
@ -310,15 +326,18 @@ TEST_F(BlockColumnPredicateTest, OR_AND_MUTI_COLUMN) {
|
||||
|
||||
TEST_F(BlockColumnPredicateTest, OR_AND_MUTI_COLUMN_VEC) {
|
||||
vectorized::MutableColumns block;
|
||||
block.push_back(vectorized::PredicateColumnType<int>::create());
|
||||
block.push_back(vectorized::PredicateColumnType<TYPE_INT>::create());
|
||||
|
||||
int less_value = 5;
|
||||
int great_value = 3;
|
||||
int rows = 10;
|
||||
int col_idx = 0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<int>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<int>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(new LessPredicate<int>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::GT>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(0, great_value));
|
||||
|
||||
// Test for and or single
|
||||
// (column < 5 and column > 3) or column < 3
|
||||
@ -341,7 +360,8 @@ TEST_F(BlockColumnPredicateTest, OR_AND_MUTI_COLUMN_VEC) {
|
||||
|
||||
selected_size = or_block_column_pred.evaluate(block, sel_idx, selected_size);
|
||||
EXPECT_EQ(selected_size, 4);
|
||||
auto* pred_col = reinterpret_cast<vectorized::PredicateColumnType<int>*>(block[col_idx].get());
|
||||
auto* pred_col =
|
||||
reinterpret_cast<vectorized::PredicateColumnType<TYPE_INT>*>(block[col_idx].get());
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[0]], 0);
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[1]], 1);
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[2]], 2);
|
||||
@ -376,9 +396,12 @@ TEST_F(BlockColumnPredicateTest, AND_OR_MUTI_COLUMN) {
|
||||
}
|
||||
double less_value = 5.0;
|
||||
double great_value = 3.0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<double>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<double>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(new LessPredicate<double>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::GT>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(
|
||||
new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, great_value));
|
||||
|
||||
init_row_block(tablet_schema, size);
|
||||
ColumnBlock col_block = _row_block->column_block(0);
|
||||
@ -422,15 +445,18 @@ TEST_F(BlockColumnPredicateTest, AND_OR_MUTI_COLUMN) {
|
||||
|
||||
TEST_F(BlockColumnPredicateTest, AND_OR_MUTI_COLUMN_VEC) {
|
||||
vectorized::MutableColumns block;
|
||||
block.push_back(vectorized::PredicateColumnType<int>::create());
|
||||
block.push_back(vectorized::PredicateColumnType<TYPE_INT>::create());
|
||||
|
||||
int less_value = 5;
|
||||
int great_value = 3;
|
||||
int rows = 10;
|
||||
int col_idx = 0;
|
||||
std::unique_ptr<ColumnPredicate> less_pred(new LessPredicate<int>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(new GreaterPredicate<int>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(new LessPredicate<int>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(0, less_value));
|
||||
std::unique_ptr<ColumnPredicate> great_pred(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::GT>(0, great_value));
|
||||
std::unique_ptr<ColumnPredicate> less_pred1(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(0, great_value));
|
||||
|
||||
// Test for and or single
|
||||
// (column < 5 or column < 3) and column > 3
|
||||
@ -453,7 +479,8 @@ TEST_F(BlockColumnPredicateTest, AND_OR_MUTI_COLUMN_VEC) {
|
||||
|
||||
selected_size = and_block_column_pred.evaluate(block, sel_idx, selected_size);
|
||||
|
||||
auto* pred_col = reinterpret_cast<vectorized::PredicateColumnType<int>*>(block[col_idx].get());
|
||||
auto* pred_col =
|
||||
reinterpret_cast<vectorized::PredicateColumnType<TYPE_INT>*>(block[col_idx].get());
|
||||
EXPECT_EQ(selected_size, 1);
|
||||
EXPECT_EQ(pred_col->get_data()[sel_idx[0]], 4);
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ TEST_F(TestBloomFilterColumnPredicate, FLOAT_COLUMN) {
|
||||
EXPECT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.1);
|
||||
|
||||
// for vectorized::Block no null
|
||||
auto pred_col = PredicateColumnType<vectorized::Float32>::create();
|
||||
auto pred_col = PredicateColumnType<TYPE_FLOAT>::create();
|
||||
pred_col->reserve(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
*(col_data + i) = i + 0.1f;
|
||||
@ -151,7 +151,7 @@ TEST_F(TestBloomFilterColumnPredicate, FLOAT_COLUMN) {
|
||||
vectorized::ColumnNullable::create(std::move(pred_col), std::move(null_map));
|
||||
select_size = pred->evaluate(*nullable_col, _row_block->selection_vector(), select_size);
|
||||
EXPECT_EQ(select_size, 1);
|
||||
auto nested_col = check_and_get_column<PredicateColumnType<vectorized::Float32>>(
|
||||
auto nested_col = check_and_get_column<PredicateColumnType<TYPE_FLOAT>>(
|
||||
nullable_col->get_nested_column());
|
||||
EXPECT_FLOAT_EQ((float)nested_col->get_data()[_row_block->selection_vector()[0]], 5.1);
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "olap/row_block2.h"
|
||||
#include "olap/wrapper_field.h"
|
||||
#include "runtime/mem_pool.h"
|
||||
#include "runtime/primitive_type.h"
|
||||
#include "runtime/string_value.hpp"
|
||||
#include "util/logging.h"
|
||||
|
||||
@ -129,7 +130,7 @@ TEST_F(TestEqualPredicate, FLOAT_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
float value = 5.0;
|
||||
ColumnPredicate* pred = new EqualPredicate<float>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_FLOAT, PredicateType::EQ>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -173,7 +174,7 @@ TEST_F(TestEqualPredicate, DOUBLE_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
double value = 5.0;
|
||||
ColumnPredicate* pred = new EqualPredicate<double>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::EQ>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -217,7 +218,8 @@ TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
decimal12_t value = {5, 5};
|
||||
ColumnPredicate* pred = new EqualPredicate<decimal12_t>(0, value);
|
||||
ColumnPredicate* pred =
|
||||
new ComparisonPredicateBase<TYPE_DECIMALV2, PredicateType::EQ>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -282,7 +284,7 @@ TEST_F(TestEqualPredicate, STRING_COLUMN) {
|
||||
value.len = 4;
|
||||
value.ptr = const_cast<char*>(value_buffer);
|
||||
|
||||
ColumnPredicate* pred = new EqualPredicate<StringValue>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_STRING, PredicateType::EQ>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -339,7 +341,7 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
uint24_t value = datetime::to_date_timestamp("2017-09-10");
|
||||
ColumnPredicate* pred = new EqualPredicate<uint24_t>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DATE, PredicateType::EQ>(0, value);
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07");
|
||||
@ -397,7 +399,7 @@ TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
uint64_t value = datetime::to_datetime_timestamp("2017-09-10 01:00:00");
|
||||
ColumnPredicate* pred = new EqualPredicate<uint64_t>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DATETIME, PredicateType::EQ>(0, value);
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07 00:00:00");
|
||||
@ -454,7 +456,7 @@ TEST_F(TestLessPredicate, FLOAT_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
float value = 5.0;
|
||||
ColumnPredicate* pred = new LessPredicate<float>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_FLOAT, PredicateType::LT>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -506,7 +508,7 @@ TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
double value = 5.0;
|
||||
ColumnPredicate* pred = new LessPredicate<double>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DOUBLE, PredicateType::LT>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -558,7 +560,8 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
decimal12_t value = {5, 5};
|
||||
ColumnPredicate* pred = new LessPredicate<decimal12_t>(0, value);
|
||||
ColumnPredicate* pred =
|
||||
new ComparisonPredicateBase<TYPE_DECIMALV2, PredicateType::LT>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -606,7 +609,7 @@ TEST_F(TestLessPredicate, STRING_COLUMN) {
|
||||
const char* value_buffer = "dddd";
|
||||
value.len = 4;
|
||||
value.ptr = const_cast<char*>(value_buffer);
|
||||
ColumnPredicate* pred = new LessPredicate<StringValue>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_STRING, PredicateType::LT>(0, value);
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -668,7 +671,7 @@ TEST_F(TestLessPredicate, DATE_COLUMN) {
|
||||
return_columns.push_back(i);
|
||||
}
|
||||
uint24_t value = datetime::to_date_timestamp("2017-09-10");
|
||||
ColumnPredicate* pred = new LessPredicate<uint24_t>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DATE, PredicateType::LT>(0, value);
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07");
|
||||
@ -728,7 +731,7 @@ TEST_F(TestLessPredicate, DATETIME_COLUMN) {
|
||||
}
|
||||
|
||||
uint64_t value = datetime::to_datetime_timestamp("2017-09-10 01:00:00");
|
||||
ColumnPredicate* pred = new LessPredicate<uint64_t>(0, value);
|
||||
ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DATETIME, PredicateType::LT>(0, value);
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07 00:00:00");
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "olap/field.h"
|
||||
#include "olap/row_block2.h"
|
||||
#include "runtime/mem_pool.h"
|
||||
#include "runtime/primitive_type.h"
|
||||
#include "runtime/string_value.hpp"
|
||||
#include "util/logging.h"
|
||||
|
||||
@ -138,7 +139,7 @@ public:
|
||||
std::unique_ptr<Schema> _schema;
|
||||
};
|
||||
|
||||
#define TEST_IN_LIST_PREDICATE_V2(TYPE, TYPE_NAME, FIELD_TYPE) \
|
||||
#define TEST_IN_LIST_PREDICATE_V2(PRIMITIVE_TYPE, TYPE, TYPE_NAME, FIELD_TYPE) \
|
||||
TEST_F(TestInListPredicate, TYPE_NAME##_COLUMN_V2) { \
|
||||
TabletSchemaSPtr tablet_schema = std::make_shared<TabletSchema>(); \
|
||||
SetTabletSchema(std::string("TYPE_NAME##_COLUMN"), FIELD_TYPE, "REPLACE", 1, false, true, \
|
||||
@ -150,7 +151,8 @@ public:
|
||||
values.insert(4); \
|
||||
values.insert(5); \
|
||||
values.insert(6); \
|
||||
ColumnPredicate* pred = new InListPredicate<TYPE>(0, std::move(values)); \
|
||||
ColumnPredicate* pred = new InListPredicateBase<PRIMITIVE_TYPE, PredicateType::IN_LIST>( \
|
||||
0, std::move(values)); \
|
||||
uint16_t sel[10]; \
|
||||
for (int i = 0; i < 10; ++i) { \
|
||||
sel[i] = i; \
|
||||
@ -197,11 +199,11 @@ public:
|
||||
delete pred; \
|
||||
}
|
||||
|
||||
TEST_IN_LIST_PREDICATE_V2(int8_t, TINYINT, "TINYINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(int16_t, SMALLINT, "SMALLINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(int32_t, INT, "INT")
|
||||
TEST_IN_LIST_PREDICATE_V2(int64_t, BIGINT, "BIGINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(int128_t, LARGEINT, "LARGEINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(TYPE_TINYINT, int8_t, TINYINT, "TINYINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(TYPE_SMALLINT, int16_t, SMALLINT, "SMALLINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(TYPE_INT, int32_t, INT, "INT")
|
||||
TEST_IN_LIST_PREDICATE_V2(TYPE_BIGINT, int64_t, BIGINT, "BIGINT")
|
||||
TEST_IN_LIST_PREDICATE_V2(TYPE_LARGEINT, int128_t, LARGEINT, "LARGEINT")
|
||||
|
||||
TEST_F(TestInListPredicate, FLOAT_COLUMN) {
|
||||
TabletSchemaSPtr tablet_schema = std::make_shared<TabletSchema>();
|
||||
@ -215,7 +217,8 @@ TEST_F(TestInListPredicate, FLOAT_COLUMN) {
|
||||
values.insert(4.1);
|
||||
values.insert(5.1);
|
||||
values.insert(6.1);
|
||||
ColumnPredicate* pred = new InListPredicate<float>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_FLOAT, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -265,7 +268,8 @@ TEST_F(TestInListPredicate, DOUBLE_COLUMN) {
|
||||
values.insert(5.1);
|
||||
values.insert(6.1);
|
||||
|
||||
ColumnPredicate* pred = new InListPredicate<double>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_DOUBLE, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -319,7 +323,8 @@ TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
|
||||
decimal12_t value3 = {6, 6};
|
||||
values.insert(value3);
|
||||
|
||||
ColumnPredicate* pred = new InListPredicate<decimal12_t>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_DECIMALV2, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -384,7 +389,8 @@ TEST_F(TestInListPredicate, CHAR_COLUMN) {
|
||||
value3.len = 5;
|
||||
values.insert(value3);
|
||||
|
||||
ColumnPredicate* pred = new InListPredicate<StringValue>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_CHAR, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -461,7 +467,8 @@ TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
|
||||
value3.len = 3;
|
||||
values.insert(value3);
|
||||
|
||||
ColumnPredicate* pred = new InListPredicate<StringValue>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_VARCHAR, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
// for ColumnBlock no null
|
||||
init_row_block(tablet_schema, size);
|
||||
@ -527,7 +534,8 @@ TEST_F(TestInListPredicate, DATE_COLUMN) {
|
||||
|
||||
uint24_t value3 = datetime::timestamp_from_date("2017-09-11");
|
||||
values.insert(value3);
|
||||
ColumnPredicate* pred = new InListPredicate<uint24_t>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_DATE, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07");
|
||||
@ -599,7 +607,8 @@ TEST_F(TestInListPredicate, DATE_V2_COLUMN) {
|
||||
|
||||
uint32_t value3 = datetime::timestamp_from_date_v2("2017-09-11");
|
||||
values.insert(value3);
|
||||
ColumnPredicate* pred = new InListPredicate<uint32_t>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_DATEV2, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07");
|
||||
@ -672,7 +681,8 @@ TEST_F(TestInListPredicate, DATETIME_COLUMN) {
|
||||
uint64_t value3 = datetime::timestamp_from_datetime("2017-09-11 01:01:00");
|
||||
values.insert(value3);
|
||||
|
||||
ColumnPredicate* pred = new InListPredicate<uint64_t>(0, std::move(values));
|
||||
ColumnPredicate* pred =
|
||||
new InListPredicateBase<TYPE_DATETIME, PredicateType::IN_LIST>(0, std::move(values));
|
||||
|
||||
std::vector<std::string> date_array;
|
||||
date_array.push_back("2017-09-07 00:00:00");
|
||||
|
||||
@ -266,7 +266,8 @@ TEST_F(BetaRowsetTest, BasicFunctionTest) {
|
||||
{
|
||||
std::vector<ColumnPredicate*> column_predicates;
|
||||
// column predicate: k1 = 10
|
||||
std::unique_ptr<ColumnPredicate> predicate(new EqualPredicate<int32_t>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(0, 10));
|
||||
column_predicates.emplace_back(predicate.get());
|
||||
reader_context.predicates = &column_predicates;
|
||||
RowsetReaderSharedPtr rowset_reader;
|
||||
@ -350,7 +351,8 @@ TEST_F(BetaRowsetTest, BasicFunctionTest) {
|
||||
{
|
||||
std::vector<ColumnPredicate*> column_predicates;
|
||||
// column predicate: k3 < 100
|
||||
ColumnPredicate* predicate = new LessPredicate<int32_t>(2, 100);
|
||||
ColumnPredicate* predicate =
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::LT>(2, 100);
|
||||
column_predicates.emplace_back(predicate);
|
||||
reader_context.predicates = &column_predicates;
|
||||
RowsetReaderSharedPtr rowset_reader;
|
||||
|
||||
@ -424,7 +424,8 @@ TEST_F(SegmentReaderWriterTest, LazyMaterialization) {
|
||||
// lazy enabled when predicate is subset of returned columns:
|
||||
// select c1, c2 where c2 = 30;
|
||||
Schema read_schema(tablet_schema);
|
||||
std::unique_ptr<ColumnPredicate> predicate(new EqualPredicate<int32_t>(1, 30));
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(1, 30));
|
||||
const std::vector<ColumnPredicate*> predicates = {predicate.get()};
|
||||
|
||||
OlapReaderStatistics stats;
|
||||
@ -448,8 +449,10 @@ TEST_F(SegmentReaderWriterTest, LazyMaterialization) {
|
||||
// lazy disabled when all return columns have predicates:
|
||||
// select c1, c2 where c1 = 10 and c2 = 100;
|
||||
Schema read_schema(tablet_schema);
|
||||
std::unique_ptr<ColumnPredicate> p0(new EqualPredicate<int32_t>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> p1(new EqualPredicate<int32_t>(1, 100));
|
||||
std::unique_ptr<ColumnPredicate> p0(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> p1(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(1, 100));
|
||||
const std::vector<ColumnPredicate*> predicates = {p0.get(), p1.get()};
|
||||
|
||||
OlapReaderStatistics stats;
|
||||
@ -503,7 +506,8 @@ TEST_F(SegmentReaderWriterTest, LazyMaterialization) {
|
||||
// lazy disabled when all predicates are removed by bitmap index:
|
||||
// select c1, c2 where c2 = 30;
|
||||
Schema read_schema(tablet_schema);
|
||||
std::unique_ptr<ColumnPredicate> predicate(new EqualPredicate<int32_t>(0, 20));
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(0, 20));
|
||||
const std::vector<ColumnPredicate*> predicates = {predicate.get()};
|
||||
|
||||
OlapReaderStatistics stats;
|
||||
@ -1153,7 +1157,8 @@ TEST_F(SegmentReaderWriterTest, TestBitmapPredicate) {
|
||||
// test where v1=10
|
||||
{
|
||||
std::vector<ColumnPredicate*> column_predicates;
|
||||
std::unique_ptr<ColumnPredicate> predicate(new EqualPredicate<int32_t>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(0, 10));
|
||||
column_predicates.emplace_back(predicate.get());
|
||||
|
||||
StorageReadOptions read_opts;
|
||||
@ -1174,8 +1179,10 @@ TEST_F(SegmentReaderWriterTest, TestBitmapPredicate) {
|
||||
// test where v1=10 and v2=11
|
||||
{
|
||||
std::vector<ColumnPredicate*> column_predicates;
|
||||
std::unique_ptr<ColumnPredicate> predicate(new EqualPredicate<int32_t>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> predicate2(new EqualPredicate<int32_t>(1, 11));
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> predicate2(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(1, 11));
|
||||
column_predicates.emplace_back(predicate.get());
|
||||
column_predicates.emplace_back(predicate2.get());
|
||||
|
||||
@ -1197,8 +1204,10 @@ TEST_F(SegmentReaderWriterTest, TestBitmapPredicate) {
|
||||
// test where v1=10 and v2=15
|
||||
{
|
||||
std::vector<ColumnPredicate*> column_predicates;
|
||||
std::unique_ptr<ColumnPredicate> predicate(new EqualPredicate<int32_t>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> predicate2(new EqualPredicate<int32_t>(1, 15));
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(0, 10));
|
||||
std::unique_ptr<ColumnPredicate> predicate2(
|
||||
new ComparisonPredicateBase<TYPE_INT, PredicateType::EQ>(1, 15));
|
||||
column_predicates.emplace_back(predicate.get());
|
||||
column_predicates.emplace_back(predicate2.get());
|
||||
|
||||
@ -1224,7 +1233,8 @@ TEST_F(SegmentReaderWriterTest, TestBitmapPredicate) {
|
||||
values.insert(20);
|
||||
values.insert(1);
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new InListPredicate<int32_t>(0, std::move(values)));
|
||||
new InListPredicateBase<TYPE_INT, PredicateType::IN_LIST>(0,
|
||||
std::move(values)));
|
||||
column_predicates.emplace_back(predicate.get());
|
||||
|
||||
StorageReadOptions read_opts;
|
||||
@ -1248,7 +1258,8 @@ TEST_F(SegmentReaderWriterTest, TestBitmapPredicate) {
|
||||
values.insert(10);
|
||||
values.insert(20);
|
||||
std::unique_ptr<ColumnPredicate> predicate(
|
||||
new NotInListPredicate<int32_t>(0, std::move(values)));
|
||||
new InListPredicateBase<TYPE_INT, PredicateType::NOT_IN_LIST>(
|
||||
0, std::move(values)));
|
||||
column_predicates.emplace_back(predicate.get());
|
||||
|
||||
StorageReadOptions read_opts;
|
||||
|
||||
Reference in New Issue
Block a user