You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2019/04/23 07:07:17 UTC

[GitHub] [incubator-doris] imay commented on a change in pull request #925: Doris on ES by HTTP way

imay commented on a change in pull request #925: Doris on ES by HTTP way
URL: https://github.com/apache/incubator-doris/pull/925#discussion_r277540540
 
 

 ##########
 File path: be/src/exec/es_predicate.cpp
 ##########
 @@ -0,0 +1,421 @@
+// 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 "exec/es_predicate.h"
+
+#include <stdint.h>
+#include <map>
+#include <sstream>
+#include <boost/algorithm/string.hpp>
+#include <gutil/strings/substitute.h>
+
+#include "common/status.h"
+#include "common/logging.h"
+#include "exprs/expr.h"
+#include "exprs/expr_context.h"
+#include "exprs/in_predicate.h"
+
+#include "gen_cpp/PlanNodes_types.h"
+#include "olap/olap_common.h"
+#include "olap/utils.h"
+#include "runtime/client_cache.h"
+#include "runtime/runtime_state.h"
+#include "runtime/row_batch.h"
+#include "runtime/datetime_value.h"
+#include "runtime/large_int_value.h"
+#include "runtime/string_value.h"
+#include "runtime/tuple_row.h"
+
+#include "service/backend_options.h"
+#include "util/debug_util.h"
+#include "util/es_query_builder.h"
+#include "util/runtime_profile.h"
+
+namespace doris {
+
+using namespace std;
+
+std::string ExtLiteral::value_to_string() {
+    std::stringstream ss;
+    switch (_type) {
+        case TYPE_TINYINT:
+            ss << std::to_string(get_byte());
+            break;
+        case TYPE_SMALLINT:
+            ss << std::to_string(get_short());
+            break;
+        case TYPE_INT:
+            ss << std::to_string(get_int());
+            break;
+        case TYPE_BIGINT:
+            ss << std::to_string(get_long());
+            break;
+        case TYPE_FLOAT:
+            ss << std::to_string(get_float());
+            break;
+        case TYPE_DOUBLE:
+            ss << std::to_string(get_double());
+            break;
+        case TYPE_CHAR:
+        case TYPE_VARCHAR:
+            ss << get_string();
+            break;
+        case TYPE_DATE:
+        case TYPE_DATETIME:
+            ss << get_date_string();
+            break;
+        case TYPE_BOOLEAN:
+            ss << std::to_string(get_bool());
+            break;
+        case TYPE_DECIMAL:
+            ss << get_decimal_string();
+            break;
+        case TYPE_DECIMALV2:
+            ss << get_decimalv2_string();
+            break;
+        case TYPE_LARGEINT:
+            ss << get_largeint_string();
+            break;
+        default:
+            DCHECK(false);
+            break;
+    }
+    return ss.str();
+}
+
+ExtLiteral::~ExtLiteral(){
+}
+
+int8_t ExtLiteral::get_byte() {
+    DCHECK(_type == TYPE_TINYINT);
+    return *(reinterpret_cast<int8_t*>(_value));
+}
+
+int16_t ExtLiteral::get_short() {
+    DCHECK(_type == TYPE_SMALLINT);
+    return *(reinterpret_cast<int16_t*>(_value));
+}
+
+int32_t ExtLiteral::get_int() {
+    DCHECK(_type == TYPE_INT);
+    return *(reinterpret_cast<int32_t*>(_value));
+}
+
+int64_t ExtLiteral::get_long() {
+    DCHECK(_type == TYPE_BIGINT);
+    return *(reinterpret_cast<int64_t*>(_value));
+}
+
+float ExtLiteral::get_float() {
+    DCHECK(_type == TYPE_FLOAT);
+    return *(reinterpret_cast<float*>(_value));
+}
+
+double ExtLiteral::get_double() {
+    DCHECK(_type == TYPE_DOUBLE);
+    return *(reinterpret_cast<double*>(_value));
+}
+
+std::string ExtLiteral::get_string() {
+    DCHECK(_type == TYPE_VARCHAR || _type == TYPE_CHAR);
+    return (reinterpret_cast<StringValue*>(_value))->to_string();
+}
+
+std::string ExtLiteral::get_date_string() {
+    DCHECK(_type == TYPE_DATE || _type == TYPE_DATETIME);
+    DateTimeValue date_value = *reinterpret_cast<DateTimeValue*>(_value);
+    if (_type == TYPE_DATE) {
+        date_value.cast_to_date();
+    }
+
+    char str[MAX_DTVALUE_STR_LEN];
+    date_value.to_string(str);
+    return std::string(str, strlen(str)); 
+}
+
+bool ExtLiteral::get_bool() {
+    DCHECK(_type == TYPE_BOOLEAN);
+    return *(reinterpret_cast<bool*>(_value));
+}
+
+std::string ExtLiteral::get_decimal_string() {
+    DCHECK(_type == TYPE_DECIMAL);
+    return reinterpret_cast<DecimalValue*>(_value)->to_string();
+}
+
+std::string ExtLiteral::get_decimalv2_string() {
+    DCHECK(_type == TYPE_DECIMALV2);
+    return reinterpret_cast<DecimalV2Value*>(_value)->to_string();
+}
+
+std::string ExtLiteral::get_largeint_string() {
+    DCHECK(_type == TYPE_LARGEINT);
+    return LargeIntValue::to_string(*reinterpret_cast<__int128*>(_value));
+}
+
+EsPredicate::EsPredicate(ExprContext* context,
+            const TupleDescriptor* tuple_desc) :
+    _context(context),
+    _disjuncts_num(0),
+    _tuple_desc(tuple_desc),
+    _es_query_status(Status::OK) {
+}
+
+EsPredicate::~EsPredicate() {
+    for(int i=0; i < _disjuncts.size(); i++) {
+        delete _disjuncts[i];
+    }
+    _disjuncts.clear();
+}
+
+bool EsPredicate::build_disjuncts_list() {
+    return build_disjuncts_list(_context->root());
+}
+
+// make sure to build by build_disjuncts_list
+const vector<ExtPredicate*>& EsPredicate::get_predicate_list(){
+    return _disjuncts;
+}
+
+static bool ignore_cast(const SlotDescriptor* slot, const Expr* expr) {
+    if (slot->type().is_date_type() && expr->type().is_date_type()) {
+        return true;
+    }
+    if (slot->type().is_string_type() && expr->type().is_string_type()) {
+        return true;
+    }
+    return false;
+}
+
+static bool is_literal_node(const Expr* expr) {
+    switch (expr->node_type()) {
+        case TExprNodeType::BOOL_LITERAL:
+        case TExprNodeType::INT_LITERAL:
+        case TExprNodeType::LARGE_INT_LITERAL:
+        case TExprNodeType::FLOAT_LITERAL:
+        case TExprNodeType::DECIMAL_LITERAL:
+        case TExprNodeType::STRING_LITERAL:
+        case TExprNodeType::DATE_LITERAL:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool EsPredicate::build_disjuncts_list(const Expr* conjunct) {
 
 Review comment:
   why return `bool`? I think `Status` can give caller more information about failure

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org