use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestScanOperExecOuputSchema method testStrictProvidedSchemaWithWildcard.
@Test
public void testStrictProvidedSchemaWithWildcard() {
TupleMetadata providedSchema = new SchemaBuilder().add("a", // Projected, in reader
MinorType.INT).add("d", // Projected, not in reader
MinorType.BIGINT).add("e", // Not projected, not in reader
MinorType.BIGINT).buildSchema();
providedSchema.metadata("d").setDefaultValue("20");
providedSchema.metadata("e").setDefaultValue("30");
providedSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder();
// Project schema only
builder.setProjection(RowSetTestUtils.projectAll());
builder.addReader(new MockSimpleReader());
builder.builder.providedSchema(providedSchema);
builder.builder.nullType(Types.optional(MinorType.VARCHAR));
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("d", MinorType.BIGINT).add("e", MinorType.BIGINT).buildSchema();
// Initial schema
assertTrue(scan.buildSchema());
{
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).build();
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
}
// Batch with defaults and null types
assertTrue(scan.next());
{
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, 20L, 30L).build();
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
}
assertFalse(scan.next());
scanFixture.close();
}
use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestScanBatchWriters method sanityTest.
@Test
public void sanityTest() throws Exception {
Scan scanConfig = new AbstractSubScan("bob") {
@Override
public String getOperatorType() {
return "";
}
};
OperatorContext opContext = fixture.newOperatorContext(scanConfig);
// Setup: normally done by ScanBatch
VectorContainer container = new VectorContainer(fixture.allocator());
OutputMutator output = new ScanBatch.Mutator(opContext, fixture.allocator(), container);
DrillBuf buffer = opContext.getManagedBuffer();
try (VectorContainerWriter writer = new VectorContainerWriter(output)) {
// Per-batch
writer.allocate();
writer.reset();
BaseWriter.MapWriter map = writer.rootAsMap();
// Write one record (10, "Fred", [100, 110, 120] )
map.integer("a").writeInt(10);
byte[] bytes = "Fred".getBytes("UTF-8");
buffer.setBytes(0, bytes, 0, bytes.length);
map.varChar("b").writeVarChar(0, bytes.length, buffer);
try (ListWriter list = map.list("c")) {
list.startList();
list.integer().writeInt(100);
list.integer().writeInt(110);
list.integer().writeInt(120);
list.endList();
// Write another record: (20, "Wilma", [])
writer.setPosition(1);
map.integer("a").writeInt(20);
bytes = "Wilma".getBytes("UTF-8");
buffer.setBytes(0, bytes, 0, bytes.length);
map.varChar("b").writeVarChar(0, bytes.length, buffer);
writer.setValueCount(2);
// Wrap-up done by ScanBatch
container.setRecordCount(2);
container.buildSchema(SelectionVectorMode.NONE);
RowSet rowSet = fixture.wrap(container);
// Expected
TupleMetadata schema = new SchemaBuilder().addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).addArray("c", MinorType.INT).buildSchema();
RowSet expected = fixture.rowSetBuilder(schema).addRow(10, "Fred", new int[] { 100, 110, 120 }).addRow(20, "Wilma", null).build();
new RowSetComparison(expected).verifyAndClearAll(rowSet);
}
} finally {
opContext.close();
}
}
use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestParquetMetadataCache method testEmptyDirectoryWithMetadataDirFile.
@Test
public void testEmptyDirectoryWithMetadataDirFile() throws Exception {
final String emptyDirNameWithMetadataFile = "empty_directory";
dirTestWatcher.makeTestTmpSubDir(Paths.get(emptyDirNameWithMetadataFile));
dirTestWatcher.makeTestTmpSubDir(Paths.get(emptyDirNameWithMetadataFile, "t2"));
dirTestWatcher.makeTestTmpSubDir(Paths.get(emptyDirNameWithMetadataFile, "t1"));
dirTestWatcher.copyResourceToTestTmp(Paths.get("parquet", "metadata_files_with_old_versions", "v3_1", "metadata_directories.requires_replace.txt"), Paths.get(emptyDirNameWithMetadataFile, Metadata.METADATA_DIRECTORIES_FILENAME));
final BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(new SchemaBuilder()).build();
testBuilder().sqlQuery("select * from dfs.tmp.`%s`", emptyDirNameWithMetadataFile).schemaBaseLine(expectedSchema).build().run();
}
use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestSequenceFileReader method testExplicitQuery.
@Test
public void testExplicitQuery() throws Exception {
String sql = "select convert_from(binary_key, 'UTF8') as binary_key from cp.`sequencefiles/simple.seq`";
QueryBuilder builder = client.queryBuilder().sql(sql);
RowSet sets = builder.rowSet();
TupleMetadata schema = new SchemaBuilder().addNullable(SequenceFileBatchReader.KEY_SCHEMA, MinorType.VARCHAR).build();
RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow(byteWritableString("key0")).addRow(byteWritableString("key1")).build();
assertEquals(2, sets.rowCount());
new RowSetComparison(expected).verifyAndClearAll(sets);
}
use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestBatchSizingMemoryUtil method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() {
schema = new SchemaBuilder().add("name_vchar", TypeProtos.MinorType.VARCHAR, TypeProtos.DataMode.REQUIRED).add("name_vbinary", TypeProtos.MinorType.VARBINARY, TypeProtos.DataMode.REQUIRED).add("name_vdecimal", TypeProtos.MinorType.VARDECIMAL, TypeProtos.DataMode.REQUIRED).buildSchema();
nullableSchema = new SchemaBuilder().add("name_vchar", TypeProtos.MinorType.VARCHAR, TypeProtos.DataMode.OPTIONAL).add("name_vbinary", TypeProtos.MinorType.VARBINARY, TypeProtos.DataMode.OPTIONAL).add("name_vdecimal", TypeProtos.MinorType.VARDECIMAL, TypeProtos.DataMode.OPTIONAL).buildSchema();
}
Aggregations