This is an automated email from the ASF dual-hosted git repository.

wyf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new af06adb  [Doris On ES][Bug-fix] fix boolean predicate pushdown manner 
(#4990)
af06adb is described below

commit af06adb57fbaf306534971bae8cf11162d714404
Author: Yunfeng,Wu <wuyunfen...@baidu.com>
AuthorDate: Wed Dec 2 10:13:13 2020 +0800

    [Doris On ES][Bug-fix] fix boolean predicate pushdown manner (#4990)
    
    Correct handling `boolean` field predicate through set the predicate value 
to `true`、`false` or `empty set` for DOE
---
 be/src/exec/es/es_query_builder.cpp | 32 ++++++++++++++++++++++++++------
 be/src/exec/es/es_query_builder.h   |  1 +
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/be/src/exec/es/es_query_builder.cpp 
b/be/src/exec/es/es_query_builder.cpp
index a75ed0e..4149d3a 100644
--- a/be/src/exec/es/es_query_builder.cpp
+++ b/be/src/exec/es/es_query_builder.cpp
@@ -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)
diff --git a/be/src/exec/es/es_query_builder.h 
b/be/src/exec/es/es_query_builder.h
index 6fb66bf..c471380 100644
--- a/be/src/exec/es/es_query_builder.h
+++ b/be/src/exec/es/es_query_builder.h
@@ -53,6 +53,7 @@ public:
 private:
     std::string _field;
     std::string _term;
+    bool _match_none;
 };
 
 // process range predicate field >= value or field < value etc.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to