Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tuple.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_RUNTIME_TUPLE_H
17 #define IMPALA_RUNTIME_TUPLE_H
18 
19 #include <cstring>
20 #include "common/logging.h"
21 #include "gutil/macros.h"
22 #include "runtime/descriptors.h"
23 #include "runtime/mem-pool.h"
24 
25 namespace impala {
26 
27 struct StringValue;
28 class TupleDescriptor;
29 class TupleRow;
30 
35 //
46 //
48 class Tuple {
49  public:
51  static Tuple* Create(int size, MemPool* pool) {
52  if (size == 0) return NULL;
53  Tuple* result = reinterpret_cast<Tuple*>(pool->Allocate(size));
54  result->Init(size);
55  return result;
56  }
57 
58  void Init(int size) {
59  bzero(this, size);
60  }
61 
66  Tuple* DeepCopy(const TupleDescriptor& desc, MemPool* pool, bool convert_ptrs = false);
67 
73  void DeepCopy(Tuple* dst, const TupleDescriptor& desc, MemPool* pool,
74  bool convert_ptrs = false);
75 
83  void DeepCopy(const TupleDescriptor& desc, char** data, int* offset,
84  bool convert_ptrs = false);
85 
92  template <bool collect_string_vals>
93  void MaterializeExprs(
94  TupleRow* row, const TupleDescriptor& desc,
95  const std::vector<ExprContext*>& materialize_expr_ctxs, MemPool* pool,
96  std::vector<StringValue*>* non_null_var_len_values = NULL,
97  int* total_var_len = NULL);
98 
102  char* null_indicator_byte = reinterpret_cast<char*>(this) + offset.byte_offset;
103  *null_indicator_byte |= offset.bit_mask;
104  }
105 
108  char* null_indicator_byte = reinterpret_cast<char*>(this) + offset.byte_offset;
109  *null_indicator_byte &= ~offset.bit_mask;
110  }
111 
112  bool IsNull(const NullIndicatorOffset& offset) const {
113  const char* null_indicator_byte =
114  reinterpret_cast<const char*>(this) + offset.byte_offset;
115  return (*null_indicator_byte & offset.bit_mask) != 0;
116  }
117 
118  void* GetSlot(int offset) {
119  DCHECK(offset != -1); // -1 offset indicates non-materialized slot
120  return reinterpret_cast<char*>(this) + offset;
121  }
122 
123  const void* GetSlot(int offset) const {
124  DCHECK(offset != -1); // -1 offset indicates non-materialized slot
125  return reinterpret_cast<const char*>(this) + offset;
126  }
127 
129  DCHECK(offset != -1); // -1 offset indicates non-materialized slot
130  return reinterpret_cast<StringValue*>(reinterpret_cast<char*>(this) + offset);
131  }
132 
134  static const char* LLVM_CLASS_NAME;
135 
136  private:
138 };
139 
140 }
141 
142 #endif
const void * GetSlot(int offset) const
Definition: tuple.h:123
void SetNull(const NullIndicatorOffset &offset)
Definition: tuple.h:101
A tuple with 0 materialised slots is represented as NULL.
Definition: tuple.h:48
DISALLOW_COPY_AND_ASSIGN(Tuple)
void Init(int size)
Definition: tuple.h:58
void * GetSlot(int offset)
Definition: tuple.h:118
static Tuple * Create(int size, MemPool *pool)
initialize individual tuple with data residing in mem pool
Definition: tuple.h:51
Tuple * DeepCopy(const TupleDescriptor &desc, MemPool *pool, bool convert_ptrs=false)
Definition: tuple.cc:34
bool IsNull(const NullIndicatorOffset &offset) const
Definition: tuple.h:112
static const char * LLVM_CLASS_NAME
For C++/IR interop, we need to be able to look up types by name.
Definition: tuple.h:134
ObjectPool pool
StringValue * GetStringSlot(int offset)
Definition: tuple.h:128
uint8_t offset[7 *64-sizeof(uint64_t)]
void MaterializeExprs(TupleRow *row, const TupleDescriptor &desc, const std::vector< ExprContext * > &materialize_expr_ctxs, MemPool *pool, std::vector< StringValue * > *non_null_var_len_values=NULL, int *total_var_len=NULL)
uint8_t * Allocate(int size)
Definition: mem-pool.h:92
void SetNotNull(const NullIndicatorOffset &offset)
Turn null indicator bit off.
Definition: tuple.h:107