Skip to content

Commit 6aca146

Browse files
committed
try to get rid of some instanceofs
1 parent 1e7c489 commit 6aca146

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/AggregatorImplementer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public AggregatorImplementer(
122122
}).filter(a -> a instanceof PositionArgument == false).toList();
123123

124124
this.tryToUseVectors = aggParams.stream().anyMatch(a -> (a instanceof BlockArgument) == false)
125-
&& aggParams.stream().noneMatch(a -> a instanceof StandardArgument && a.hasVector() == false);
125+
&& aggParams.stream().noneMatch(a -> a.supportsVectorReadAccess() == false);
126126

127127
this.createParameters = init.getParameters()
128128
.stream()

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.compute.gen.argument.BlockArgument;
1919
import org.elasticsearch.compute.gen.argument.BuilderArgument;
2020
import org.elasticsearch.compute.gen.argument.FixedArgument;
21-
import org.elasticsearch.compute.gen.argument.PositionArgument;
2221

2322
import java.util.ArrayList;
2423
import java.util.List;
@@ -71,9 +70,7 @@ public EvaluatorImplementer(
7170
declarationType.getSimpleName() + extraName + "Evaluator"
7271
);
7372
this.processOutputsMultivalued = this.processFunction.hasBlockType;
74-
boolean anyParameterNotSupportingVectors = this.processFunction.args.stream()
75-
.filter(a -> a instanceof FixedArgument == false && a instanceof PositionArgument == false)
76-
.anyMatch(a -> a.hasVector() == false);
73+
boolean anyParameterNotSupportingVectors = this.processFunction.args.stream().anyMatch(a -> a.supportsVectorReadAccess() == false);
7774
vectorsUnsupported = processOutputsMultivalued || anyParameterNotSupportingVectors;
7875
this.allNullsIsNull = allNullsIsNull;
7976
}

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public GroupingAggregatorImplementer(
128128
}).filter(a -> a instanceof PositionArgument == false).toList();
129129

130130
this.hasOnlyBlockArguments = this.aggParams.stream().allMatch(a -> a instanceof BlockArgument);
131-
this.allArgumentsSupportVectors = aggParams.stream().noneMatch(a -> a instanceof StandardArgument && a.hasVector() == false);
131+
this.allArgumentsSupportVectors = aggParams.stream().noneMatch(a -> a.supportsVectorReadAccess() == false);
132132

133133
this.createParameters = init.getParameters()
134134
.stream()

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/Argument.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ default TypeName elementType() {
117117
*/
118118
TypeName dataType(boolean blockStyle);
119119

120-
default boolean hasVector() {
121-
return dataType(false) != null;
120+
/**
121+
* False if and only if there is a block backing this parameter and that block does not support access as a vector. Otherwise true.
122+
*/
123+
default boolean supportsVectorReadAccess() {
124+
return true;
122125
}
123126

124127
/**

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/ArrayArgument.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public TypeName dataType(boolean blockStyle) {
3535
return ArrayTypeName.of(vectorType(type));
3636
}
3737

38+
@Override
39+
public boolean supportsVectorReadAccess() {
40+
return vectorType(type) != null;
41+
}
42+
3843
@Override
3944
public String paramName(boolean blockStyle) {
4045
return name + (blockStyle ? "Block" : "Vector") + "s";

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/argument/StandardArgument.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public TypeName dataType(boolean blockStyle) {
3535
return vectorType(type);
3636
}
3737

38+
@Override
39+
public boolean supportsVectorReadAccess() {
40+
return dataType(false) != null;
41+
}
42+
3843
@Override
3944
public String paramName(boolean blockStyle) {
4045
return name + (blockStyle ? "Block" : "Vector");

0 commit comments

Comments
 (0)