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
32 changes: 26 additions & 6 deletions be/src/exec/es/es_query_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,39 @@ void ESQueryBuilder::to_json(rapidjson::Document* document, rapidjson::Value* qu
}

TermQueryBuilder::TermQueryBuilder(const std::string& field, const std::string& term)
: _field(field), _term(term) {}
: _field(field), _term(term), _match_none(false) {}

TermQueryBuilder::TermQueryBuilder(const ExtBinaryPredicate& binary_predicate)
: _field(binary_predicate.col.name), _term(binary_predicate.value.to_string()) {}
: _field(binary_predicate.col.name), _match_none(false) {
if (binary_predicate.col.type.type == PrimitiveType::TYPE_BOOLEAN) {
int val = atoi(binary_predicate.value.to_string().c_str());
if (val == 1) {
_term = std::string("true");
} else if (val == 0){
_term = std::string("false");
} else {
// keep semantic consistent with mysql
_match_none = true;
}
} else {
_term = binary_predicate.value.to_string();
}
}

void TermQueryBuilder::to_json(rapidjson::Document* document, rapidjson::Value* query) {
rapidjson::Document::AllocatorType& allocator = document->GetAllocator();
rapidjson::Value term_node(rapidjson::kObjectType);
term_node.SetObject();
rapidjson::Value field_value(_field.c_str(), allocator);
rapidjson::Value term_value(_term.c_str(), allocator);
term_node.AddMember(field_value, term_value, allocator);
query->AddMember("term", term_node, allocator);
if (!_match_none) {
rapidjson::Value field_value(_field.c_str(), allocator);
rapidjson::Value term_value(_term.c_str(), allocator);
term_node.AddMember(field_value, term_value, allocator);
query->AddMember("term", term_node, allocator);
} else {
// this would only appear `bool` column's predicate (a = 2)
query->AddMember("match_none", term_node, allocator);
}

}

RangeQueryBuilder::RangeQueryBuilder(const ExtBinaryPredicate& range_predicate)
Expand Down
1 change: 1 addition & 0 deletions be/src/exec/es/es_query_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class TermQueryBuilder : public QueryBuilder {
private:
std::string _field;
std::string _term;
bool _match_none;
};

// process range predicate field >= value or field < value etc.
Expand Down