Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ExistsPredicate.java
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 package com.cloudera.impala.analysis;
16 
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 
21 import com.cloudera.impala.thrift.TExprNode;
22 import com.google.common.base.Preconditions;
23 
27 public class ExistsPredicate extends Predicate {
28  private final static Logger LOG = LoggerFactory.getLogger(
29  ExistsPredicate.class);
30  private boolean notExists_ = false;
31 
32  public boolean isNotExists() { return notExists_; }
33 
37  public ExistsPredicate(Subquery subquery, boolean notExists) {
38  Preconditions.checkNotNull(subquery);
39  children_.add(subquery);
40  notExists_ = notExists;
41  }
42 
43  @Override
44  public Expr negate() {
45  return new ExistsPredicate((Subquery)getChild(0), !notExists_);
46  }
47 
52  super(other);
53  notExists_ = other.notExists_;
54  }
55 
56  @Override
57  public void analyze(Analyzer analyzer) throws AnalysisException {
58  if (isAnalyzed_) return;
59  super.analyze(analyzer);
60  }
61 
62  @Override
63  protected void toThrift(TExprNode msg) {
64  // Cannot serialize a nested predicate
65  Preconditions.checkState(false);
66  }
67 
68  @Override
69  public Expr clone() { return new ExistsPredicate(this); }
70 
71  @Override
72  public String toSqlImpl() {
73  StringBuilder strBuilder = new StringBuilder();
74  if (notExists_) strBuilder.append("NOT ");
75  strBuilder.append("EXISTS ");
76  strBuilder.append(getChild(0).toSql());
77  return strBuilder.toString();
78  }
79 }
ExistsPredicate(Subquery subquery, boolean notExists)