Search in sources :

Example 11 with DirectRowSet

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

the class TestJdbcWriterWithPostgres method testCTASFromFileWithNulls.

@Test
public void testCTASFromFileWithNulls() throws Exception {
    String sql = "CREATE TABLE pg.public.`t1` AS SELECT int_field, float_field, varchar_field, boolean_field FROM cp.`json/dataTypes.json`";
    QuerySummary insertResults = queryBuilder().sql(sql).run();
    assertTrue(insertResults.succeeded());
    sql = "SELECT * FROM pg.public.`t1`";
    DirectRowSet results = queryBuilder().sql(sql).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("int_field", MinorType.BIGINT, 19).addNullable("float_field", MinorType.FLOAT8, 22).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);
    String dropQuery = "DROP TABLE pg.`public`.`t1`";
    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 12 with DirectRowSet

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

the class TestJdbcWriterWithPostgres method testCTASFromFileWithUglyData.

@Test
public void testCTASFromFileWithUglyData() throws Exception {
    String sql = "CREATE TABLE pg.public.`t2` AS SELECT ugly1, ugly2 FROM cp.`json/uglyData.json`";
    QuerySummary insertResults = queryBuilder().sql(sql).run();
    assertTrue(insertResults.succeeded());
    sql = "SELECT * FROM  pg.public.`t2`";
    DirectRowSet results = queryBuilder().sql(sql).rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("ugly1", MinorType.VARCHAR, 38).addNullable("ugly2", MinorType.VARCHAR, 38).build();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("O'Malley", "Abraham Lincoln's best speech started with: \"Four score and seven years ago...").build();
    RowSetUtilities.verify(expected, results);
    String dropQuery = "DROP TABLE  pg.public.`t2`";
    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 13 with DirectRowSet

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

the class TestJdbcWriterWithPostgres method testBasicCTASWithSpacesInTableName.

@Test
public void testBasicCTASWithSpacesInTableName() throws Exception {
    String query = "CREATE TABLE pg.public.`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 pg.public.`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 pg.public.`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 14 with DirectRowSet

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

the class TestJdbcWriterWithH2 method testCTASFromFileWithUglyData.

@Test
public void testCTASFromFileWithUglyData() throws Exception {
    String sql = String.format("CREATE TABLE %s AS SELECT ugly1, ugly2 FROM cp.`json/uglyData.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("ugly1", MinorType.VARCHAR, 38).addNullable("ugly2", MinorType.VARCHAR, 38).build();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("O'Malley", "Abraham Lincoln's best speech started with: \"Four score and seven years ago...").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 15 with DirectRowSet

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

the class TestJdbcWriterWithH2 method testBasicCTASWithSpacesInFieldNames.

@Test
public void testBasicCTASWithSpacesInFieldNames() throws Exception {
    String query = String.format("CREATE TABLE %s (`My id`, `My 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("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);
    } 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)

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