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