Add Lookup resolution to the ScalarQueryUtil.isScalar
This will enable using that method in the iterative optimizer.
*/
package com.facebook.presto.sql.planner.optimizations;
+import com.facebook.presto.sql.planner.iterative.GroupReference;
+import com.facebook.presto.sql.planner.iterative.Lookup;
import com.facebook.presto.sql.planner.plan.AggregationNode;
import com.facebook.presto.sql.planner.plan.EnforceSingleRowNode;
import com.facebook.presto.sql.planner.plan.ExchangeNode;
@@ -23,23 +25,44 @@ import com.facebook.presto.sql.planner.plan.ProjectNode;
import com.facebook.presto.sql.planner.plan.ValuesNode;
import com.google.common.collect.ImmutableList;
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.getOnlyElement;
+import static java.util.Objects.requireNonNull;
public final class ScalarQueryUtil
{
private ScalarQueryUtil() {}
+ public static boolean isScalar(PlanNode node, Lookup lookup)
+ {
+ return node.accept(new IsScalarPlanVisitor(Optional.ofNullable(lookup)), null);
+ }
+
public static boolean isScalar(PlanNode node)
{
- return node.accept(new IsScalarPlanVisitor(), null);
+ return isScalar(node, null);
}
private static final class IsScalarPlanVisitor
extends PlanVisitor<Void, Boolean>
{
+ private final Optional<Lookup> lookup;
+
+ public IsScalarPlanVisitor(Optional<Lookup> lookup)
+ {
+ this.lookup = requireNonNull(lookup, "lookup is null");
+ }
+
@Override
protected Boolean visitPlan(PlanNode node, Void context)
{
+ if (node instanceof GroupReference) {
+ checkState(lookup.isPresent(), "Lookup has to be provided to test plans with GroupReference nodes");
+ return lookup.get().resolve(node).accept(this, null);
+ }
+
return false;
}
