1 package com.cloudera.impala.analysis;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
8 import com.google.common.base.Joiner;
9 import com.google.common.base.Preconditions;
10 import com.google.common.collect.Lists;
21 private final static Logger
LOG = LoggerFactory.getLogger(ExprSubstitutionMap.class);
27 this(Lists.<
Expr>newArrayList(), Lists.<
Expr>newArrayList());
40 Preconditions.checkState(rhsExpr.isAnalyzed_,
"Rhs expr must be analyzed.");
49 for (
int i = 0; i < lhs_.size(); ++i) {
50 if (lhsExpr.equals(
lhs_.get(i)))
return rhs_.get(i);
59 return lhs_.contains(lhsExpr);
70 if (f == null)
return g;
71 if (g == null)
return f;
74 result.lhs_ = Expr.cloneList(f.lhs_);
75 result.rhs_ = Expr.substituteList(f.rhs_, g, analyzer,
false);
79 for (
int i = 0; i < g.lhs_.size(); i++) {
88 if (!result.
lhs_.contains(g.lhs_.get(i))) {
89 result.lhs_.add(g.lhs_.get(i).clone());
90 result.rhs_.add(g.rhs_.get(i).clone());
104 if (f == null)
return g;
105 if (g == null)
return f;
107 result.lhs_ = Lists.newArrayList(f.lhs_);
108 result.lhs_.addAll(g.lhs_);
109 result.rhs_ = Lists.newArrayList(f.rhs_);
110 result.rhs_.addAll(g.rhs_);
116 lhs_ = Expr.substituteList(
lhs_, lhsSmap, analyzer,
false);
122 public int size() {
return lhs_.size(); }
125 Preconditions.checkState(lhs_.size() ==
rhs_.size());
126 List<String> output = Lists.newArrayList();
127 for (
int i = 0; i < lhs_.size(); ++i) {
128 output.add(lhs_.get(i).toSql() +
":" + rhs_.get(i).toSql());
131 return "smap(" + Joiner.on(
" ").join(output) +
")";
139 for (
int i = 0; i < lhs_.size(); ++i) {
140 for (
int j = i + 1; j < lhs_.size(); ++j) {
141 if (
lhs_.get(i).equals(lhs_.get(j))) {
142 LOG.info(
"verify: smap=" + this.debugString());
143 Preconditions.checkState(
false);
146 Preconditions.checkState(rhs_.get(i).isAnalyzed_);
ExprSubstitutionMap(List< Expr > lhs, List< Expr > rhs)
boolean containsMappingFor(Expr lhsExpr)
void substituteLhs(ExprSubstitutionMap lhsSmap, Analyzer analyzer)
void put(Expr lhsExpr, Expr rhsExpr)
static ExprSubstitutionMap combine(ExprSubstitutionMap f, ExprSubstitutionMap g)
static ExprSubstitutionMap compose(ExprSubstitutionMap f, ExprSubstitutionMap g, Analyzer analyzer)