use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestBatchValidator method testValidVariable.
@Test
public void testValidVariable() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).addNullable("b", MinorType.VARCHAR).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow("col1.1", "col1.2").addRow("col2.1", "col2.2").addRow("col3.1", null).addRow("col4.1", "col4.2").build();
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
assertTrue(validator.errors().isEmpty());
batch.clear();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestBatchValidator method testRepeatedBadArrayOffset.
@Test
public void testRepeatedBadArrayOffset() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR, DataMode.REPEATED).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow((Object) strArray()).addRow((Object) strArray("fred", "barney", "wilma")).addRow((Object) strArray("dino")).build();
VectorAccessible va = batch.vectorAccessible();
ValueVector v = va.iterator().next().getValueVector();
RepeatedVarCharVector vc = (RepeatedVarCharVector) v;
UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(3, 1);
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
List<String> errors = validator.errors();
assertEquals(1, errors.size());
assertTrue(errors.get(0).contains("Decreasing offsets"));
batch.clear();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestCopier method testMapType.
public void testMapType(OperatorFixture fixture) throws Exception {
BatchSchema schema = new SchemaBuilder().add("key", MinorType.INT).addMap("m1").add("b", MinorType.INT).addMap("m2").add("c", MinorType.INT).resumeMap().resumeSchema().build();
CopierTester tester = new CopierTester(fixture);
tester.addInput(fixture.rowSetBuilder(schema).addRow(1, objArray(10, objArray(100))).addRow(5, objArray(50, objArray(500))).withSv2().build());
tester.addInput(fixture.rowSetBuilder(schema).addRow(2, objArray(20, objArray(200))).addRow(6, objArray(60, objArray(600))).withSv2().build());
tester.addOutput(fixture.rowSetBuilder(schema).addRow(1, objArray(10, objArray(100))).addRow(2, objArray(20, objArray(200))).addRow(5, objArray(50, objArray(500))).addRow(6, objArray(60, objArray(600))).build());
tester.run();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestSorter method testMapKey.
@Test
@Ignore("DRILL-5384")
public void testMapKey() throws Exception {
BatchSchema schema = new SchemaBuilder().addMap("map").add("key", MinorType.INT).add("value", MinorType.VARCHAR).resumeSchema().build();
SingleRowSet input = fixture.rowSetBuilder(schema).addRow(3, "third").addRow(1, "first").addRow(2, "second").withSv2().build();
SingleRowSet output = fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, "second").addRow(3, "third").build();
Sort popConfig = makeSortConfig("map.key", Ordering.ORDER_ASC, Ordering.NULLS_LAST);
runSorterTest(popConfig, input, output);
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestResultSetLoaderMapArray method testBasics.
@Test
public void testBasics() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Verify structure and schema
TupleMetadata actualSchema = rootWriter.schema();
assertEquals(2, actualSchema.size());
assertTrue(actualSchema.metadata(1).isArray());
assertTrue(actualSchema.metadata(1).isMap());
assertEquals(2, actualSchema.metadata("m").mapSchema().size());
assertEquals(2, actualSchema.column("m").getChildren().size());
// Write a couple of rows with arrays.
rsLoader.startBatch();
rootWriter.addRow(10, objArray(objArray(110, "d1.1"), objArray(120, "d2.2"))).addRow(20, objArray()).addRow(30, objArray(objArray(310, "d3.1"), objArray(320, "d3.2"), objArray(330, "d3.3")));
// Verify the first batch
RowSet actual = fixture.wrap(rsLoader.harvest());
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(objArray(110, "d1.1"), objArray(120, "d2.2"))).addRow(20, objArray()).addRow(30, objArray(objArray(310, "d3.1"), objArray(320, "d3.2"), objArray(330, "d3.3"))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
// In the second, create a row, then add a map member.
// Should be back-filled to empty for the first row.
rsLoader.startBatch();
rootWriter.addRow(40, objArray(objArray(410, "d4.1"), objArray(420, "d4.2")));
TupleWriter mapWriter = rootWriter.array("m").tuple();
mapWriter.addColumn(SchemaBuilder.columnSchema("e", MinorType.VARCHAR, DataMode.OPTIONAL));
rootWriter.addRow(50, objArray(objArray(510, "d5.1", "e5.1"), objArray(520, "d5.2", null))).addRow(60, objArray(objArray(610, "d6.1", "e6.1"), objArray(620, "d6.2", null), objArray(630, "d6.3", "e6.3")));
// Verify the second batch
actual = fixture.wrap(rsLoader.harvest());
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).addNullable("e", MinorType.VARCHAR).resumeSchema().buildSchema();
expected = fixture.rowSetBuilder(expectedSchema).addRow(40, objArray(objArray(410, "d4.1", null), objArray(420, "d4.2", null))).addRow(50, objArray(objArray(510, "d5.1", "e5.1"), objArray(520, "d5.2", null))).addRow(60, objArray(objArray(610, "d6.1", "e6.1"), objArray(620, "d6.2", null), objArray(630, "d6.3", "e6.3"))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
rsLoader.close();
}
Aggregations