Search in sources :

Example 21 with SchemaBuilder

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

the class RowSetTest method testSchema.

/**
   * Test a simple physical schema with no maps.
   */
@Test
public void testSchema() {
    BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).add("a", MinorType.INT, DataMode.REPEATED).addNullable("b", MinorType.VARCHAR).build();
    assertEquals("c", batchSchema.getColumn(0).getName());
    assertEquals("a", batchSchema.getColumn(1).getName());
    assertEquals("b", batchSchema.getColumn(2).getName());
    RowSetSchema schema = new RowSetSchema(batchSchema);
    TupleSchema access = schema.hierarchicalAccess();
    assertEquals(3, access.count());
    crossCheck(access, 0, "c", MinorType.INT);
    assertEquals(DataMode.REQUIRED, access.column(0).getDataMode());
    assertEquals(DataMode.REQUIRED, access.column(0).getType().getMode());
    assertTrue(!access.column(0).isNullable());
    crossCheck(access, 1, "a", MinorType.INT);
    assertEquals(DataMode.REPEATED, access.column(1).getDataMode());
    assertEquals(DataMode.REPEATED, access.column(1).getType().getMode());
    assertTrue(!access.column(1).isNullable());
    crossCheck(access, 2, "b", MinorType.VARCHAR);
    assertEquals(MinorType.VARCHAR, access.column(2).getType().getMinorType());
    assertEquals(DataMode.OPTIONAL, access.column(2).getDataMode());
    assertEquals(DataMode.OPTIONAL, access.column(2).getType().getMode());
    assertTrue(access.column(2).isNullable());
    // No maps: physical schema is the same as access schema.
    PhysicalSchema physical = schema.physical();
    assertEquals(3, physical.count());
    assertEquals("c", physical.column(0).field().getName());
    assertEquals("a", physical.column(1).field().getName());
    assertEquals("b", physical.column(2).field().getName());
}
Also used : PhysicalSchema(org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetSchema(org.apache.drill.test.rowSet.RowSetSchema) TupleSchema(org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema) Test(org.junit.Test)

Example 22 with SchemaBuilder

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

the class RowSetTest method testFloatRW.

private void testFloatRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT4).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0F).add(Float.MAX_VALUE).add(Float.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getDouble(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Float.MAX_VALUE, reader.column(0).getDouble(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Float.MIN_VALUE, reader.column(0).getDouble(), 0.000001);
    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 23 with SchemaBuilder

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

the class TestCsv method testInvalidCsvHeaders.

@Test
public void testInvalidCsvHeaders() throws IOException {
    String fileName = "case3.csv";
    buildFile(fileName, invalidHeaders);
    RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
    BatchSchema expectedSchema = new SchemaBuilder().add("column_1", MinorType.VARCHAR).add("column_2", MinorType.VARCHAR).add("col_9b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).add("c_2", MinorType.VARCHAR).add("c_2_2", MinorType.VARCHAR).build();
    assertEquals(expectedSchema, actual.batchSchema());
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).add("10", "foo", "bar", "fourth", "fifth", "sixth").build();
    new RowSetComparison(expected).verifyAndClear(actual);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 24 with SchemaBuilder

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

the class TestCsv method testValidCsvHeaders.

@Test
public void testValidCsvHeaders() throws IOException {
    String fileName = "case2.csv";
    buildFile(fileName, validHeaders);
    RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
    BatchSchema expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).build();
    assertEquals(expectedSchema, actual.batchSchema());
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).add("10", "foo", "bar").build();
    new RowSetComparison(expected).verifyAndClear(actual);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 25 with SchemaBuilder

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

the class TestBatchValidator method testVariableCorruptFirst.

@Test
public void testVariableCorruptFirst() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add("x").add("y").add("z").build();
    zapOffset(batch, 0, 1);
    // 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("Offset (0) must be 0"));
    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)

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