Search in sources :

Example 31 with DirectRowSet

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

the class TestJdbcWriterWithMySQL method testBasicCTASWithSpacesInFieldNames.

@Test
public void testBasicCTASWithSpacesInFieldNames() throws Exception {
    String query = "CREATE TABLE mysql.`drill_mysql_test`.`test table` (`My id`, `My 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("My id", MinorType.BIGINT, DataMode.OPTIONAL).add("My 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 32 with DirectRowSet

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

the class TestJdbcPluginWithClickhouse method pushDownAggWithDecimal.

@Test
public void pushDownAggWithDecimal() throws Exception {
    String query = "SELECT sum(decimal_field * smallint_field) AS `order_total`\n" + "FROM clickhouse.`default`.person e";
    DirectRowSet results = queryBuilder().sql(query).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("order_total", TypeProtos.MinorType.VARDECIMAL, 38, 2).buildSchema();
    RowSet expected = client.rowSetBuilder(expectedSchema).addRow(123.32).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 33 with DirectRowSet

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

the class TestJdbcPluginWithMySQLIT method pushDownAggWithDecimal.

@Test
public void pushDownAggWithDecimal() throws Exception {
    String query = "SELECT sum(decimal_field * smallint_field) AS `order_total`\n" + "FROM mysql.`drill_mysql_test`.person e";
    DirectRowSet results = queryBuilder().sql(query).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("order_total", TypeProtos.MinorType.VARDECIMAL, 38, 2).buildSchema();
    RowSet expected = client.rowSetBuilder(expectedSchema).addRow(123.32).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 34 with DirectRowSet

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

the class TestJdbcWriterWithH2 method testBasicCTASWithSpacesInTableName.

@Test
public void testBasicCTASWithSpacesInTableName() throws Exception {
    String query = "CREATE TABLE h2.tmp.`drill_h2_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());
    try {
        // Query the table to see if the insertion was successful
        String testQuery = "SELECT * FROM h2.tmp.`drill_h2_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);
    } finally {
        String dropQuery = "DROP TABLE  h2.tmp.`drill_h2_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)

Example 35 with DirectRowSet

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

the class TestJdbcWriterWithH2 method testCTASWithDuplicateTable.

@Test
public void testCTASWithDuplicateTable() 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();
    assertTrue(insertResults.succeeded());
    try {
        // Run the query again, should fail.
        try {
            queryBuilder().sql(query).run();
            fail();
        } catch (UserRemoteException e) {
            assertTrue(e.getMessage().contains("VALIDATION ERROR"));
        }
        // Try again with IF NOT EXISTS, Should not do anything, but not throw an exception
        query = String.format("CREATE TABLE IF NOT EXISTS %s (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))", TEST_TABLE);
        DirectRowSet results = queryBuilder().sql(query).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("ok", MinorType.BIT).add("summary", MinorType.VARCHAR, DataMode.OPTIONAL).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(false, "A table or view with given name [test_table] already exists in schema [h2.tmp.drill_h2_test]").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) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) 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)

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