Search in sources :

Example 31 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 32 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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();
        }
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 33 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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();
        }
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 34 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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();
        }
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 35 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet in project drill by apache.

the class TestSimpleTopN method sortOneKeyAscending.

@Test
public void sortOneKeyAscending() throws Throwable {
    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("/topN/one_key_sort.json"), Charsets.UTF_8));
        int count = 0;
        for (QueryDataBatch b : results) {
            if (b.getHeader().getRowCount() != 0) {
                count += b.getHeader().getRowCount();
            }
        }
        assertEquals(100, count);
        long previousBigInt = Long.MIN_VALUE;
        int recordCount = 0;
        int batchCount = 0;
        for (QueryDataBatch b : results) {
            if (b.getHeader().getRowCount() == 0) {
                continue;
            }
            batchCount++;
            RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator());
            loader.load(b.getHeader().getDef(), b.getData());
            BigIntVector c1 = (BigIntVector) loader.getValueAccessorById(BigIntVector.class, loader.getValueVectorId(new SchemaPath("blue", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
            BigIntVector.Accessor a1 = c1.getAccessor();
            for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
                recordCount++;
                assertTrue(previousBigInt <= a1.get(i));
                previousBigInt = a1.get(i);
            }
            loader.clear();
            b.release();
        }
        System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount));
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) SchemaPath(org.apache.drill.common.expression.SchemaPath) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) BigIntVector(org.apache.drill.exec.vector.BigIntVector) Test(org.junit.Test)

Aggregations

RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)63 Drillbit (org.apache.drill.exec.server.Drillbit)61 Test (org.junit.Test)56 DrillClient (org.apache.drill.exec.client.DrillClient)55 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)55 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)36 ValueVector (org.apache.drill.exec.vector.ValueVector)30 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)13 DrillConfig (org.apache.drill.common.config.DrillConfig)8 ExecTest (org.apache.drill.exec.ExecTest)8 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)7 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)5 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)3 QueryContext (org.apache.drill.exec.ops.QueryContext)3 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)3 ZookeeperHelper (org.apache.drill.exec.ZookeeperHelper)2 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)2 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)2