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);
}
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();
}
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();
}
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);
}
Aggregations