use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestOptiqPlans method testOrderVarbinary.
@Test
public void testOrderVarbinary() throws Exception {
final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (final Drillbit bit1 = new Drillbit(config, serviceSet);
final DrillClient client = new DrillClient(config, serviceSet.getCoordinator())) {
bit1.run();
client.connect();
final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Resources.toString(Resources.getResource("physical_order_varbinary.json"), Charsets.UTF_8));
final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator());
for (final QueryDataBatch b : results) {
System.out.println(String.format("Got %d results", b.getHeader().getRowCount()));
loader.load(b.getHeader().getDef(), b.getData());
for (final VectorWrapper vw : loader) {
System.out.println(vw.getValueVector().getField().getPath());
final ValueVector vv = vw.getValueVector();
for (int i = 0; i < vv.getAccessor().getValueCount(); i++) {
final Object o = vv.getAccessor().getObject(i);
if (vv instanceof VarBinaryVector) {
final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor();
final VarBinaryHolder vbh = new VarBinaryHolder();
x.get(i, vbh);
System.out.printf("%d..%d", vbh.start, vbh.end);
System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]");
} else {
System.out.println(vv.getAccessor().getObject(i));
}
}
}
loader.clear();
b.release();
}
client.close();
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestOptiqPlans method testFilterString.
@Test
public void testFilterString() throws Exception {
final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (final Drillbit bit1 = new Drillbit(config, serviceSet);
final DrillClient client = new DrillClient(config, serviceSet.getCoordinator())) {
bit1.run();
client.connect();
final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.LOGICAL, Resources.toString(Resources.getResource("logical_string_filter.json"), Charsets.UTF_8));
final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator());
for (final QueryDataBatch b : results) {
System.out.println(String.format("Got %d results", b.getHeader().getRowCount()));
loader.load(b.getHeader().getDef(), b.getData());
for (final VectorWrapper<?> vw : loader) {
System.out.println(vw.getValueVector().getField().getPath());
final ValueVector vv = vw.getValueVector();
for (int i = 0; i < vv.getAccessor().getValueCount(); i++) {
final Object o = vv.getAccessor().getObject(i);
if (vv instanceof VarBinaryVector) {
final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor();
final VarBinaryHolder vbh = new VarBinaryHolder();
x.get(i, vbh);
System.out.printf("%d..%d", vbh.start, vbh.end);
System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]");
} else {
System.out.println(vv.getAccessor().getObject(i));
}
}
}
loader.clear();
b.release();
}
client.close();
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestUnionExchange method twoBitTwoExchangeTwoEntryRun.
@Test
public void twoBitTwoExchangeTwoEntryRun() throws Exception {
RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
bit1.run();
bit2.run();
client.connect();
List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile("/sender/union_exchange.json"), Charsets.UTF_8));
int count = 0;
for (QueryDataBatch b : results) {
if (b.getHeader().getRowCount() != 0) {
count += b.getHeader().getRowCount();
}
b.release();
}
assertEquals(150, count);
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestReverseImplicitCast method twoWayCast.
@Test
public void twoWayCast(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
// Function checks for casting from Float, Double to Decimal data types
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.toString(FileUtils.getResourceAsFile("/functions/cast/two_way_implicit_cast.json"), Charsets.UTF_8));
RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
QueryDataBatch batch = results.get(0);
assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
ValueVector.Accessor intAccessor1 = itr.next().getValueVector().getAccessor();
ValueVector.Accessor varcharAccessor1 = itr.next().getValueVector().getAccessor();
for (int i = 0; i < intAccessor1.getValueCount(); i++) {
System.out.println(intAccessor1.getObject(i));
assertEquals(intAccessor1.getObject(i), 10);
System.out.println(varcharAccessor1.getObject(i));
assertEquals(varcharAccessor1.getObject(i).toString(), "101");
}
batchLoader.clear();
for (QueryDataBatch result : results) {
result.release();
}
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestSimpleFragmentRun method runNoExchangeFragment.
@Test
public void runNoExchangeFragment() throws Exception {
try (final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
final Drillbit bit = new Drillbit(CONFIG, serviceSet);
final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
// run query.
bit.run();
client.connect();
final String path = "/physical_test2.json";
// String path = "/filter/test1.json";
final List<QueryDataBatch> results = client.runQuery(QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile(path), Charsets.UTF_8));
// look at records
final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
int recordCount = 0;
for (final QueryDataBatch batch : results) {
final boolean schemaChanged = batchLoader.load(batch.getHeader().getDef(), batch.getData());
boolean firstColumn = true;
// print headers.
if (schemaChanged) {
System.out.println("\n\n========NEW SCHEMA=========\n\n");
for (final VectorWrapper<?> value : batchLoader) {
if (firstColumn) {
firstColumn = false;
} else {
System.out.print("\t");
}
System.out.print(value.getField().getPath());
System.out.print("[");
System.out.print(value.getField().getType().getMinorType());
System.out.print("]");
}
System.out.println();
}
for (int i = 0; i < batchLoader.getRecordCount(); i++) {
boolean first = true;
recordCount++;
for (final VectorWrapper<?> value : batchLoader) {
if (first) {
first = false;
} else {
System.out.print("\t");
}
System.out.print(value.getValueVector().getAccessor().getObject(i));
}
if (!first) {
System.out.println();
}
}
batchLoader.clear();
batch.release();
}
logger.debug("Received results {}", results);
assertEquals(recordCount, 200);
}
}
Aggregations