Search in sources :

Example 1 with JsonFileBuilder

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

the class TestExternalSort method testNumericTypes.

/**
 * Test union type support in sort using numeric types: BIGINT and FLOAT8
 * Drill does not support union types fully. Sort was adapted to handle them.
 * This test simply verifies that the sort handles these types, even though
 * Drill does not.
 *
 * @param testLegacy
 *          true to test the old (pre-1.11) sort, false to test the new (1.11
 *          and later) sort
 * @throws Exception
 */
private void testNumericTypes(boolean testLegacy) throws Exception {
    final int record_count = 10000;
    final String tableDirName = "numericTypes";
    {
        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.FLOAT4)).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow((float) i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).setCustomFormatter("a", "%.2f").build(tableFile);
        rowSet.clear();
    }
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by a desc", tableDirName).optionSettingQueriesForTestQuery(getOptions(testLegacy)).ordered().baselineColumns("a");
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i--);
        if (i >= 0) {
            builder.baselineValues((double) 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 2 with JsonFileBuilder

use of org.apache.drill.test.rowSet.file.JsonFileBuilder 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 3 with JsonFileBuilder

use of org.apache.drill.test.rowSet.file.JsonFileBuilder 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 4 with JsonFileBuilder

use of org.apache.drill.test.rowSet.file.JsonFileBuilder 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 5 with JsonFileBuilder

use of org.apache.drill.test.rowSet.file.JsonFileBuilder in project drill by apache.

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 TupleMetadata schema = new SchemaBuilder().add("id", Types.required(TypeProtos.MinorType.VARCHAR)).add("name", Types.required(TypeProtos.MinorType.VARCHAR)).buildSchema();
        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`";
            logger.info(client.queryBuilder().sql(sql).explainJson());
            QuerySummary results = client.queryBuilder().sql(sql).run();
            logger.info(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.exec.physical.rowSet.RowSetBuilder) RootAllocator(org.apache.drill.exec.memory.RootAllocator) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)8 JsonFileBuilder (org.apache.drill.test.rowSet.file.JsonFileBuilder)8 TestBuilder (org.apache.drill.test.TestBuilder)6 Test (org.junit.Test)5 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)4 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)4 BatchSchema (org.apache.drill.exec.record.BatchSchema)4 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)4 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)4 RowSet (org.apache.drill.test.rowSet.RowSet)4 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)4 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)4 OperatorTest (org.apache.drill.categories.OperatorTest)3 SlowTest (org.apache.drill.categories.SlowTest)3 RootAllocator (org.apache.drill.exec.memory.RootAllocator)2 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)2 Ignore (org.junit.Ignore)1