Skip to content

Commit 8870fef

Browse files
committed
Provide support in tests for creating constant blocks from collection values
1 parent 7d1f8b7 commit 8870fef

File tree

1 file changed

+9
-0
lines changed
  • x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data

1 file changed

+9
-0
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/BlockUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
import java.util.ArrayList;
1717
import java.util.Arrays;
18+
import java.util.Collection;
1819
import java.util.HashSet;
1920
import java.util.List;
2021
import java.util.Random;
2122
import java.util.function.Consumer;
2223

2324
import static org.elasticsearch.common.lucene.BytesRefs.toBytesRef;
25+
import static org.elasticsearch.compute.data.ElementType.NULL;
2426
import static org.elasticsearch.compute.data.ElementType.fromJava;
2527

2628
public final class BlockUtils {
@@ -222,6 +224,13 @@ public static Block constantBlock(BlockFactory blockFactory, Object val, int siz
222224
if (val == null) {
223225
return blockFactory.newConstantNullBlock(size);
224226
}
227+
if (val instanceof Collection<?> collection) {
228+
if (collection.isEmpty()) {
229+
return constantBlock(blockFactory, NULL, val, size);
230+
}
231+
Object colVal = collection.iterator().next();
232+
return constantBlock(blockFactory, fromJava(colVal.getClass()), colVal, size);
233+
}
225234
return constantBlock(blockFactory, fromJava(val.getClass()), val, size);
226235
}
227236

0 commit comments

Comments
 (0)