Search in sources :

Example 26 with SchemaBuilder

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

the class TestRecordBatchSizer method testEmptyVariableWidthVector.

/**
 * Test to verify that record batch sizer handles the actual empty vectors correctly. RowSetBuilder by default
 * allocates Drillbuf of 10bytes for each vector type which makes their capacity >0 and not ==0 which will be in
 * case of empty vectors.
 */
@Test
public void testEmptyVariableWidthVector() {
    final BatchSchema schema = new SchemaBuilder().add("key", MinorType.INT).add("value", MinorType.VARCHAR).build();
    final RowSetBuilder builder = fixture.rowSetBuilder(schema);
    final RowSet rows = builder.build();
    // Release the initial bytes allocated by RowSetBuilder
    VectorAccessibleUtilities.clear(rows.container());
    try {
        // Create RecordBatchSizer for this empty container and it should not fail
        final RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
        int totalDataSize = 0;
        for (ColumnSize colSize : sizer.columns().values()) {
            totalDataSize += colSize.getTotalDataSize();
        }
        // Verify that the totalDataSize for all the columns is zero
        assertEquals(0, totalDataSize);
    } catch (Exception ex) {
        fail();
    } finally {
        rows.clear();
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 27 with SchemaBuilder

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

the class TestTupleSchema method testNestedSchema.

@Test
public void testNestedSchema() {
    TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).addMap().add("a", MinorType.INT).add("b", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.FLOAT8).addType(MinorType.DECIMAL18).buildNested().resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata col = schema.metadata(0);
    assertTrue(col.isVariant());
    VariantMetadata union = col.variantSchema();
    assertNotNull(union);
    assertEquals(4, union.size());
    assertTrue(union.hasType(MinorType.MAP));
    assertTrue(union.hasType(MinorType.LIST));
    ColumnMetadata mapCol = union.member(MinorType.MAP);
    TupleMetadata mapSchema = mapCol.mapSchema();
    assertEquals(2, mapSchema.size());
    ColumnMetadata listCol = union.member(MinorType.LIST);
    VariantMetadata listSchema = listCol.variantSchema();
    assertEquals(2, listSchema.size());
    assertTrue(listSchema.hasType(MinorType.FLOAT8));
    assertTrue(listSchema.hasType(MinorType.DECIMAL18));
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) MapColumnMetadata(org.apache.drill.exec.record.metadata.MapColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 28 with SchemaBuilder

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

the class TestLoad method testSchemaChange.

@Test
public void testSchemaChange() throws SchemaChangeException {
    final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
    final RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
    // Initial schema: a: INT, b: VARCHAR
    // Schema change: N/A
    BatchSchema schema1 = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
    {
        assertTrue(loadBatch(allocator, batchLoader, schema1));
        assertTrue(schema1.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    // Same schema
    // Schema change: No
    {
        assertFalse(loadBatch(allocator, batchLoader, schema1));
        assertTrue(schema1.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    // Reverse columns: b: VARCHAR, a: INT
    // Schema change: No
    {
        BatchSchema schema = new SchemaBuilder().add("b", MinorType.VARCHAR).add("a", MinorType.INT).build();
        assertFalse(loadBatch(allocator, batchLoader, schema));
        // Potential bug: see DRILL-5828
        assertTrue(schema.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    // Drop a column: a: INT
    // Schema change: Yes
    {
        BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).build();
        assertTrue(loadBatch(allocator, batchLoader, schema));
        assertTrue(schema.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    // Add a column: a: INT, b: VARCHAR, c: INT
    // Schema change: Yes
    {
        assertTrue(loadBatch(allocator, batchLoader, schema1));
        assertTrue(schema1.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
        BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).add("c", MinorType.INT).build();
        assertTrue(loadBatch(allocator, batchLoader, schema));
        assertTrue(schema.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    // Change a column type: a: INT, b: VARCHAR, c: VARCHAR
    // Schema change: Yes
    {
        BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).build();
        assertTrue(loadBatch(allocator, batchLoader, schema));
        assertTrue(schema.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    // Empty schema
    // Schema change: Yes
    {
        BatchSchema schema = new SchemaBuilder().build();
        assertTrue(loadBatch(allocator, batchLoader, schema));
        assertTrue(schema.isEquivalent(batchLoader.getSchema()));
        batchLoader.getContainer().zeroVectors();
    }
    batchLoader.clear();
    allocator.close();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest)

Example 29 with SchemaBuilder

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

the class TestMiniPlan method testUnionFilter.

@Test
public void testUnionFilter() throws Exception {
    List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 1 }]", "[{\"a\": 5, \"b\" : 5},{\"a\": 3, \"b\" : 8}]", "[{\"a\": 40, \"b\" : 3},{\"a\": 13, \"b\" : 100}]");
    List<String> rightJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 10 }]", "[{\"a\": 50, \"b\" : 100}]");
    RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
    new UnionAll(Collections.<PhysicalOperator>emptyList())).addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=5"), 1.0f)).addJsonScanAsChild().jsonBatches(leftJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=50"), 1.0f)).addJsonScanAsChild().jsonBatches(rightJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().build();
    BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.BIGINT).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
    new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).baselineValues(5l, 1l).baselineValues(5l, 5l).baselineValues(50l, 100l).go();
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) UnionAll(org.apache.drill.exec.physical.config.UnionAll) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest)

Example 30 with SchemaBuilder

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

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).expectSchema(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.schema.SchemaBuilder) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest)

Aggregations

SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)175 Test (org.junit.Test)154 BatchSchema (org.apache.drill.exec.record.BatchSchema)102 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)91 SubOperatorTest (org.apache.drill.test.SubOperatorTest)86 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)65 RowSet (org.apache.drill.test.rowSet.RowSet)52 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)50 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)38 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)38 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)26 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)25 DrillTest (org.apache.drill.test.DrillTest)21 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)20 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)18 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)18 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)17 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)16 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)16 RecordBatch (org.apache.drill.exec.record.RecordBatch)14