Search in sources :

Example 6 with SchemaBuilder

use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.

the class TestMiniPlan method testSimpleJson.

@Test
public void testSimpleJson() throws Exception {
    List<String> jsonBatches = Lists.newArrayList("{\"a\":100}");
    RecordBatch scanBatch = new JsonScanBuilder().jsonBatches(jsonBatches).build();
    BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).build();
    new MiniPlanTestBuilder().root(scanBatch).expectedSchema(expectedSchema).baselineValues(100L).go();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) Test(org.junit.Test)

Example 7 with SchemaBuilder

use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.

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).add("col1.1", "col1.2").add("col2.1", "col2.2").add("col3.1", null).add("col4.1", "col4.2").build();
    BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
    validator.validate();
    assertTrue(validator.errors().isEmpty());
    batch.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) Test(org.junit.Test)

Example 8 with SchemaBuilder

use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.

the class TestBatchValidator method testVariableCorruptMiddleHigh.

@Test
public void testVariableCorruptMiddleHigh() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add("xx").add("yy").add("zz").build();
    zapOffset(batch, 1, 10);
    // Validator should catch the error.
    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();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) Test(org.junit.Test)

Example 9 with SchemaBuilder

use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.

the class RowSetTest method testIntRW.

private void testIntRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.INT).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0).add(Integer.MAX_VALUE).add(Integer.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getInt());
    assertTrue(reader.next());
    assertEquals(Integer.MAX_VALUE, reader.column(0).getInt());
    assertTrue(reader.next());
    assertEquals(Integer.MIN_VALUE, reader.column(0).getInt());
    assertFalse(reader.next());
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader)

Example 10 with SchemaBuilder

use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.

the class RowSetTest method TestTopScalarArray.

@Test
public void TestTopScalarArray() {
    BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addArray("a", MinorType.INT).build();
    ExtendableRowSet rs1 = fixture.rowSet(batchSchema);
    RowSetWriter writer = rs1.writer();
    writer.column(0).setInt(10);
    ArrayWriter array = writer.column(1).array();
    array.setInt(100);
    array.setInt(110);
    writer.save();
    writer.column(0).setInt(20);
    array = writer.column(1).array();
    array.setInt(200);
    array.setInt(120);
    array.setInt(220);
    writer.save();
    writer.column(0).setInt(30);
    writer.save();
    writer.done();
    RowSetReader reader = rs1.reader();
    assertTrue(reader.next());
    assertEquals(10, reader.column(0).getInt());
    ArrayReader arrayReader = reader.column(1).array();
    assertEquals(2, arrayReader.size());
    assertEquals(100, arrayReader.getInt(0));
    assertEquals(110, arrayReader.getInt(1));
    assertTrue(reader.next());
    assertEquals(20, reader.column(0).getInt());
    arrayReader = reader.column(1).array();
    assertEquals(3, arrayReader.size());
    assertEquals(200, arrayReader.getInt(0));
    assertEquals(120, arrayReader.getInt(1));
    assertEquals(220, arrayReader.getInt(2));
    assertTrue(reader.next());
    assertEquals(30, reader.column(0).getInt());
    arrayReader = reader.column(1).array();
    assertEquals(0, arrayReader.size());
    assertFalse(reader.next());
    SingleRowSet rs2 = fixture.rowSetBuilder(batchSchema).add(10, new int[] { 100, 110 }).add(20, new int[] { 200, 120, 220 }).add(30, null).build();
    new RowSetComparison(rs1).verifyAndClear(rs2);
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSet.RowSetWriter) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) Test(org.junit.Test)

Aggregations

BatchSchema (org.apache.drill.exec.record.BatchSchema)26 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)26 Test (org.junit.Test)20 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)18 BatchValidator (org.apache.drill.exec.physical.impl.validate.BatchValidator)10 RowSetReader (org.apache.drill.test.rowSet.RowSet.RowSetReader)8 RecordBatch (org.apache.drill.exec.record.RecordBatch)4 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)3 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)3 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)3 ValueVector (org.apache.drill.exec.vector.ValueVector)3 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)3 Filter (org.apache.drill.exec.physical.config.Filter)2 UnionAll (org.apache.drill.exec.physical.config.UnionAll)2 VarCharVector (org.apache.drill.exec.vector.VarCharVector)2 ClusterTest (org.apache.drill.test.ClusterTest)2 RowSet (org.apache.drill.test.rowSet.RowSet)2 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)2 RowSetSchema (org.apache.drill.test.rowSet.RowSetSchema)2 PhysicalSchema (org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema)2