Search in sources :

Example 36 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class TestJdbcWriterWithH2 method testCTASFromFileWithNulls.

@Test
public void testCTASFromFileWithNulls() throws Exception {
    String sql = String.format("CREATE TABLE %s AS SELECT int_field, float_field, varchar_field, boolean_field FROM cp.`json/dataTypes.json`", TEST_TABLE);
    QuerySummary insertResults = queryBuilder().sql(sql).run();
    assertTrue(insertResults.succeeded());
    try {
        sql = String.format("SELECT * FROM %s", TEST_TABLE);
        DirectRowSet results = queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().addNullable("int_field", MinorType.BIGINT, 38).addNullable("float_field", MinorType.FLOAT8, 38).addNullable("varchar_field", MinorType.VARCHAR, 38).addNullable("boolean_field", MinorType.BIT, 1).build();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 1.0, "foo1", true).addRow(null, null, null, null).addRow(2L, 2.0, "foo2", false).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 37 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class TestJdbcWriterWithH2 method testBasicCTASIfNotExists.

@Test
public void testBasicCTASIfNotExists() throws Exception {
    String query = String.format("CREATE TABLE IF NOT EXISTS %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();
    assertTrue(insertResults.succeeded());
    try {
        // 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 38 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class TestJdbcPluginWithPostgres method testExpressionsWithoutAlias.

@Test
public void testExpressionsWithoutAlias() throws Exception {
    String sql = "select count(*), 1+1+2+3+5+8+13+21+34, (1+sqrt(5))/2\n" + "from pg.`public`.person";
    DirectRowSet results = queryBuilder().sql(sql).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("EXPR$0", MinorType.BIGINT, 19).addNullable("EXPR$1", MinorType.INT, 10).addNullable("EXPR$2", MinorType.FLOAT8, 17, 17).build();
    RowSet expected = client.rowSetBuilder(expectedSchema).addRow(4L, 88L, 1.618033988749895).build();
    RowSetUtilities.verify(expected, results);
}
Also used : 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 39 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class IcebergQueriesTest method testSelectFromSnapshotIdAndToSnapshotId.

@Test
public void testSelectFromSnapshotIdAndToSnapshotId() throws Exception {
    String snapshotQuery = "select snapshot_id from dfs.tmp.`testAllTypes#snapshots` order by committed_at";
    String query = "select * from table(dfs.tmp.testAllTypes(type => 'iceberg', fromSnapshotId => %s, toSnapshotId => %s))";
    DirectRowSet rowSet = queryBuilder().sql(snapshotQuery).rowSet();
    try {
        RowSetReader reader = rowSet.reader();
        assertTrue(reader.next());
        Long fromSnapshotId = (Long) reader.column(0).reader().getObject();
        assertTrue(reader.next());
        Long toSnapshotId = (Long) reader.column(0).reader().getObject();
        String plan = queryBuilder().sql(query, fromSnapshotId, toSnapshotId).explainJson();
        long count = queryBuilder().physical(plan).run().recordCount();
        assertEquals(1, count);
    } finally {
        rowSet.clear();
    }
}
Also used : DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 40 with DirectRowSet

use of org.apache.drill.exec.physical.rowSet.DirectRowSet in project drill by apache.

the class TestPagination method testAggregateQuery.

@Test
public void testAggregateQuery() throws Exception {
    // Note that since the data arrives in multiple batches,
    // in order to access the contents, we have to receive the batches and parse them.
    // This is the case even with aggregate queries.
    String sql = "SELECT ZONE, COUNT(*) AS row_count FROM `local`.`xml_paginator` GROUP BY ZONE";
    try (MockWebServer server = startServer()) {
        server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_XML_PAGE1));
        server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_XML_PAGE2));
        server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_XML_PAGE3));
        QueryRowSetIterator iterator = client.queryBuilder().sql(sql).rowSetIterator();
        TupleMetadata expectedSchema = new SchemaBuilder().addNullable("ZONE", MinorType.VARCHAR).add("row_count", MinorType.BIGINT).build();
        RowSet expectedFirstRow = new RowSetBuilder(client.allocator(), expectedSchema).addRow("4", 5).build();
        RowSet expectedSecondRow = new RowSetBuilder(client.allocator(), expectedSchema).addRow("3", 3).build();
        int count = 0;
        while (iterator.hasNext()) {
            DirectRowSet results = iterator.next();
            if (results.rowCount() > 0) {
                if (count == 0) {
                    RowSetUtilities.verify(expectedFirstRow, results);
                } else if (count == 1) {
                    RowSetUtilities.verify(expectedSecondRow, results);
                }
                count++;
            }
        }
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) QueryRowSetIterator(org.apache.drill.test.QueryRowSetIterator) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MockWebServer(okhttp3.mockwebserver.MockWebServer) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Aggregations

DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)42 Test (org.junit.Test)40 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)39 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)39 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)39 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)35 ClusterTest (org.apache.drill.test.ClusterTest)33 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)25 JdbcStorageTest (org.apache.drill.categories.JdbcStorageTest)21 RowSetReader (org.apache.drill.exec.physical.rowSet.RowSetReader)8 EvfTest (org.apache.drill.categories.EvfTest)7 MockResponse (okhttp3.mockwebserver.MockResponse)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)3 IOException (java.io.IOException)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 PersistentTokenTable (org.apache.drill.exec.oauth.PersistentTokenTable)2 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)2 BigDecimal (java.math.BigDecimal)1