Search in sources :

Example 21 with QuerySummary

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

the class TestJdbcWriterWithH2 method testBasicCTAS.

@Test
public void testBasicCTAS() throws Exception {
    String query = String.format("CREATE TABLE %s (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))", TEST_TABLE);
    // Create the table and insert the values
    QuerySummary insertResults = queryBuilder().sql(query).run();
    try {
        assertTrue(insertResults.succeeded());
        // Query the table to see if the insertion was successful
        String testQuery = String.format("SELECT * FROM %s", 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);
    } finally {
        QuerySummary dropResults = queryBuilder().sql(DROP_TEST_TABLE).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)

Example 22 with QuerySummary

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

the class TestLogReaderIssue method testIssue7853.

@Test
public void testIssue7853() throws Exception {
    thrownException.expect(UserRemoteException.class);
    thrownException.expectMessage("is not valid for type TIMESTAMP");
    String sql = "SELECT type, `time` FROM `dfs.data`.`root/issue7853.log2`";
    QuerySummary result = client.queryBuilder().sql(sql).run();
    assertEquals(2, result.recordCount());
}
Also used : QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) BaseCsvTest(org.apache.drill.exec.store.easy.text.compliant.BaseCsvTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 23 with QuerySummary

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

the class DrillSeparatePlanningTest method getResultsHelper.

private int getResultsHelper(final QueryPlanFragments planFragments) throws Exception {
    int totalRows = 0;
    for (PlanFragment fragment : planFragments.getFragmentsList()) {
        DrillbitEndpoint assignedNode = fragment.getAssignment();
        ClientFixture fragmentClient = cluster.client(assignedNode.getAddress(), assignedNode.getUserPort());
        RowSet rowSet = fragmentClient.queryBuilder().sql("select hostname, user_port from sys.drillbits where `current`=true").rowSet();
        assertEquals(1, rowSet.rowCount());
        RowSetReader reader = rowSet.reader();
        assertTrue(reader.next());
        String host = reader.scalar("hostname").getString();
        int port = reader.scalar("user_port").getInt();
        rowSet.clear();
        assertEquals(assignedNode.getAddress(), host);
        assertEquals(assignedNode.getUserPort(), port);
        List<PlanFragment> fragmentList = Lists.newArrayList();
        fragmentList.add(fragment);
        QuerySummary summary = fragmentClient.queryBuilder().plan(fragmentList).run();
        totalRows += summary.recordCount();
        fragmentClient.close();
    }
    return totalRows;
}
Also used : DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) ClientFixture(org.apache.drill.test.ClientFixture) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment)

Example 24 with QuerySummary

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

the class DrillSeparatePlanningTest method testPlanningNoSplit.

@Test(timeout = 60_000)
public void testPlanningNoSplit() throws Exception {
    final String query = "SELECT dir0, sum(o_totalprice) FROM dfs.`multilevel/json` group by dir0 order by dir0";
    client.alterSession("planner.slice_target", 1);
    try {
        final QueryPlanFragments planFragments = client.planQuery(query);
        assertNotNull(planFragments);
        assertTrue((planFragments.getFragmentsCount() > 1));
        PlanFragment rootFragment = planFragments.getFragments(0);
        assertFalse(rootFragment.getLeafFragment());
        QuerySummary summary = client.queryBuilder().plan(planFragments.getFragmentsList()).run();
        assertEquals(3, summary.recordCount());
    } finally {
        client.resetSession("planner.slice_target");
    }
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 25 with QuerySummary

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

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)

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