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());
}
}
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());
}
}
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);
}
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();
}
}
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++;
}
}
}
}
Aggregations