diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java index 2e1c6bcbfee484..ab081712479cec 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java @@ -19,6 +19,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Collections; import java.util.Deque; import java.util.List; import java.util.stream.Collectors; @@ -83,12 +84,16 @@ public PartitionExtractor(IgniteTypeFactory typeFactory) { @Override protected IgniteRel processNode(IgniteRel rel) { IgniteRel res = super.processNode(rel); - if (rel.getInputs().size() <= 1) + if (rel.getInputs().isEmpty()) return res; List operands = new ArrayList<>(); - for (int i = 0; i < rel.getInputs().size(); ++i) + for (int i = 0; i < rel.getInputs().size(); ++i) { + if (stack.isEmpty()) + break; + operands.add(stack.pop()); + } stack.push(PartitionOperandNode.createOrOperandNode(operands)); @@ -139,7 +144,12 @@ private void processScan(IgniteRel rel) { types.add(Primitives.wrap((Class)typeFactory.getJavaClass(field.getType()))); } - List requiredCols = ((ProjectableFilterableTableScan)rel).requiredColumns().asList(); + List requiredCols; + if (((ProjectableFilterableTableScan)rel).requiredColumns() != null) + requiredCols = ((ProjectableFilterableTableScan)rel).requiredColumns().asList(); + else + requiredCols = Collections.emptyList(); + PartitionNode partNode = processCondition(condition, types, keys, requiredCols, cacheId); stack.push(partNode); @@ -166,7 +176,9 @@ private PartitionNode processCondition( if (!left.isA(SqlKind.LOCAL_REF)) return PartitionAllNode.INSTANCE; - int idx = requiredCols.get(((RexLocalRef)left).getIndex()); + int idx = ((RexLocalRef)left).getIndex(); + if (!requiredCols.isEmpty()) + idx = requiredCols.get(idx); if (!keys.contains(idx)) return PartitionAllNode.INSTANCE; @@ -193,7 +205,9 @@ private PartitionNode processCondition( if (!right.isA(SqlKind.LITERAL) && !right.isA(SqlKind.DYNAMIC_PARAM)) return PartitionAllNode.INSTANCE; - int idx = requiredCols.get(((RexLocalRef)left).getIndex()); + int idx = ((RexLocalRef)left).getIndex(); + if (!requiredCols.isEmpty()) + idx = requiredCols.get(idx); if (!keys.contains(idx)) return PartitionAllNode.INSTANCE;