Skip to content

Commit c7cd12d

Browse files
committed
Fail hard when there are multi-valued blocks
1 parent 3bb04d3 commit c7cd12d

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

x-pack/plugin/esql/arrow/src/main/java/org/elasticsearch/xpack/esql/arrow/ArrowResponse.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ public ArrowResponse(List<Column> columns, List<Page> pages) {
6464
currentSegment = new SchemaResponse(this);
6565
List<ResponseSegment> rest = new ArrayList<>(pages.size());
6666
for (int p = 0; p < pages.size(); p++) {
67-
rest.add(new PageResponse(this, pages.get(p)));
67+
var page = pages.get(p);
68+
rest.add(new PageResponse(this, page));
69+
// Multivalued fields are not supported yet.
70+
for (int b = 0; b < page.getBlockCount(); b++) {
71+
if (page.getBlock(b).mayHaveMultivaluedFields()) {
72+
throw new IllegalArgumentException(
73+
"ES|QL response field [" + columns.get(b).name + "] is multi-valued. This isn't supported yet by the Arrow format"
74+
);
75+
}
76+
}
6877
}
6978
rest.add(new EndResponse(this));
7079
segments = rest.iterator();

x-pack/plugin/esql/arrow/src/test/java/org/elasticsearch/xpack/esql/arrow/ArrowResponseTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,41 @@ public void testSingleBlock() throws IOException {
260260
compareEsqlAndArrow(testCase);
261261
}
262262

263+
/**
264+
* Test that multivalued arrays are rejected
265+
*/
266+
public void testMultivaluedField() throws IOException {
267+
IntBlock.Builder builder = BLOCK_FACTORY.newIntBlockBuilder(0);
268+
builder.appendInt(42);
269+
builder.appendInt(43);
270+
builder.beginPositionEntry();
271+
builder.appendInt(44);
272+
builder.appendInt(45);
273+
builder.endPositionEntry();
274+
builder.appendInt(46);
275+
IntBlock block = builder.build();
276+
277+
// Consistency check
278+
assertTrue(block.mayHaveMultivaluedFields());
279+
assertEquals(0, block.getFirstValueIndex(0));
280+
assertEquals(1, block.getValueCount(0));
281+
assertEquals(1, block.getValueCount(1));
282+
283+
assertEquals(2, block.getValueCount(2));
284+
assertEquals(2, block.getFirstValueIndex(2));
285+
assertEquals(45, block.getInt(block.getFirstValueIndex(2) + 1));
286+
287+
assertEquals(4, block.getFirstValueIndex(3));
288+
289+
var column = TestColumn.create("some-field", "integer");
290+
TestCase testCase = new TestCase(List.of(column), List.of(new TestPage(List.of(new TestBlock(column, block, Density.Dense)))));
291+
292+
IllegalArgumentException exc = assertThrows(IllegalArgumentException.class, () -> compareEsqlAndArrow(testCase));
293+
294+
assertEquals("ES|QL response field [some-field] is multi-valued. This isn't supported yet by the Arrow format", exc.getMessage());
295+
296+
}
297+
263298
/**
264299
* Test a random set of types/columns/pages/densities
265300
*/

0 commit comments

Comments
 (0)