Search in sources :

Example 1 with Document

use of org.ojai.Document in project drill by apache.

the class TestSimpleJson method testPushdownStringEqual.

@Test
public void testPushdownStringEqual() throws Exception {
    setColumnWidths(new int[] { 25, 40, 40, 40 });
    final String sql = "SELECT\n" + "  _id, name, business.hours.Monday.`open`, categories[1], years[2], full_address\n" + "FROM\n" + "  hbase.`business` business\n" + "WHERE\n" + " name = 'Sprint'";
    final Document queryResult = MapRDB.newDocument();
    SingleRowListener listener = new SingleRowListener() {

        @Override
        protected void rowArrived(QueryDataBatch result) {
            try {
                final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
                loader.load(result.getHeader().getDef(), result.getData());
                StringBuilder sb = new StringBuilder();
                VectorUtil.appendVectorAccessibleContent(loader, sb, "|", false);
                loader.clear();
                queryResult.set("result", sb.toString());
            } catch (SchemaChangeException e) {
                queryResult.set("error", "true");
            }
        }
    };
    testWithListener(QueryType.SQL, sql, listener);
    listener.waitForCompletion();
    assertNull(queryResult.getString("error"));
    assertNotNull(queryResult.getString("result"));
    String[] fields = queryResult.getString("result").split("\\|");
    assertEquals("1970-01-01T11:00:00.000", fields[2]);
    assertEquals("Mobile Phones", fields[3]);
    assertEquals("2016.0", fields[4]);
    final String[] expectedPlan = { "condition=\\(name = \"Sprint\"\\)" };
    final String[] excludedPlan = {};
    PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
Also used : SingleRowListener(org.apache.drill.SingleRowListener) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) Document(org.ojai.Document) Test(org.junit.Test) ClusterTest(com.mapr.tests.annotations.ClusterTest)

Aggregations

ClusterTest (com.mapr.tests.annotations.ClusterTest)1 SingleRowListener (org.apache.drill.SingleRowListener)1 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)1 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)1 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)1 Test (org.junit.Test)1 Document (org.ojai.Document)1