use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by axbaretto.
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());
}
}
use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by axbaretto.
the class ExampleTest method secondTest.
/**
* <p>
* Example that uses the fixture builder to build a cluster fixture. Lets
* you set configuration (boot-time) options, session options, system options
* and more.
* </p>
* <p>
* You can write test files to the {@link BaseDirTestWatcher#getRootDir()} and query them in the test.
* </p>
* <p>
* Also shows how to display the plan JSON and just run a query silently,
* getting just the row count, batch count and run time.
* </p>
* @throws Exception if anything goes wrong
*/
@Test
public void secondTest() throws Exception {
try (RootAllocator allocator = new RootAllocator(100_000_000)) {
final File tableFile = dirTestWatcher.getRootDir().toPath().resolve("employee.json").toFile();
final BatchSchema schema = new SchemaBuilder().add("id", Types.required(TypeProtos.MinorType.VARCHAR)).add("name", Types.required(TypeProtos.MinorType.VARCHAR)).build();
final RowSet rowSet = new RowSetBuilder(allocator, schema).addRow("1", "kiwi").addRow("2", "watermelon").build();
new JsonFileBuilder(rowSet).build(tableFile);
rowSet.clear();
ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).configProperty(ExecConstants.SLICE_TARGET, 10);
try (ClusterFixture cluster = builder.build();
ClientFixture client = cluster.clientFixture()) {
String sql = "SELECT * FROM `dfs`.`test/employee.json`";
System.out.println(client.queryBuilder().sql(sql).explainJson());
QuerySummary results = client.queryBuilder().sql(sql).run();
System.out.println(String.format("Read %d rows", results.recordCount()));
// Usually we want to test something. Here, just test that we got
// the 2 records.
assertEquals(2, results.recordCount());
}
}
}
use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by apache.
the class TestJdbcWriterWithMySQL method testBasicCTASIfNotExists.
@Test
public void testBasicCTASIfNotExists() throws Exception {
String query = "CREATE TABLE IF NOT EXISTS mysql.`drill_mysql_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());
// 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("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 mysql.`drill_mysql_test`.`test_table`";
QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
assertTrue(dropResults.succeeded());
}
use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by apache.
the class TestJdbcWriterWithMySQL method testBasicCTASWithLocalDatabase.
@Test
@Ignore("Requires local installation of MySQL")
public void testBasicCTASWithLocalDatabase() throws Exception {
// Local databases
String localMySql = "jdbc:mysql://localhost:3306/?useJDBCCompliantTimezoneShift=true&serverTimezone=EST5EDT";
JdbcStorageConfig localJdbcStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", localMySql, "root", "password", false, true, null, null, 10000);
localJdbcStorageConfig.setEnabled(true);
cluster.defineStoragePlugin("localMysql", localJdbcStorageConfig);
String query = "CREATE TABLE localMysql.`drill_mysql_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());
// Query the table to see if the insertion was successful
String testQuery = "SELECT * FROM localMysql.`drill_mysql_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);
// Now drop the table
String dropQuery = "DROP TABLE localMysql.`drill_mysql_test`.`test_table`";
QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
assertTrue(dropResults.succeeded());
}
use of org.apache.drill.test.QueryBuilder.QuerySummary in project drill by apache.
the class TestJdbcWriterWithMySQL method testBasicCTAS.
@Test
public void testBasicCTAS() throws Exception {
String query = "CREATE TABLE mysql.`drill_mysql_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());
// 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("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 mysql.`drill_mysql_test`.`test_table`";
QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
assertTrue(dropResults.succeeded());
}
Aggregations