Search in sources :

Example 36 with BatchSchema

use of org.apache.drill.exec.record.BatchSchema 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 37 with BatchSchema

use of org.apache.drill.exec.record.BatchSchema 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)

Example 38 with BatchSchema

use of org.apache.drill.exec.record.BatchSchema in project drill by apache.

the class TestBatchValidator method testVariableMissingLast.

@Test
public void testVariableMissingLast() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add("x").add("y").add("z").build();
    // Here we are evil: stomp on the last offset to simulate corruption.
    // Don't do this in real code!
    VectorAccessible va = batch.vectorAccessible();
    @SuppressWarnings("resource") ValueVector v = va.iterator().next().getValueVector();
    VarCharVector vc = (VarCharVector) v;
    @SuppressWarnings("resource") UInt4Vector ov = vc.getOffsetVector();
    assertTrue(ov.getAccessor().get(3) > 0);
    ov.getMutator().set(3, 0);
    // 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 : ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) Test(org.junit.Test)

Example 39 with BatchSchema

use of org.apache.drill.exec.record.BatchSchema in project drill by apache.

the class DrillColumnMetaDataListTest method setUp.

@Before
public void setUp() throws Exception {
    emptyList = new DrillColumnMetaDataList();
    // Create mock columns
    final MaterializedField exampleIntField = mock(MaterializedField.class);
    MajorType exampleIntType = MajorType.newBuilder().setMinorType(MinorType.INT).build();
    when(exampleIntField.getPath()).thenReturn("/path/to/testInt");
    when(exampleIntField.getType()).thenReturn(exampleIntType);
    when(exampleIntField.getDataMode()).thenReturn(DataMode.OPTIONAL);
    final MaterializedField exampleStringField = mock(MaterializedField.class);
    MajorType exampleStringType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).build();
    when(exampleStringField.getPath()).thenReturn("/path/to/testString");
    when(exampleStringField.getType()).thenReturn(exampleStringType);
    when(exampleStringField.getDataMode()).thenReturn(DataMode.REQUIRED);
    oneElementList = new DrillColumnMetaDataList();
    BatchSchema oneElementSchema = mock(BatchSchema.class);
    when(oneElementSchema.getFieldCount()).thenReturn(1);
    doAnswer(new Answer<MaterializedField>() {

        @Override
        public MaterializedField answer(InvocationOnMock invocationOnMock) throws Throwable {
            Integer index = (Integer) invocationOnMock.getArguments()[0];
            if (index == 0) {
                return exampleIntField;
            }
            return null;
        }
    }).when(oneElementSchema).getColumn(Mockito.anyInt());
    List<Class<?>> oneClassList = new ArrayList<>();
    oneClassList.add(Integer.class);
    oneElementList.updateColumnMetaData("testCatalog", "testSchema", "testTable", oneElementSchema, oneClassList);
    twoElementList = new DrillColumnMetaDataList();
    BatchSchema twoElementSchema = mock(BatchSchema.class);
    when(twoElementSchema.getFieldCount()).thenReturn(2);
    doAnswer(new Answer<MaterializedField>() {

        @Override
        public MaterializedField answer(InvocationOnMock invocationOnMock) throws Throwable {
            Integer index = (Integer) invocationOnMock.getArguments()[0];
            if (index == 0) {
                return exampleIntField;
            } else if (index == 1) {
                return exampleStringField;
            }
            return null;
        }
    }).when(twoElementSchema).getColumn(Mockito.anyInt());
    List<Class<?>> twoClassList = new ArrayList<>();
    twoClassList.add(Integer.class);
    twoClassList.add(String.class);
    twoElementList.updateColumnMetaData("testCatalog", "testSchema", "testTable", twoElementSchema, twoClassList);
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) DrillColumnMetaDataList(org.apache.drill.jdbc.impl.DrillColumnMetaDataList) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ArrayList(java.util.ArrayList) MaterializedField(org.apache.drill.exec.record.MaterializedField) Before(org.junit.Before)

Aggregations

BatchSchema (org.apache.drill.exec.record.BatchSchema)39 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 MaterializedField (org.apache.drill.exec.record.MaterializedField)7 ValueVector (org.apache.drill.exec.vector.ValueVector)6 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 RecordBatch (org.apache.drill.exec.record.RecordBatch)4 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 ArrayList (java.util.ArrayList)3 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)3 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)3 DrillBuf (io.netty.buffer.DrillBuf)2 IOException (java.io.IOException)2 UserException (org.apache.drill.common.exceptions.UserException)2 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)2 MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)2