use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class QuerySubmitter method submitQuery.
public int submitQuery(String planLocation, String queryString, String type, String zkQuorum, boolean local, int bits, String format, int width) throws Exception {
DrillConfig config = DrillConfig.create();
DrillClient client = null;
Preconditions.checkArgument(!(planLocation == null && queryString == null), "Must provide either query file or query string");
Preconditions.checkArgument(!(planLocation != null && queryString != null), "Must provide either query file or query string, not both");
RemoteServiceSet serviceSet = null;
Drillbit[] drillbits = null;
try {
if (local) {
serviceSet = RemoteServiceSet.getLocalServiceSet();
drillbits = new Drillbit[bits];
for (int i = 0; i < bits; i++) {
drillbits[i] = new Drillbit(config, serviceSet);
drillbits[i].run();
}
client = new DrillClient(config, serviceSet.getCoordinator());
} else {
ZKClusterCoordinator clusterCoordinator = new ZKClusterCoordinator(config, zkQuorum);
clusterCoordinator.start(10000);
client = new DrillClient(config, clusterCoordinator);
}
client.connect();
String plan;
if (queryString == null) {
plan = Charsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get(planLocation)))).toString();
} else {
plan = queryString;
}
return submitQuery(client, plan, type, format, width);
} catch (Throwable th) {
System.err.println("Query Failed due to : " + th.getMessage());
return -1;
} finally {
if (client != null) {
client.close();
}
if (local) {
for (Drillbit b : drillbits) {
b.close();
}
serviceSet.close();
}
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestCastFunctions method testCastFromNullablCol.
@Test
public void testCastFromNullablCol() throws Throwable {
final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (final Drillbit bit = new Drillbit(CONFIG, serviceSet);
final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
bit.run();
client.connect();
final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/cast/testCastVarCharNull.json"), Charsets.UTF_8).read().replace("#{TEST_FILE}", "/jsoninput/input1.json"));
final QueryDataBatch batch = results.get(0);
final RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
batchLoader.load(batch.getHeader().getDef(), batch.getData());
final Object[][] result = getRunResult(batchLoader);
final Object[][] expected = new Object[2][2];
expected[0][0] = new String("2001");
expected[0][1] = new String("1.2");
expected[1][0] = new String("-2002");
expected[1][1] = new String("-1.2");
assertEquals(result.length, expected.length);
assertEquals(result[0].length, expected[0].length);
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < result[0].length; j++) {
assertEquals(String.format("Column %s at row %s have wrong result", j, i), result[i][j].toString(), expected[i][j]);
}
}
batchLoader.clear();
for (final QueryDataBatch b : results) {
b.release();
}
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestMultiInputAdd method testMultiInputAdd.
@Test
public void testMultiInputAdd() throws Throwable {
try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
Drillbit bit = new Drillbit(CONFIG, serviceSet);
DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
// run query.
bit.run();
client.connect();
List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/multi_input_add_test.json"), Charsets.UTF_8).read());
RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
QueryDataBatch batch = results.get(0);
assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
for (VectorWrapper<?> v : batchLoader) {
ValueVector.Accessor accessor = v.getValueVector().getAccessor();
assertTrue((accessor.getObject(0)).equals(10));
}
batchLoader.clear();
for (QueryDataBatch b : results) {
b.release();
}
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestNewAggregateFunctions method runTest.
public void runTest(String physicalPlan, String inputDataFile, Object[] expected) throws Exception {
try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
Drillbit bit = new Drillbit(CONFIG, serviceSet);
DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
// run query.
bit.run();
client.connect();
List<QueryDataBatch> results = client.runQuery(QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile(physicalPlan), Charsets.UTF_8).read().replace("#{TEST_FILE}", inputDataFile));
RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
QueryDataBatch batch = results.get(1);
assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
int i = 0;
for (VectorWrapper<?> v : batchLoader) {
ValueVector.Accessor accessor = v.getValueVector().getAccessor();
assertEquals(expected[i++], (accessor.getObject(0)));
}
batchLoader.clear();
for (QueryDataBatch b : results) {
b.release();
}
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class ExpressionInterpreterTest method doTest.
protected void doTest(String expressionStr, String[] colNames, TypeProtos.MajorType[] colTypes, String[] expectFirstTwoValues, BitControl.PlanFragment planFragment) throws Exception {
final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
final Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
bit1.run();
// Create a mock scan batch as input for evaluation.
assertEquals(colNames.length, colTypes.length);
final MockTableDef.MockColumn[] columns = new MockTableDef.MockColumn[colNames.length];
for (int i = 0; i < colNames.length; i++) {
columns[i] = new MockTableDef.MockColumn(colNames[i], colTypes[i].getMinorType(), colTypes[i].getMode(), 0, 0, 0, null, null, null);
}
final MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(10, false, 0, 1, columns);
final MockSubScanPOP scanPOP = new MockSubScanPOP("testTable", false, java.util.Collections.singletonList(entry));
final CloseableRecordBatch batch = createMockScanBatch(bit1, scanPOP, planFragment);
batch.next();
final ValueVector vv = evalExprWithInterpreter(expressionStr, batch, bit1);
// Verify the first 2 values in the output of evaluation.
assertEquals(2, expectFirstTwoValues.length);
assertEquals(expectFirstTwoValues[0], getValueFromVector(vv, 0));
assertEquals(expectFirstTwoValues[1], getValueFromVector(vv, 1));
showValueVectorContent(vv);
vv.clear();
batch.close();
batch.getContext().close();
bit1.close();
}
Aggregations