Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
desc-tbl-builder.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 #include "util/bit-util.h"
17 
18 
19 #include "runtime/descriptors.h"
20 
21 #include "common/names.h"
22 
23 namespace impala {
24 
26 }
27 
29  TupleDescBuilder* tuple_builder = obj_pool_->Add(new TupleDescBuilder());
30  tuples_descs_.push_back(tuple_builder);
31  return *tuple_builder;
32 }
33 
34 static TSlotDescriptor MakeSlotDescriptor(int id, int parent_id, const ColumnType& type,
35  int slot_idx, int byte_offset) {
36  int null_byte = slot_idx / 8;
37  int null_bit = slot_idx % 8;
38  TSlotDescriptor slot_desc;
39  slot_desc.__set_id(id);
40  slot_desc.__set_parent(parent_id);
41  slot_desc.__set_slotType(type.ToThrift());
42  slot_desc.__set_columnPath(vector<int>(1, slot_idx));
43  slot_desc.__set_byteOffset(byte_offset);
44  slot_desc.__set_nullIndicatorByte(null_byte);
45  slot_desc.__set_nullIndicatorBit(null_bit);
46  slot_desc.__set_slotIdx(slot_idx);
47  slot_desc.__set_isMaterialized(true);
48  return slot_desc;
49 }
50 
51 static TTupleDescriptor MakeTupleDescriptor(int id, int byte_size, int num_null_bytes) {
52  TTupleDescriptor tuple_desc;
53  tuple_desc.__set_id(id);
54  tuple_desc.__set_byteSize(byte_size);
55  tuple_desc.__set_numNullBytes(num_null_bytes);
56  return tuple_desc;
57 }
58 
60  DescriptorTbl* desc_tbl;
61  TDescriptorTable thrift_desc_tbl;
62  int slot_id = tuples_descs_.size(); // First ids reserved for TupleDescriptors
63 
64  for (int i = 0; i < tuples_descs_.size(); ++i) {
65  vector<ColumnType> slot_types = tuples_descs_[i]->slot_types();
66  int num_null_bytes = BitUtil::Ceil(slot_types.size(), 8);
67  int byte_offset = num_null_bytes;
68  int tuple_id = i;
69 
70  for(int j = 0; j < slot_types.size(); ++j) {
71  thrift_desc_tbl.slotDescriptors.push_back(
72  MakeSlotDescriptor(++slot_id, tuple_id, slot_types[j], j, byte_offset));
73 
74  int byte_size = slot_types[j].GetByteSize();
75  if (byte_size == 0) {
76  // can only handle strings right now
77  DCHECK(slot_types[j].type == TYPE_STRING || slot_types[j].type == TYPE_VARCHAR);
78  byte_size = 16;
79  }
80  byte_offset += byte_size;
81  }
82 
83  thrift_desc_tbl.tupleDescriptors.push_back(
84  MakeTupleDescriptor(tuple_id, byte_offset, num_null_bytes));
85  }
86 
87  Status status = DescriptorTbl::Create(obj_pool_, thrift_desc_tbl, &desc_tbl);
88  DCHECK(status.ok());
89  return desc_tbl;
90 }
91 
92 }
DescriptorTblBuilder(ObjectPool *object_pool)
std::vector< TupleDescBuilder * > tuples_descs_
ObjectPool * obj_pool_
Owned by caller.
boost::scoped_ptr< ObjectPool > obj_pool_
Object pool owned by the coordinator. Any executor will have its own pool.
Definition: coordinator.h:296
ObjectPool * obj_pool()
Returns a local object pool.
Definition: coordinator.h:263
static TSlotDescriptor MakeSlotDescriptor(int id, int parent_id, const ColumnType &type, int slot_idx, int byte_offset)
static int Ceil(int value, int divisor)
Returns the ceil of value/divisor.
Definition: bit-util.h:32
static TTupleDescriptor MakeTupleDescriptor(int id, int byte_size, int num_null_bytes)
TupleDescBuilder & DeclareTuple()
static Status Create(ObjectPool *pool, const TDescriptorTable &thrift_tbl, DescriptorTbl **tbl)
Definition: descriptors.cc:378
TColumnType ToThrift() const
Definition: types.h:147
bool ok() const
Definition: status.h:172