use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestOptiqPlans method testLogicalJsonScan.
@Test
public void testLogicalJsonScan() 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_json_scan.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 TestSimpleFragmentRun method runJSONScanPopFragment.
@Test
public void runJSONScanPopFragment() 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 List<QueryDataBatch> results = client.runQuery(QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile("/physical_json_scan_test1.json"), Charsets.UTF_8).replace("#{TEST_FILE}", FileUtils.getResourceAsFile("/scan_json_test_1.json").toURI().toString()));
// look at records
final RecordBatchLoader batchLoader = new RecordBatchLoader(RootAllocatorFactory.newRoot(CONFIG));
int recordCount = 0;
for (int i = 0; i < results.size(); ++i) {
final QueryDataBatch batch = results.get(i);
if (i == 0) {
assertTrue(batch.hasData());
} else {
assertFalse(batch.hasData());
batch.release();
continue;
}
assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
boolean firstColumn = true;
// print headers.
System.out.println("\n\n========NEW SCHEMA=========\n\n");
for (final VectorWrapper<?> v : batchLoader) {
if (firstColumn) {
firstColumn = false;
} else {
System.out.print("\t");
}
System.out.print(v.getField().getPath());
System.out.print("[");
System.out.print(v.getField().getType().getMinorType());
System.out.print("]");
}
System.out.println();
for (int r = 0; r < batchLoader.getRecordCount(); r++) {
boolean first = true;
recordCount++;
for (final VectorWrapper<?> v : batchLoader) {
if (first) {
first = false;
} else {
System.out.print("\t");
}
final ValueVector.Accessor accessor = v.getValueVector().getAccessor();
System.out.print(accessor.getObject(r));
}
if (!first) {
System.out.println();
}
}
batchLoader.clear();
batch.release();
}
assertEquals(2, recordCount);
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestDateTypes method testDate.
// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestDateTypes.class);
@Test
public void testDate() 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(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile("/record/vector/test_date.json"), Charsets.UTF_8).replace("#{TEST_FILE}", "/test_simple_date.json"));
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();
assertEquals((accessor.getObject(0).toString()), ("1970-01-02"));
assertEquals((accessor.getObject(1).toString()), ("2008-12-28"));
assertEquals((accessor.getObject(2).toString()), ("2000-02-27"));
}
batchLoader.clear();
for (QueryDataBatch b : results) {
b.release();
}
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestDateTypes method testSortDate.
@Test
public void testSortDate() 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(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile("/record/vector/test_sort_date.json"), Charsets.UTF_8).replace("#{TEST_FILE}", "/test_simple_date.json"));
RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
QueryDataBatch batch = results.get(1);
assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
for (VectorWrapper<?> v : batchLoader) {
ValueVector.Accessor accessor = v.getValueVector().getAccessor();
assertEquals((accessor.getObject(0).toString()), new String("1970-01-02"));
assertEquals((accessor.getObject(1).toString()), new String("2000-02-27"));
assertEquals((accessor.getObject(2).toString()), new String("2008-12-28"));
}
batchLoader.clear();
for (QueryDataBatch b : results) {
b.release();
}
}
}
use of org.apache.drill.exec.client.DrillClient in project drill by apache.
the class TestMultiInputAdd method testMultiInputAdd.
@Test
public void testMultiInputAdd(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) 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.toString(FileUtils.getResourceAsFile("/functions/multi_input_add_test.json"), Charsets.UTF_8));
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();
}
}
}
Aggregations