Search in sources :

Example 16 with RowSetBuilder

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

the class TestSorter method testEmptyRowSet.

// Test degenerate case: no rows
@Test
public void testEmptyRowSet() throws Exception {
    BatchSchema schema = SortTestUtilities.nonNullSchema();
    SingleRowSet rowSet = new RowSetBuilder(fixture.allocator(), schema).withSv2().build();
    SingleRowSet expected = new RowSetBuilder(fixture.allocator(), schema).build();
    runSorterTest(rowSet, expected);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 17 with RowSetBuilder

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

the class TestExternalSort method testNewColumns.

private void testNewColumns(boolean testLegacy) throws Exception {
    final int record_count = 10000;
    final String tableDirName = "newColumns";
    {
        final BatchSchema schema = new SchemaBuilder().add("a", TypeProtos.MinorType.INT).add("b", TypeProtos.MinorType.INT).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 0; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i, i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "a.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    {
        final BatchSchema schema = new SchemaBuilder().add("a", TypeProtos.MinorType.INT).add("c", TypeProtos.MinorType.INT).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i, i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    // Test framework currently doesn't handle changing schema (i.e. new
    // columns) on the client side
    TestBuilder builder = testBuilder().sqlQuery("select a, b, c from dfs.`%s` order by a desc", tableDirName).ordered().optionSettingQueriesForTestQuery(getOptions(testLegacy)).baselineColumns("a", "b", "c");
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i, (long) i--, null);
        if (i >= 0) {
            builder.baselineValues((long) i, null, (long) i--);
        }
    }
    builder.go();
    // TODO: Useless test: just dumps to console
    test("select * from dfs.`%s` order by a desc", tableDirName);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSet(org.apache.drill.test.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder)

Example 18 with RowSetBuilder

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

the class TestExternalSort method testNumericAndStringTypes.

private void testNumericAndStringTypes(boolean testLegacy) throws Exception {
    final int record_count = 10000;
    final String tableDirName = "numericAndStringTypes";
    {
        final BatchSchema schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 0; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "a.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    {
        final BatchSchema schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).setCustomFormatter("a", "\"%05d\"").build(tableFile);
        rowSet.clear();
    }
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by a desc", tableDirName).ordered().optionSettingQueriesForTestQuery(getOptions(testLegacy)).baselineColumns("a");
    // Strings come first because order by is desc
    for (int i = record_count; i >= 0; ) {
        i--;
        if (i >= 0) {
            builder.baselineValues(String.format("%05d", i--));
        }
    }
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i--);
        i--;
    }
    builder.go();
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSet(org.apache.drill.test.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder)

Example 19 with RowSetBuilder

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

the class AbstractGenericCopierTest method testAppendRecords.

@Test
public void testAppendRecords() throws SchemaChangeException {
    try (RootAllocator allocator = new RootAllocator(10_000_000)) {
        final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
        final RowSet srcRowSet = createSrcRowSet(allocator);
        final RowSet destRowSet = new RowSetBuilder(allocator, batchSchema).build();
        final VectorContainer destContainer = destRowSet.container();
        final Copier copier = createCopier();
        final RowSet expectedRowSet = createExpectedRowset(allocator);
        copier.setup(new RowSetBatch(srcRowSet), destContainer);
        copier.appendRecord(0);
        copier.appendRecords(1, 2);
        try {
            new RowSetComparison(expectedRowSet).verify(destRowSet);
        } finally {
            srcRowSet.clear();
            if (srcRowSet instanceof RowSet.HyperRowSet) {
                ((RowSet.HyperRowSet) srcRowSet).getSv4().clear();
            }
            destRowSet.clear();
            expectedRowSet.clear();
        }
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RootAllocator(org.apache.drill.exec.memory.RootAllocator) RowSetBatch(org.apache.drill.test.rowSet.RowSetBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test)

Example 20 with RowSetBuilder

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

the class GenericSV4CopierTest method createSrcRowSet.

@Override
public RowSet createSrcRowSet(RootAllocator allocator) throws SchemaChangeException {
    final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
    final DrillBuf drillBuf = allocator.buffer(4 * 3);
    final SelectionVector4 sv4 = new SelectionVector4(drillBuf, 3, Character.MAX_VALUE);
    final VectorContainer batch1 = new RowSetBuilder(allocator, batchSchema).addRow(row1()).addRow(row4()).build().container();
    final VectorContainer batch2 = new RowSetBuilder(allocator, batchSchema).addRow(row2()).addRow(row5()).addRow(row3()).build().container();
    final ExpandableHyperContainer hyperContainer = new ExpandableHyperContainer(batch1);
    hyperContainer.addBatch(batch2);
    sv4.set(0, 0, 0);
    sv4.set(1, 1, 0);
    sv4.set(2, 1, 2);
    return new HyperRowSetImpl(hyperContainer, sv4);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) ExpandableHyperContainer(org.apache.drill.exec.record.ExpandableHyperContainer) BatchSchema(org.apache.drill.exec.record.BatchSchema) HyperRowSetImpl(org.apache.drill.test.rowSet.HyperRowSetImpl) DrillBuf(io.netty.buffer.DrillBuf) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)27 RowSet (org.apache.drill.test.rowSet.RowSet)23 Test (org.junit.Test)23 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)18 BatchSchema (org.apache.drill.exec.record.BatchSchema)17 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)14 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)11 SubOperatorTest (org.apache.drill.test.SubOperatorTest)11 ValueVector (org.apache.drill.exec.vector.ValueVector)10 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)9 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)8 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)7 ClusterTest (org.apache.drill.test.ClusterTest)5 File (java.io.File)4 OperatorTest (org.apache.drill.categories.OperatorTest)4 RootAllocator (org.apache.drill.exec.memory.RootAllocator)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 JsonFileBuilder (org.apache.drill.test.rowSet.file.JsonFileBuilder)4 VariableWidthVector (org.apache.drill.exec.vector.VariableWidthVector)3 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)3