Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tuple-row.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_ROW_H
17 #define IMPALA_RUNTIME_TUPLE_ROW_H
18 
19 #include "runtime/descriptors.h"
20 #include "runtime/mem-pool.h"
21 #include "runtime/row-batch.h"
22 #include "runtime/tuple.h"
23 
24 namespace impala {
25 
28 class TupleRow {
29  public:
30  Tuple* GetTuple(int tuple_idx) {
31  return tuples_[tuple_idx];
32  }
33 
34  void SetTuple(int tuple_idx, Tuple* tuple) {
35  tuples_[tuple_idx] = tuple;
36  }
37 
39  TupleRow* DeepCopy(const std::vector<TupleDescriptor*>& descs, MemPool* pool) {
40  int size = descs.size() * sizeof(Tuple*);
41  TupleRow* result = reinterpret_cast<TupleRow*>(pool->Allocate(size));
42  DeepCopy(result, descs, pool, false);
43  return result;
44  }
45 
52  void DeepCopy(TupleRow* dst, const std::vector<TupleDescriptor*>& descs, MemPool* pool,
53  bool reuse_tuple_mem) {
54  for (int i = 0; i < descs.size(); ++i) {
55  if (this->GetTuple(i) != NULL) {
56  if (reuse_tuple_mem && dst->GetTuple(i) != NULL) {
57  this->GetTuple(i)->DeepCopy(dst->GetTuple(i), *descs[i], pool);
58  } else {
59  dst->SetTuple(i, this->GetTuple(i)->DeepCopy(*descs[i], pool));
60  }
61  } else {
62  // TODO: this is wasteful. If we have 'reuse_tuple_mem', we should be able to
63  // save the tuple buffer and reuse it (i.e. freelist).
64  dst->SetTuple(i, NULL);
65  }
66  }
67  }
68 
69  inline TupleRow* next_row(RowBatch* batch) const {
70  uint8_t* mem = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(this));
71  return reinterpret_cast<TupleRow*>(mem + batch->row_byte_size());
72  }
73 
76  static const char* LLVM_CLASS_NAME;
77 
78  private:
80 };
81 
82 }
83 
84 #endif
Tuple * GetTuple(int tuple_idx)
Definition: tuple-row.h:30
A tuple with 0 materialised slots is represented as NULL.
Definition: tuple.h:48
TupleRow * next_row(RowBatch *batch) const
Definition: tuple-row.h:69
int row_byte_size()
Definition: row-batch.h:147
Tuple * DeepCopy(const TupleDescriptor &desc, MemPool *pool, bool convert_ptrs=false)
Definition: tuple.cc:34
static const char * LLVM_CLASS_NAME
Definition: tuple-row.h:76
void DeepCopy(TupleRow *dst, const std::vector< TupleDescriptor * > &descs, MemPool *pool, bool reuse_tuple_mem)
Definition: tuple-row.h:52
ObjectPool pool
Tuple * tuples_[1]
Definition: tuple-row.h:79
void SetTuple(int tuple_idx, Tuple *tuple)
Definition: tuple-row.h:34
TupleRow * DeepCopy(const std::vector< TupleDescriptor * > &descs, MemPool *pool)
Create a deep copy of this TupleRow. DeepCopy will allocate from the pool.
Definition: tuple-row.h:39
uint8_t * Allocate(int size)
Definition: mem-pool.h:92