Search in sources :

Example 1 with QuerySummary

use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by axbaretto.

the class ExampleTest method fourthTest.

/**
 * Example using custom logging. Here we run a sort with trace logging enabled
 * for just the sort class, and with logging displayed to the console.
 * <p>
 * This example also shows setting up a realistic set of options prior to
 * running a query. Note that we pass in normal Java values (don't have to
 * encode the values as a string.)
 * <p>
 * Finally, also shows defining your own ad-hoc local file workspace to
 * point to a sample data file.
 * <p>
 * Unlike the other tests, don't actually run this one. It points to
 * a location on a local machine. And, the query itself takes 23 minutes
 * to run if you had the right data file...
 *
 * @throws Exception if anything goes wrong
 */
@Test
public void fourthTest() throws Exception {
    LogFixtureBuilder logBuilder = LogFixture.builder().toConsole().logger("org.apache.drill.exec.physical.impl.xsort", Level.DEBUG).logger(ExternalSortBatch.class, Level.TRACE);
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).maxParallelization(1).sessionOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2L * 1024 * 1024 * 1024).sessionOption(PlannerSettings.EXCHANGE.getOptionName(), true).sessionOption(PlannerSettings.HASHAGG.getOptionName(), false);
    try (LogFixture logs = logBuilder.build();
        ClusterFixture cluster = builder.build();
        ClientFixture client = cluster.clientFixture()) {
        setupFile();
        cluster.defineWorkspace("dfs", "data", "/tmp/drill-test", "psv");
        String sql = "select * from `dfs.data`.`example.tbl` order by columns[0]";
        QuerySummary results = client.queryBuilder().sql(sql).run();
        assertEquals(2, results.recordCount());
    }
}
Also used : QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) LogFixtureBuilder(org.apache.drill.test.LogFixture.LogFixtureBuilder) Test(org.junit.Test)

Example 2 with QuerySummary

use of org.apache.drill.test.QueryBuilder.QuerySummary 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 QuerySummary

use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by apache.

the class TestJdbcWriterWithMySQL method testBasicCTASIfNotExists.

@Test
public void testBasicCTASIfNotExists() throws Exception {
    String query = "CREATE TABLE IF NOT EXISTS mysql.`drill_mysql_test`.`test_table` (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))";
    // Create the table and insert the values
    QuerySummary insertResults = queryBuilder().sql(query).run();
    assertTrue(insertResults.succeeded());
    // Query the table to see if the insertion was successful
    String testQuery = "SELECT * FROM  mysql.`drill_mysql_test`.`test_table`";
    DirectRowSet results = queryBuilder().sql(testQuery).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().add("ID", MinorType.BIGINT, DataMode.OPTIONAL).add("NAME", MinorType.BIGINT, DataMode.OPTIONAL).buildSchema();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 2L).addRow(3L, 4L).build();
    RowSetUtilities.verify(expected, results);
    // Now drop the table
    String dropQuery = "DROP TABLE mysql.`drill_mysql_test`.`test_table`";
    QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
    assertTrue(dropResults.succeeded());
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) JdbcStorageTest(org.apache.drill.categories.JdbcStorageTest)

Example 4 with QuerySummary

use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by apache.

the class TestJdbcWriterWithMySQL method testBasicCTASWithLocalDatabase.

@Test
@Ignore("Requires local installation of MySQL")
public void testBasicCTASWithLocalDatabase() throws Exception {
    // Local databases
    String localMySql = "jdbc:mysql://localhost:3306/?useJDBCCompliantTimezoneShift=true&serverTimezone=EST5EDT";
    JdbcStorageConfig localJdbcStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", localMySql, "root", "password", false, true, null, null, 10000);
    localJdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("localMysql", localJdbcStorageConfig);
    String query = "CREATE TABLE localMysql.`drill_mysql_test`.`test_table` (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))";
    // Create the table and insert the values
    QuerySummary insertResults = queryBuilder().sql(query).run();
    assertTrue(insertResults.succeeded());
    // Query the table to see if the insertion was successful
    String testQuery = "SELECT * FROM  localMysql.`drill_mysql_test`.`test_table`";
    DirectRowSet results = queryBuilder().sql(testQuery).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().add("ID", MinorType.BIGINT, DataMode.OPTIONAL).add("NAME", MinorType.BIGINT, DataMode.OPTIONAL).buildSchema();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 2L).addRow(3L, 4L).build();
    RowSetUtilities.verify(expected, results);
    // Now drop the table
    String dropQuery = "DROP TABLE localMysql.`drill_mysql_test`.`test_table`";
    QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
    assertTrue(dropResults.succeeded());
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) Ignore(org.junit.Ignore) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) JdbcStorageTest(org.apache.drill.categories.JdbcStorageTest)

Example 5 with QuerySummary

use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by apache.

the class TestJdbcWriterWithMySQL method testBasicCTAS.

@Test
public void testBasicCTAS() throws Exception {
    String query = "CREATE TABLE mysql.`drill_mysql_test`.`test_table` (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))";
    // Create the table and insert the values
    QuerySummary insertResults = queryBuilder().sql(query).run();
    assertTrue(insertResults.succeeded());
    // Query the table to see if the insertion was successful
    String testQuery = "SELECT * FROM  mysql.`drill_mysql_test`.`test_table`";
    DirectRowSet results = queryBuilder().sql(testQuery).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().add("ID", MinorType.BIGINT, DataMode.OPTIONAL).add("NAME", MinorType.BIGINT, DataMode.OPTIONAL).buildSchema();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 2L).addRow(3L, 4L).build();
    RowSetUtilities.verify(expected, results);
    // Now drop the table
    String dropQuery = "DROP TABLE mysql.`drill_mysql_test`.`test_table`";
    QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
    assertTrue(dropResults.succeeded());
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) JdbcStorageTest(org.apache.drill.categories.JdbcStorageTest)

Aggregations

QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)49 Test (org.junit.Test)47 ClusterTest (org.apache.drill.test.ClusterTest)40 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)27 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)26 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)26 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)26 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)25 JdbcStorageTest (org.apache.drill.categories.JdbcStorageTest)21 PlannerTest (org.apache.drill.categories.PlannerTest)6 SlowTest (org.apache.drill.categories.SlowTest)6 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)4 QueryPlanFragments (org.apache.drill.exec.proto.UserProtos.QueryPlanFragments)4 Ignore (org.junit.Ignore)4 IOException (java.io.IOException)3 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)3 Path (org.apache.hadoop.fs.Path)3 File (java.io.File)2 RootAllocator (org.apache.drill.exec.memory.RootAllocator)2 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)2