15 package com.cloudera.impala.analysis;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.HashSet;
20 import java.util.List;
24 import com.cloudera.impala.common.IdGenerator;
25 import com.cloudera.impala.thrift.TDescriptorTable;
26 import com.google.common.base.Preconditions;
27 import com.google.common.collect.Lists;
28 import com.google.common.collect.Maps;
29 import com.google.common.collect.Sets;
37 private final HashMap<TupleId, TupleDescriptor>
tupleDescs_ = Maps.newHashMap();
38 private final HashMap<SlotId, SlotDescriptor>
slotDescs_ = Maps.newHashMap();
50 tupleDescs_.put(d.getId(), d);
60 tupleDescs_.put(d.getId(), d);
67 Preconditions.checkState(d.getByteSize() == src.
getByteSize());
74 slotDescs_.put(result.getId(), result);
84 slotDescs_.put(result.getId(), result);
90 public Collection<TupleDescriptor>
getTupleDescs() {
return tupleDescs_.values(); }
91 public Collection<SlotDescriptor>
getSlotDescs() {
return slotDescs_.values(); }
96 referencedTables_.add(table);
104 HashSet<Long> refPartitions = referencedPartitionsPerTable_.get(table);
105 if (refPartitions == null) {
106 refPartitions =
new HashSet<Long>();
107 referencedPartitionsPerTable_.put(table, refPartitions);
109 return refPartitions;
133 List<SlotId> result = Lists.newArrayList();
134 for (
SlotId id: slotIds) {
135 if (
getSlotDesc(
id).getParent().getId().equals(tupleId)) result.add(id);
145 d.computeMemLayout();
150 TDescriptorTable result =
new TDescriptorTable();
151 HashSet<Table> referencedTbls = Sets.newHashSet();
152 HashSet<Table> allPartitionsTbls = Sets.newHashSet();
156 if (tupleDesc.isMaterialized()) {
157 result.addToTupleDescriptors(tupleDesc.toThrift());
158 Table table = tupleDesc.getTable();
159 if (table != null && !(table instanceof
View)) referencedTbls.add(table);
161 result.addToSlotDescriptors(slotD.toThrift());
166 referencedTbls.add(table);
168 allPartitionsTbls.add(table);
170 for (
Table tbl: referencedTbls) {
171 HashSet<Long> referencedPartitions = null;
172 if (!allPartitionsTbls.contains(tbl)) {
175 result.addToTableDescriptors(tbl.toThriftDescriptor(referencedPartitions));
181 StringBuilder out =
new StringBuilder();
182 out.append(
"tuples:\n");
184 out.append(desc.debugString() +
"\n");
186 return out.toString();
void addReferencedPartition(Table table, long partitionId)
TDescriptorTable toThrift()
final HashMap< Table, HashSet< Long > > referencedPartitionsPerTable_
SlotDescriptor getSlotDesc(SlotId id)
List< SlotId > getTupleSlotIds(List< SlotId > slotIds, TupleId tupleId)
final List< Table > referencedTables_
TupleDescriptor copyTupleDescriptor(TupleId srcId, String debugName)
final IdGenerator< TupleId > tupleIdGenerator_
TupleDescriptor createTupleDescriptor(String debugName)
Collection< TupleDescriptor > getTupleDescs()
final IdGenerator< SlotId > slotIdGenerator_
Collection< SlotDescriptor > getSlotDescs()
ArrayList< SlotDescriptor > getSlots()
TupleDescriptor getTupleDesc(TupleId id)
SlotDescriptor copySlotDescriptor(TupleDescriptor dest, SlotDescriptor src)
HashSet< Long > getReferencedPartitions(Table table)
final HashMap< TupleId, TupleDescriptor > tupleDescs_
final HashMap< SlotId, SlotDescriptor > slotDescs_
void addReferencedTable(Table table)
SlotDescriptor addSlotDescriptor(TupleDescriptor d)
void markSlotsMaterialized(List< SlotId > ids)