Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tuple-is-null-predicate.cc
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 
16 
17 #include <sstream>
18 
19 #include "gen-cpp/Exprs_types.h"
20 
21 #include "common/names.h"
22 
23 namespace impala {
24 
26  bool result = true;
27  for (int i = 0; i < tuple_idxs_.size(); ++i) {
28  if (row->GetTuple(tuple_idxs_[i]) != NULL) {
29  result = false;
30  break;
31  }
32  }
33  return BooleanVal(result);
34 }
35 
37  : Predicate(node),
38  tuple_ids_(node.tuple_is_null_pred.tuple_ids.begin(),
39  node.tuple_is_null_pred.tuple_ids.end()) {
40 }
41 
43  ExprContext* ctx) {
44  RETURN_IF_ERROR(Expr::Prepare(state, row_desc, ctx));
45  DCHECK_EQ(0, children_.size());
46  // Resolve tuple ids to tuple indexes.
47  for (int i = 0; i < tuple_ids_.size(); ++i) {
48  int32_t tuple_idx = row_desc.GetTupleIdx(tuple_ids_[i]);
49  if (tuple_idx == RowDescriptor::INVALID_IDX) {
50  // This should not happen and indicates a planner issue. This code is tricky
51  // so rather than crashing, do this as a stop gap.
52  // TODO: remove this code and replace with DCHECK.
53  return Status("Invalid plan. TupleIsNullPredicate has invalid tuple idx.");
54  }
55  if (row_desc.TupleIsNullable(tuple_idx)) tuple_idxs_.push_back(tuple_idx);
56  }
57  return Status::OK;
58 }
59 
61  llvm::Function** fn) {
62  return GetCodegendComputeFnWrapper(state, fn);
63 }
64 
66  stringstream out;
67  out << "TupleIsNullPredicate(tupleids=[";
68  for (int i = 0; i < tuple_ids_.size(); ++i) {
69  out << (i == 0 ? "" : " ") << tuple_ids_[i];
70  }
71  out << "])";
72  return out.str();
73 }
74 
75 }
Tuple * GetTuple(int tuple_idx)
Definition: tuple-row.h:30
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Definition: status.h:242
virtual std::string DebugString() const
bool TupleIsNullable(int tuple_idx) const
Return true if the Tuple of the given Tuple index is nullable.
Definition: descriptors.cc:333
static const int INVALID_IDX
Definition: descriptors.h:400
virtual BooleanVal GetBooleanVal(ExprContext *context, TupleRow *row)
std::vector< int32_t > tuple_idxs_
Tuple indexes into the RowDescriptor. Only contains indexes of nullable tuples.
Status GetCodegendComputeFnWrapper(RuntimeState *state, llvm::Function **fn)
Definition: expr.cc:546
int GetTupleIdx(TupleId id) const
Returns INVALID_IDX if id not part of this row.
Definition: descriptors.cc:328
const RowDescriptor & row_desc() const
static const Status OK
Definition: status.h:87
std::vector< TupleId > tuple_ids_
Tuple ids to check for NULL. May contain ids of nullable and non-nullable tuples. ...
TupleIsNullPredicate(const TExprNode &node)
virtual Status Prepare(RuntimeState *state, const RowDescriptor &row_desc, ExprContext *ctx)
static Status Prepare(const std::vector< ExprContext * > &ctxs, RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
virtual Status GetCodegendComputeFn(RuntimeState *state, llvm::Function **fn)
std::vector< Expr * > children_
Definition: expr.h:290