Convert equality-based Multimaps in Analysis into NodeRef-based
@@ -57,6 +57,7 @@ import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.emptyList;
+import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSet;
import static java.util.Objects.requireNonNull;
@@ -83,11 +84,10 @@ public class Analysis
private final Map<NodeRef<OrderBy>, List<FunctionCall>> orderByWindowFunctions = new LinkedHashMap<>();
private final Map<NodeRef<Join>, Expression> joins = new LinkedHashMap<>();
- // TODO convert ListMultimap too
- private final ListMultimap<Node, InPredicate> inPredicatesSubqueries = ArrayListMultimap.create();
- private final ListMultimap<Node, SubqueryExpression> scalarSubqueries = ArrayListMultimap.create();
- private final ListMultimap<Node, ExistsPredicate> existsSubqueries = ArrayListMultimap.create();
- private final ListMultimap<Node, QuantifiedComparisonExpression> quantifiedComparisonSubqueries = ArrayListMultimap.create();
+ private final ListMultimap<NodeRef<Node>, InPredicate> inPredicatesSubqueries = ArrayListMultimap.create();
+ private final ListMultimap<NodeRef<Node>, SubqueryExpression> scalarSubqueries = ArrayListMultimap.create();
+ private final ListMultimap<NodeRef<Node>, ExistsPredicate> existsSubqueries = ArrayListMultimap.create();
+ private final ListMultimap<NodeRef<Node>, QuantifiedComparisonExpression> quantifiedComparisonSubqueries = ArrayListMultimap.create();
private final Map<NodeRef<Table>, TableHandle> tables = new LinkedHashMap<>();
@@ -302,42 +302,31 @@ public class Analysis
public void recordSubqueries(Node node, ExpressionAnalysis expressionAnalysis)
{
- this.inPredicatesSubqueries.putAll(node, expressionAnalysis.getSubqueryInPredicates());
- this.scalarSubqueries.putAll(node, expressionAnalysis.getScalarSubqueries());
- this.existsSubqueries.putAll(node, expressionAnalysis.getExistsSubqueries());
- this.quantifiedComparisonSubqueries.putAll(node, expressionAnalysis.getQuantifiedComparisons());
+ NodeRef<Node> key = NodeRef.of(node);
+ this.inPredicatesSubqueries.putAll(key, expressionAnalysis.getSubqueryInPredicates());
+ this.scalarSubqueries.putAll(key, expressionAnalysis.getScalarSubqueries());
+ this.existsSubqueries.putAll(key, expressionAnalysis.getExistsSubqueries());
+ this.quantifiedComparisonSubqueries.putAll(key, expressionAnalysis.getQuantifiedComparisons());
}
public List<InPredicate> getInPredicateSubqueries(Node node)
{
- if (inPredicatesSubqueries.containsKey(node)) {
- return inPredicatesSubqueries.get(node);
- }
- return ImmutableList.of();
+ return ImmutableList.copyOf(inPredicatesSubqueries.get(NodeRef.of(node)));
}
public List<SubqueryExpression> getScalarSubqueries(Node node)
{
- if (scalarSubqueries.containsKey(node)) {
- return scalarSubqueries.get(node);
- }
- return ImmutableList.of();
+ return ImmutableList.copyOf(scalarSubqueries.get(NodeRef.of(node)));
}
public List<ExistsPredicate> getExistsSubqueries(Node node)
{
- if (existsSubqueries.containsKey(node)) {
- return existsSubqueries.get(node);
- }
- return ImmutableList.of();
+ return ImmutableList.copyOf(existsSubqueries.get(NodeRef.of(node)));
}
public List<QuantifiedComparisonExpression> getQuantifiedComparisonSubqueries(Node node)
{
- if (quantifiedComparisonSubqueries.containsKey(node)) {
- return quantifiedComparisonSubqueries.get(node);
- }
- return ImmutableList.of();
+ return unmodifiableList(quantifiedComparisonSubqueries.get(NodeRef.of(node)));
}
public void setWindowFunctions(QuerySpecification node, List<FunctionCall> functions)
