15 package com.cloudera.impala.planner;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.HashSet;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
35 import com.cloudera.impala.thrift.TColumnValue;
36 import com.cloudera.impala.thrift.TResultRow;
37 import com.google.common.base.Preconditions;
38 import com.google.common.collect.Lists;
39 import com.google.common.collect.Maps;
46 private final static Logger
LOG = LoggerFactory.getLogger(HdfsPartitionFilter.class);
51 private final ArrayList<SlotRef>
lhsSlotRefs_ = Lists.newArrayList();
53 private final ArrayList<Integer>
refdKeys_ = Lists.newArrayList();
59 ArrayList<SlotId> refdSlots = Lists.newArrayList();
60 predicate.getIds(null, refdSlots);
61 HashMap<Column, SlotDescriptor> slotDescsByCol = Maps.newHashMap();
62 for (
SlotId refdSlot: refdSlots) {
63 SlotDescriptor slotDesc = analyzer.getDescTbl().getSlotDesc(refdSlot);
64 slotDescsByCol.put(slotDesc.getColumn(), slotDesc);
67 for (
int i = 0; i < tbl.getNumClusteringCols(); ++i) {
68 Column col = tbl.getColumns().
get(i);
70 if (slotDesc != null) {
71 lhsSlotRefs_.add(
new SlotRef(slotDesc));
75 Preconditions.checkState(lhsSlotRefs_.size() ==
refdKeys_.size());
84 HashSet<Long> result =
new HashSet<Long>();
86 ArrayList<Expr> predicates =
new ArrayList<Expr>(partitions.size());
87 long[] partitionIds =
new long[partitions.size()];
91 partitionIds[indx++] = p.getId();
94 TResultRow results = FeSupport.EvalPredicateBatch(predicates,
95 analyzer.getQueryCtx());
96 Preconditions.checkState(results.getColValsSize() == partitions.size());
98 for (TColumnValue val: results.getColVals()) {
99 if (val.isBool_val()) result.add(partitionIds[indx]);
113 for (
int i = 0; i < refdKeys_.size(); ++i) {
115 lhsSlotRefs_.get(i), partition.getPartitionValues().get(refdKeys_.get(i)));
118 Expr literalPredicate = predicate_.substitute(sMap, analyzer,
false);
119 LOG.trace(
"buildPartitionPredicate: " + literalPredicate.toSql() +
" " +
121 Preconditions.checkState(literalPredicate.isConstant());
122 return literalPredicate;
HashSet< Long > getMatchingPartitionIds(ArrayList< HdfsPartition > partitions, Analyzer analyzer)
final ArrayList< Integer > refdKeys_
final ArrayList< SlotRef > lhsSlotRefs_
HdfsPartitionFilter(Expr predicate, HdfsTable tbl, Analyzer analyzer)
Expr buildPartitionPredicate(HdfsPartition partition, Analyzer analyzer)