Search in sources :

Example 11 with RowSetBuilder

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

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();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("10", "foo", "bar").build();
    new RowSetComparison(expected).verifyAndClearAll(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.schema.SchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 12 with RowSetBuilder

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

the class ExampleTest method secondTest.

/**
 * <p>
 *   Example that uses the fixture builder to build a cluster fixture. Lets
 *   you set configuration (boot-time) options, session options, system options
 *   and more.
 * </p>
 * <p>
 *   You can write test files to the {@link BaseDirTestWatcher#getRootDir()} and query them in the test.
 * </p>
 * <p>
 *   Also shows how to display the plan JSON and just run a query silently,
 *   getting just the row count, batch count and run time.
 * </p>
 * @throws Exception if anything goes wrong
 */
@Test
public void secondTest() throws Exception {
    try (RootAllocator allocator = new RootAllocator(100_000_000)) {
        final File tableFile = dirTestWatcher.getRootDir().toPath().resolve("employee.json").toFile();
        final BatchSchema schema = new SchemaBuilder().add("id", Types.required(TypeProtos.MinorType.VARCHAR)).add("name", Types.required(TypeProtos.MinorType.VARCHAR)).build();
        final RowSet rowSet = new RowSetBuilder(allocator, schema).addRow("1", "kiwi").addRow("2", "watermelon").build();
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
        ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).configProperty(ExecConstants.SLICE_TARGET, 10);
        try (ClusterFixture cluster = builder.build();
            ClientFixture client = cluster.clientFixture()) {
            String sql = "SELECT * FROM `dfs`.`test/employee.json`";
            System.out.println(client.queryBuilder().sql(sql).explainJson());
            QuerySummary results = client.queryBuilder().sql(sql).run();
            System.out.println(String.format("Read %d rows", results.recordCount()));
            // Usually we want to test something. Here, just test that we got
            // the 2 records.
            assertEquals(2, results.recordCount());
        }
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RootAllocator(org.apache.drill.exec.memory.RootAllocator) BatchSchema(org.apache.drill.exec.record.BatchSchema) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) 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) Test(org.junit.Test)

Example 13 with RowSetBuilder

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

the class TestCsv method testInvalidCsvHeaders.

@Test
public void testInvalidCsvHeaders() throws IOException {
    String fileName = "case3.csv";
    buildFile(fileName, invalidHeaders);
    RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
    BatchSchema expectedSchema = new SchemaBuilder().add("column_1", MinorType.VARCHAR).add("column_2", MinorType.VARCHAR).add("col_9b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).add("c_2", MinorType.VARCHAR).add("c_2_2", MinorType.VARCHAR).build();
    assertEquals(expectedSchema, actual.batchSchema());
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).add("10", "foo", "bar", "fourth", "fifth", "sixth").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 14 with RowSetBuilder

use of org.apache.drill.test.rowSet.RowSetBuilder 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 15 with RowSetBuilder

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

the class TestShortArrays method testSizer.

@Test
public void testSizer() {
    // Create a row set with less than one item, on
    // average, per array.
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.INT).build();
    RowSetBuilder builder = fixture.rowSetBuilder(schema).addRow(1, intArray(10));
    for (int i = 2; i <= 10; i++) {
        builder.addRow(i, intArray());
    }
    RowSet rows = builder.build();
    // Run the record batch sizer on the resulting batch.
    RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
    assertEquals(2, sizer.columns().size());
    ColumnSize bCol = sizer.columns().get("b");
    assertEquals(0.1, bCol.getCardinality(), 0.01);
    assertEquals(1, bCol.getElementCount());
    // Create a vector initializer using the sizer info.
    VectorInitializer vi = sizer.buildVectorInitializer();
    AllocationHint bHint = vi.hint("b");
    assertNotNull(bHint);
    assertEquals(bHint.elementCount, bCol.getCardinality(), 0.001);
    // Create a new batch, and new vector, using the sizer and
    // initializer inferred from the previous batch.
    SingleRowSet empty = fixture.rowSet(schema);
    vi.allocateBatch(empty.container(), 100);
    assertEquals(2, empty.container().getNumberOfColumns());
    @SuppressWarnings("resource") ValueVector bVector = empty.container().getValueVector(1).getValueVector();
    assertTrue(bVector instanceof RepeatedIntVector);
    assertEquals(16, ((RepeatedIntVector) bVector).getDataVector().getValueCapacity());
    rows.clear();
    empty.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) VectorInitializer(org.apache.drill.exec.record.VectorInitializer) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) AllocationHint(org.apache.drill.exec.record.VectorInitializer.AllocationHint) AllocationHint(org.apache.drill.exec.record.VectorInitializer.AllocationHint) ValueVector(org.apache.drill.exec.vector.ValueVector) RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RecordBatchSizer(org.apache.drill.exec.record.RecordBatchSizer) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

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