Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions be/src/core/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,20 @@ std::string Field::get_type_name() const {

template <PrimitiveType T>
typename PrimitiveTypeTraits<T>::CppType& Field::get() {
DCHECK(T == type || (is_string_type(type) && is_string_type(T)) || type == TYPE_NULL)
<< "Type mismatch: requested " << type_to_string(T) << ", actual " << get_type_name();
if (T != type && !(is_string_type(type) && is_string_type(T)) && type != TYPE_NULL) {
throw Exception(Status::FatalError("Field::get type mismatch: requested {}, actual {}",
type_to_string(T), get_type_name()));
}
auto* MAY_ALIAS ptr = reinterpret_cast<typename PrimitiveTypeTraits<T>::CppType*>(&storage);
return *ptr;
}

template <PrimitiveType T>
const typename PrimitiveTypeTraits<T>::CppType& Field::get() const {
DCHECK(T == type || (is_string_type(type) && is_string_type(T)) || type == TYPE_NULL)
<< "Type mismatch: requested " << type_to_string(T) << ", actual " << get_type_name();
if (T != type && !(is_string_type(type) && is_string_type(T)) && type != TYPE_NULL) {
throw Exception(Status::FatalError("Field::get type mismatch: requested {}, actual {}",
type_to_string(T), get_type_name()));
}
const auto* MAY_ALIAS ptr =
reinterpret_cast<const typename PrimitiveTypeTraits<T>::CppType*>(&storage);
return *ptr;
Expand Down
7 changes: 2 additions & 5 deletions be/src/exprs/function/array/function_array_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "core/data_type/data_type_number.h" // IWYU pragma: keep
#include "core/data_type/define_primitive_type.h"
#include "core/data_type/primitive_type.h"
#include "core/field.h"
#include "core/string_ref.h"
#include "core/types.h"
#include "exprs/function/function.h"
Expand Down Expand Up @@ -151,7 +152,6 @@ class FunctionArrayIndex : public IFunction {
}
Field param_value;
arguments[0].column->get(0, param_value);
auto param_type = arguments[0].type->get_primitive_type();
// The current implementation for the inverted index of arrays cannot handle cases where the array contains null values,
// meaning an item in the array is null.
if (param_value.is_null()) {
Expand All @@ -164,13 +164,10 @@ class FunctionArrayIndex : public IFunction {
RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
null_bitmap = null_bitmap_cache_handle.get_bitmap();
}
std::unique_ptr<InvertedIndexQueryParamFactory> query_param = nullptr;
RETURN_IF_ERROR(InvertedIndexQueryParamFactory::create_query_value(param_type, &param_value,
query_param));
InvertedIndexParam param;
param.column_name = data_type_with_name.first;
param.column_type = data_type_with_name.second;
param.query_value = query_param->get_value();
param.query_value = param_value;
param.query_type = segment_v2::InvertedIndexQueryType::EQUAL_QUERY;
param.num_rows = num_rows;
param.roaring = std::make_shared<roaring::Roaring>();
Expand Down
9 changes: 1 addition & 8 deletions be/src/exprs/function/array/function_arrays_overlap.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ class FunctionArraysOverlap : public IFunction {
Field param_value;
arguments[0].column->get(0, param_value);
DCHECK(arguments[0].type->get_primitive_type() == TYPE_ARRAY);
auto nested_param_type =
check_and_get_data_type<DataTypeArray>(remove_nullable(arguments[0].type).get())
->get_nested_type()
->get_primitive_type();
// The current implementation for the inverted index of arrays cannot handle cases where the array contains null values,
// meaning an item in the array is null.
if (param_value.is_null()) {
Expand All @@ -246,7 +242,6 @@ class FunctionArraysOverlap : public IFunction {
RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
null_bitmap = null_bitmap_cache_handle.get_bitmap();
}
std::unique_ptr<InvertedIndexQueryParamFactory> query_param = nullptr;
const Array& query_val = param_value.get<TYPE_ARRAY>();

InvertedIndexParam param;
Expand All @@ -260,9 +255,7 @@ class FunctionArraysOverlap : public IFunction {
if (nested_query_val.is_null()) {
return Status::OK();
}
RETURN_IF_ERROR(InvertedIndexQueryParamFactory::create_query_value(
nested_param_type, &nested_query_val, query_param));
param.query_value = query_param->get_value();
param.query_value = nested_query_val;
param.roaring = std::make_shared<roaring::Roaring>();
param.analyzer_ctx = analyzer_ctx;
RETURN_IF_ERROR(iter->read_from_index(segment_v2::IndexParam {&param}));
Expand Down
12 changes: 3 additions & 9 deletions be/src/exprs/function/function_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "core/data_type/data_type_number.h"
#include "core/data_type/data_type_string.h"
#include "core/data_type/data_type_struct.h"
#include "core/field.h"
#include "core/types.h"
#include "core/value/ip_address_cidr.h"
#include "exec/common/endian.h"
Expand Down Expand Up @@ -707,29 +708,22 @@ class FunctionIsIPAddressInRange : public IFunction {
// apply for inverted index
std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>();

auto param_type = data_type_with_name.second->get_primitive_type();
std::unique_ptr<segment_v2::InvertedIndexQueryParamFactory> query_param = nullptr;

// >= min ip
RETURN_IF_ERROR(segment_v2::InvertedIndexQueryParamFactory::create_query_value(
param_type, &min_ip, query_param));
segment_v2::InvertedIndexParam min_param;
min_param.column_name = data_type_with_name.first;
min_param.column_type = data_type_with_name.second;
min_param.query_type = segment_v2::InvertedIndexQueryType::GREATER_EQUAL_QUERY;
min_param.query_value = query_param->get_value();
min_param.query_value = min_ip;
min_param.num_rows = num_rows;
min_param.roaring = std::make_shared<roaring::Roaring>();
RETURN_IF_ERROR(iter->read_from_index(&min_param));

// <= max ip
RETURN_IF_ERROR(segment_v2::InvertedIndexQueryParamFactory::create_query_value(
param_type, &max_ip, query_param));
segment_v2::InvertedIndexParam max_param;
max_param.column_name = data_type_with_name.first;
max_param.column_type = data_type_with_name.second;
max_param.query_type = segment_v2::InvertedIndexQueryType::LESS_EQUAL_QUERY;
max_param.query_value = query_param->get_value();
max_param.query_value = max_ip;
max_param.num_rows = num_rows;
max_param.roaring = std::make_shared<roaring::Roaring>();
RETURN_IF_ERROR(iter->read_from_index(&max_param));
Expand Down
7 changes: 2 additions & 5 deletions be/src/exprs/function/function_multi_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "core/column/column.h"
#include "core/field.h"
#include "exprs/function/simple_function_factory.h"
#include "exprs/vslot_ref.h"
#include "io/fs/file_reader.h"
Expand Down Expand Up @@ -79,13 +80,9 @@ Status FunctionMultiMatch::evaluate_inverted_index(
return Status::Error<ErrorCode::INDEX_INVALID_PARAMETERS>(
"arguments for multi_match must be string");
}
// Must convert StringRef to std::string because downstream readers
// (e.g. FullTextIndexReader::query) reinterpret_cast query_value as std::string*.
std::string query_str(query_str_ref.data, query_str_ref.size);

// search
InvertedIndexParam param;
param.query_value = &query_str;
param.query_value = Field::create_field<TYPE_STRING>(query_str_ref.to_string());
param.query_type = query_type;
param.num_rows = num_rows;
for (size_t i = 0; i < data_type_with_names.size(); i++) {
Expand Down
8 changes: 2 additions & 6 deletions be/src/exprs/function/functions_comparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/data_type/data_type_string.h"
#include "core/data_type/define_primitive_type.h"
#include "core/decimal_comparison.h"
#include "core/field.h"
#include "core/memcmp_small.h"
#include "core/value/vdatetime_value.h"
#include "exprs/function/function.h"
Expand Down Expand Up @@ -486,15 +487,10 @@ class FunctionComparison : public IFunction {
if (param_value.is_null()) {
return Status::OK();
}
auto param_type = arguments[0].type->get_primitive_type();
std::unique_ptr<segment_v2::InvertedIndexQueryParamFactory> query_param = nullptr;
RETURN_IF_ERROR(segment_v2::InvertedIndexQueryParamFactory::create_query_value(
param_type, &param_value, query_param));

segment_v2::InvertedIndexParam param;
param.column_name = data_type_with_name.first;
param.column_type = data_type_with_name.second;
param.query_value = query_param->get_value();
param.query_value = param_value;
param.query_type = query_type;
param.num_rows = num_rows;
param.roaring = std::make_shared<roaring::Roaring>();
Expand Down
7 changes: 2 additions & 5 deletions be/src/exprs/function/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "core/data_type/data_type_nullable.h"
#include "core/data_type/data_type_number.h"
#include "core/data_type/define_primitive_type.h"
#include "core/field.h"
#include "core/string_ref.h"
#include "core/types.h"
#include "exprs/aggregate/aggregate_function.h"
Expand Down Expand Up @@ -161,7 +162,6 @@ class FunctionIn : public IFunction {
for (const auto& arg : arguments) {
Field param_value;
arg.column->get(0, param_value);
auto param_type = arg.type->get_primitive_type();
if (param_value.is_null()) {
// predicate like column NOT IN (NULL, '') should not push down to index.
if (negative) {
Expand All @@ -170,14 +170,11 @@ class FunctionIn : public IFunction {
*roaring |= *null_bitmap;
continue;
}
std::unique_ptr<InvertedIndexQueryParamFactory> query_param = nullptr;
RETURN_IF_ERROR(InvertedIndexQueryParamFactory::create_query_value(
param_type, &param_value, query_param));
InvertedIndexQueryType query_type = InvertedIndexQueryType::EQUAL_QUERY;
segment_v2::InvertedIndexParam param;
param.column_name = data_type_with_name.first;
param.column_type = data_type_with_name.second;
param.query_value = query_param->get_value();
param.query_value = param_value;
param.query_type = query_type;
param.num_rows = num_rows;
param.roaring = std::make_shared<roaring::Roaring>();
Expand Down
7 changes: 2 additions & 5 deletions be/src/exprs/function/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <hs/hs.h>

#include "core/field.h"
#include "runtime/query_context.h"
#include "runtime/runtime_state.h"
#include "storage/index/index_reader_helper.h"
Expand Down Expand Up @@ -79,14 +80,10 @@ Status FunctionMatchBase::evaluate_inverted_index(
return Status::Error<ErrorCode::INDEX_INVALID_PARAMETERS>(
"arguments for match must be string");
}
std::unique_ptr<InvertedIndexQueryParamFactory> query_param = nullptr;
RETURN_IF_ERROR(InvertedIndexQueryParamFactory::create_query_value(param_type, &param_value,
query_param));

InvertedIndexParam param;
param.column_name = data_type_with_name.first;
param.column_type = data_type_with_name.second;
param.query_value = query_param->get_value();
param.query_value = param_value;
param.query_type = get_query_type_from_fn_name();
param.num_rows = num_rows;
param.roaring = std::make_shared<roaring::Roaring>();
Expand Down
23 changes: 2 additions & 21 deletions be/src/storage/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class StorageField {
const std::string& name() const { return _name; }
const PathInDataPtr& path() const { return _path; }

virtual void set_to_max(char* buf) const { return _type_info->set_to_max(buf); }

virtual void set_to_min(char* buf) const { return _type_info->set_to_min(buf); }

virtual StorageField* clone() const {
auto* local = new StorageField(_desc);
this->clone(local);
Expand All @@ -88,6 +84,8 @@ class StorageField {
void full_encode_ascending(const void* value, std::string* buf) const {
_key_coder->full_encode_ascending(value, buf);
}

const KeyCoder* key_coder() const { return _key_coder; }
void add_sub_field(std::unique_ptr<StorageField> sub_field) {
_sub_fields.emplace_back(std::move(sub_field));
}
Expand Down Expand Up @@ -172,12 +170,6 @@ class CharField : public StorageField {
StorageField::clone(local);
return local;
}

void set_to_max(char* ch) const override {
auto slice = reinterpret_cast<Slice*>(ch);
slice->size = _length;
memset(slice->data, 0xFF, slice->size);
}
};

class VarcharField : public StorageField {
Expand All @@ -189,12 +181,6 @@ class VarcharField : public StorageField {
StorageField::clone(local);
return local;
}

void set_to_max(char* ch) const override {
auto slice = reinterpret_cast<Slice*>(ch);
slice->size = _length - OLAP_VARCHAR_MAX_BYTES;
memset(slice->data, 0xFF, slice->size);
}
};
class StringField : public StorageField {
public:
Expand All @@ -205,11 +191,6 @@ class StringField : public StorageField {
StorageField::clone(local);
return local;
}

void set_to_max(char* ch) const override {
auto slice = reinterpret_cast<Slice*>(ch);
memset(slice->data, 0xFF, slice->size);
}
};

class BitmapAggField : public StorageField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Result<bool> InvertedIndexIterator::has_null() {

Status InvertedIndexIterator::try_read_from_inverted_index(const InvertedIndexReaderPtr& reader,
const std::string& column_name,
const void* query_value,
const Field& query_value,
InvertedIndexQueryType query_type,
size_t* count) {
// NOTE: only bkd index support try read now.
Expand Down
5 changes: 3 additions & 2 deletions be/src/storage/index/inverted/inverted_index_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unordered_map>
#include <vector>

#include "core/field.h"
#include "storage/index/analyzer_key_matcher.h"
#include "storage/index/index_iterator.h"
#include "storage/index/inverted/inverted_index_parser.h"
Expand All @@ -29,7 +30,7 @@ namespace doris::segment_v2 {
struct InvertedIndexParam {
std::string column_name;
DataTypePtr column_type;
const void* query_value;
Field query_value;
InvertedIndexQueryType query_type;
uint32_t num_rows;
std::shared_ptr<roaring::Roaring> roaring;
Expand Down Expand Up @@ -73,7 +74,7 @@ class InvertedIndexIterator : public IndexIterator {
ENABLE_FACTORY_CREATOR(InvertedIndexIterator);

Status try_read_from_inverted_index(const InvertedIndexReaderPtr& reader,
const std::string& column_name, const void* query_value,
const std::string& column_name, const Field& query_value,
InvertedIndexQueryType query_type, size_t* count);

// Normalize analyzer_key to lowercase.
Expand Down
Loading
Loading