Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
like-predicate.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_EXPRS_LIKE_PREDICATE_H_
17 #define IMPALA_EXPRS_LIKE_PREDICATE_H_
18 
19 #include <boost/scoped_ptr.hpp>
20 #include <re2/re2.h>
21 #include <string>
22 
23 #include "exprs/predicate.h"
24 #include "gen-cpp/Exprs_types.h"
25 #include "runtime/string-search.h"
26 #include "udf/udf.h"
27 
28 namespace re2 {
29 class RE2;
30 }
31 
32 namespace impala {
33 
35 class LikePredicate: public Predicate {
36  public:
38 
39  protected:
40  friend class Expr;
41  LikePredicate(const TExprNode& node);
42 
43  private:
46 
49 
58 
60  std::string search_string_;
61 
67 
72 
74  boost::scoped_ptr<re2::RE2> regex_;
75 
77  }
78 
79  void SetSearchString(const std::string& search_string) {
80  search_string_ = search_string;
81  search_string_sv_ = StringValue(search_string);
83  }
84  };
85 
86  friend class OpcodeRegistry;
87 
88  static void LikePrepare(impala_udf::FunctionContext* context,
90 
92  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
93 
94  static void LikeClose(impala_udf::FunctionContext* context,
96 
97  static void RegexPrepare(impala_udf::FunctionContext* context,
99 
101  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
102 
105 
107  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
108 
110  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
111 
114  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
115 
118  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
119 
122  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
123 
126  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
127 
130  const impala_udf::StringVal& pattern);
131 
133  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern);
134 
136  const impala_udf::StringVal& val, const impala_udf::StringVal& pattern,
137  bool is_like_pattern);
138 
141  static void ConvertLikePattern(impala_udf::FunctionContext* context,
142  const impala_udf::StringVal& pattern, std::string* re_pattern);
143 };
144 
145 } // namespace impala
146 
147 #endif // IMPALA_EXPRS_LIKE_PREDICATE_H_
std::string search_string_
Holds the string the StringValue points to and is set any time StringValue is used.
static impala_udf::BooleanVal ConstantStartsWithFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
Handling of like predicates that can be implemented using strncmp.
static void LikePrepare(impala_udf::FunctionContext *context, impala_udf::FunctionContext::FunctionStateScope scope)
LikePredicate(const TExprNode &node)
static impala_udf::BooleanVal ConstantEndsWithFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
Handling of like predicates that can be implemented using strncmp.
This class handles the Like, Regexp, and Rlike predicates and uses the udf interface.
static impala_udf::BooleanVal ConstantSubstringFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
Handling of like predicates that map to strstr.
static void RegexClose(impala_udf::FunctionContext *, impala_udf::FunctionContext::FunctionStateScope scope)
static impala_udf::BooleanVal ConstantRegexFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
boost::scoped_ptr< re2::RE2 > regex_
Used for RLIKE and REGEXP predicates if the pattern is a constant aruement.
static impala_udf::BooleanVal Like(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
static impala_udf::BooleanVal ConstantEqualsFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
Handling of like predicates that can be implemented using strcmp.
static void RegexPrepare(impala_udf::FunctionContext *context, impala_udf::FunctionContext::FunctionStateScope scope)
static impala_udf::BooleanVal RegexMatch(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern, bool is_like_pattern)
static void ConvertLikePattern(impala_udf::FunctionContext *context, const impala_udf::StringVal &pattern, std::string *re_pattern)
static impala_udf::BooleanVal Regex(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
This is the superclass of all expr evaluation nodes.
Definition: expr.h:116
friend class OpcodeRegistry
static impala_udf::BooleanVal ConstantRegexFnPartial(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
impala_udf::BooleanVal(* LikePredicateFunction)(impala_udf::FunctionContext *, const impala_udf::StringVal &, const impala_udf::StringVal &)
void SetSearchString(const std::string &search_string)
static impala_udf::BooleanVal LikeFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)
static void LikeClose(impala_udf::FunctionContext *context, impala_udf::FunctionContext::FunctionStateScope scope)
static impala_udf::BooleanVal RegexFn(impala_udf::FunctionContext *context, const impala_udf::StringVal &val, const impala_udf::StringVal &pattern)