15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.HashMap;
20 import java.util.List;
27 import com.cloudera.impala.thrift.TTupleDescriptor;
28 import com.google.common.base.Joiner;
29 import com.google.common.base.Objects;
30 import com.google.common.base.Preconditions;
31 import com.google.common.collect.Lists;
57 private final ArrayList<SlotDescriptor>
slots_ = Lists.newArrayList();
98 if (
path_ == null)
return null;
99 return path_.getRootTable();
103 return (t == null) ? null : t.getTableName();
106 Preconditions.checkNotNull(p);
107 Preconditions.checkState(p.isResolved());
108 Preconditions.checkState(p.destType().isCollectionType());
116 type_ = Path.getTypeAsStruct(p.destType());
138 List<String> slotStrings = Lists.newArrayList();
140 slotStrings.add(slot.debugString());
142 return Objects.toStringHelper(
this)
143 .add(
"id",
id_.asInt())
148 .add(
"slots",
"[" + Joiner.on(
", ").join(slotStrings) +
"]")
157 slot.setIsMaterialized(
true);
162 TTupleDescriptor ttupleDesc =
166 ttupleDesc.setTableId(
getTable().getId().asInt());
167 Preconditions.checkNotNull(
path_);
168 ttupleDesc.setTuplePath(path_.getAbsolutePath());
178 Map<Integer, List<SlotDescriptor>> slotsBySize =
179 new HashMap<Integer, List<SlotDescriptor>>();
182 int numNullableSlots = 0;
184 if (!d.isMaterialized())
continue;
192 if (!slotsBySize.containsKey(d.getType().getSlotSize())) {
193 slotsBySize.put(d.getType().getSlotSize(),
new ArrayList<SlotDescriptor>());
195 slotsBySize.get(d.getType().getSlotSize()).add(d);
196 if (d.getIsNullable()) ++numNullableSlots;
199 Preconditions.checkState(!slotsBySize.containsKey(0));
200 Preconditions.checkState(!slotsBySize.containsKey(-1));
205 int nullIndicatorByte = 0;
206 int nullIndicatorBit = 0;
210 List<Integer> sortedSizes =
new ArrayList<Integer>(slotsBySize.keySet());
211 Collections.sort(sortedSizes);
212 for (
int slotSize: sortedSizes) {
213 if (slotsBySize.get(slotSize).isEmpty())
continue;
216 int alignTo = Math.min(slotSize, 8);
217 offset = (offset + alignTo - 1) / alignTo * alignTo;
221 Preconditions.checkState(d.isMaterialized());
222 d.setByteSize(slotSize);
224 d.setSlotIdx(slotIdx++);
228 if (d.getIsNullable()) {
229 d.setNullIndicatorByte(nullIndicatorByte);
230 d.setNullIndicatorBit(nullIndicatorBit);
231 nullIndicatorBit = (nullIndicatorBit + 1) % 8;
232 if (nullIndicatorBit == 0) ++nullIndicatorByte;
235 d.setNullIndicatorBit(-1);
236 d.setNullIndicatorByte(0);
249 if (
slots_.size() != desc.slots_.size())
return false;
250 for (
int i = 0; i < slots_.size(); ++i) {
251 if (!
slots_.get(i).getType().equals(desc.
slots_.get(i).getType()))
return false;
TupleDescriptor(TupleId id, String debugName)
float getAvgSerializedSize()
final ArrayList< SlotDescriptor > slots_
TableName getAliasAsName()
void addSlot(SlotDescriptor desc)
boolean isCompatible(TupleDescriptor desc)
TTupleDescriptor toThrift()
boolean hasAvgSerializedSize()
ArrayList< SlotDescriptor > getSlots()
boolean hasExplicitAlias()
void setAliases(String[] aliases, boolean hasExplicitAlias)
uint8_t offset[7 *64-sizeof(uint64_t)]
void setIsMaterialized(boolean value)
void setType(StructType type)
boolean hasExplicitAlias_