Refactor TableLayoutResult#hasAllOutputs
Make it:
- more readable
- avoid quadratic List.containsAll(List)
@@ -16,8 +16,10 @@ package com.facebook.presto.metadata;
import com.facebook.presto.spi.ColumnHandle;
import com.facebook.presto.spi.predicate.TupleDomain;
import com.facebook.presto.sql.planner.plan.TableScanNode;
+import com.google.common.collect.ImmutableSet;
import java.util.List;
+import java.util.Set;
import static com.google.common.collect.ImmutableList.toImmutableList;
@@ -44,11 +46,14 @@ public class TableLayoutResult
public boolean hasAllOutputs(TableScanNode node)
{
+ if (!layout.getColumns().isPresent()) {
+ return true;
+ }
+ Set<ColumnHandle> columns = ImmutableSet.copyOf(layout.getColumns().get());
List<ColumnHandle> nodeColumnHandles = node.getOutputSymbols().stream()
.map(node.getAssignments()::get)
.collect(toImmutableList());
- return getLayout().getColumns()
- .map(columnHandles -> columnHandles.containsAll(nodeColumnHandles))
- .orElse(true);
+
+ return columns.containsAll(nodeColumnHandles);
}
}
