15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.List;
25 import com.cloudera.impala.thrift.TExprNode;
26 import com.cloudera.impala.thrift.TExprNodeType;
27 import com.google.common.base.Objects;
28 import com.google.common.base.Preconditions;
29 import com.google.common.collect.Lists;
44 this.description = description;
56 db.addBuiltin(ScalarFunction.createBuiltinOperator(
57 Operator.AND.name(),
"",
59 db.addBuiltin(ScalarFunction.createBuiltinOperator(
60 Operator.OR.name(),
"",
62 db.addBuiltin(ScalarFunction.createBuiltinOperator(
63 Operator.NOT.name(),
"impala::CompoundPredicate::Not",
70 Preconditions.checkNotNull(e1);
72 Preconditions.checkArgument(op == Operator.NOT && e2 == null
73 || op != Operator.NOT && e2 != null);
74 if (e2 != null) children_.add(e2);
89 if (!super.equals(obj))
return false;
95 return Objects.toStringHelper(
this)
97 .addValue(super.debugString())
103 if (children_.size() == 1) {
105 return "NOT " + getChild(0).toSql();
107 return getChild(0).toSql() +
" " +
op_.
toString() +
" " + getChild(1).toSql();
113 msg.node_type = TExprNodeType.COMPOUND_PRED;
119 super.analyze(analyzer);
122 for (
Expr e: children_) {
123 if (!e.getType().isBoolean() && !e.getType().isNull()) {
125 "'%s' should return type 'BOOLEAN' but returns type '%s'.",
132 Preconditions.checkState(
fn_ != null);
133 Preconditions.checkState(fn_.getReturnType().isBoolean());
137 || children_.size() == 2 && getChild(1).selectivity_ == -1) {
145 selectivity_ = getChild(0).selectivity_ * getChild(1).selectivity_;
148 selectivity_ = getChild(0).selectivity_ + getChild(1).selectivity_
149 - getChild(0).selectivity_ * getChild(1).selectivity_;
163 ArrayList<SlotRef> slots = Lists.newArrayList();
164 for (
int i = 0; i < getChildren().size(); ++i) {
181 Expr negatedLeft = getChild(0).negate();
182 Expr negatedRight = getChild(1).negate();
191 Expr conjunctivePred = null;
192 for (
Expr expr: conjuncts) {
193 if (conjunctivePred == null) {
194 conjunctivePred = expr;
198 expr, conjunctivePred);
200 return conjunctivePred;
209 if (rhs == null)
return lhs;
void toThrift(TExprNode msg)
void analyze(Analyzer analyzer)
void castForFunctionCall(boolean ignoreWildcardDecimals)
CompoundPredicate(CompoundPredicate other)
static final ScalarType BOOLEAN
static Expr createConjunction(Expr lhs, Expr rhs)
Type[] collectChildReturnTypes()
static void initBuiltins(Db db)
CompoundPredicate(Operator op, Expr e1, Expr e2)
Function getBuiltinFunction(Analyzer analyzer, String name, Type[] argTypes, CompareMode mode)
Operator(String description)
static Expr createConjunctivePredicate(List< Expr > conjuncts)
boolean equals(Object obj)
ArrayList< SlotRef > getBoundSlots()