Skip to content

Commit

Permalink
fix(payloadbuilder-bytes): Add fix when missing array columns when bo…
Browse files Browse the repository at this point in the history
…th schema types was equal
  • Loading branch information
kuseman committed Aug 23, 2024
1 parent a5073c6 commit 8f85c53
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ else if (expectedType == Column.Type.Table

columns.add(new Column(expectedColumn.getName(), arrayType));
}
// Equal => pick expected
else
{
columns.add(new Column(expectedColumn.getName(), expectedColumn.getType()));
}
}
// Equal => pick expected
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,57 @@ public void test_float()
VectorTestUtils.assertVectorsEquals(v, actual);
}

/**
* Regression where we had a mismatch in input schema and payload schema
* where equal arrays wasn't re-added correctly.
*/
@Test
public void test_table_with_array_1()
{
ValueVector v;
byte[] bytes;
TupleVector expected;

// @formatter:off
Schema schema = Schema.of(
Column.of("integer", Column.Type.Int),
Column.of("array", ResolvedType.array(Type.Int)));

expected = TupleVector.of(schema,
asList(VectorTestUtils.vv(Type.Int, 2, 2, 2, 2, 2),
vv(ResolvedType.array(Type.Int), vv(Type.Int, 1,2), vv(Type.Int, 3,4), vv(Type.Int, 5,6), vv(Type.Int, 7,8), vv(Type.Int, 9,10))
));
//@formatter:on

v = ValueVector.literalTable(expected, 1);
bytes = PayloadWriter.write(v);

assertEquals(120, bytes.length);

// Read with same schema

TupleVector actual = PayloadReader.readTupleVector(bytes, schema, false);

VectorTestUtils.assertTupleVectorsEquals(expected, actual);

// @formatter:off
Schema newSchema = Schema.of(
Column.of("integer", Column.Type.Boolean), // Trigg a mismatch
Column.of("array", ResolvedType.array(Type.Int)));

// Read with a new schema that mismatches
actual = PayloadReader.readTupleVector(bytes, newSchema, false);

// Schema should reflect the new input schema
assertEquals(newSchema, actual.getSchema());

// .. but the vectors are of the actual payload types

VectorTestUtils.assertVectorsEquals(VectorTestUtils.vv(Type.Int, 2, 2, 2, 2, 2), actual.getColumn(0));
VectorTestUtils.assertVectorsEquals(vv(ResolvedType.array(Type.Int), vv(Type.Int, 1,2), vv(Type.Int, 3,4), vv(Type.Int, 5,6), vv(Type.Int, 7,8), vv(Type.Int, 9,10)), actual.getColumn(1));
// @formatter:on
}

@Test
public void test_table_with_array()
{
Expand Down

0 comments on commit 8f85c53

Please sign in to comment.