Search in sources :

Example 61 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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";
        final List<QueryDataBatch> results = client.runQuery(QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile(path), Charsets.UTF_8).read());
        // look at records
        final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
        final StringBuilder sb = new StringBuilder();
        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) {
                sb.append("\n\n========NEW SCHEMA=========\n\n");
                for (final VectorWrapper<?> value : batchLoader) {
                    if (firstColumn) {
                        firstColumn = false;
                    } else {
                        sb.append("\t");
                    }
                    sb.append(value.getField().getName());
                    sb.append("[");
                    sb.append(value.getField().getType().getMinorType());
                    sb.append("]");
                }
                sb.append('\n');
            }
            for (int i = 0; i < batchLoader.getRecordCount(); i++) {
                boolean first = true;
                recordCount++;
                for (final VectorWrapper<?> value : batchLoader) {
                    if (first) {
                        first = false;
                    } else {
                        sb.append("\t");
                    }
                    sb.append(value.getValueVector().getAccessor().getObject(i));
                }
                if (!first) {
                    sb.append('\n');
                }
            }
            batchLoader.clear();
            batch.release();
        }
        logger.debug(sb.toString());
        logger.debug("Received results {}", results);
        assertEquals(recordCount, 200);
    }
}
Also used : 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 62 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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.asCharSource(DrillFileUtils.getResourceAsFile("/sender/union_exchange.json"), Charsets.UTF_8).read());
        int count = 0;
        for (QueryDataBatch b : results) {
            if (b.getHeader().getRowCount() != 0) {
                count += b.getHeader().getRowCount();
            }
            b.release();
        }
        assertEquals(150, count);
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 63 with RemoteServiceSet

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

the class TestDateTypes method testLiterals.

@Test
public void testLiterals() 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.asCharSource(DrillFileUtils.getResourceAsFile("/record/vector/test_all_date_literals.json"), Charsets.UTF_8).read().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()));
        String[] result = { "2008-02-27", "2008-02-27 01:02:03.000", "10:11:13.999", "2 years 2 months 3 days 0:1:3.89" };
        int idx = 0;
        for (VectorWrapper<?> v : batchLoader) {
            ValueVector.Accessor accessor = v.getValueVector().getAccessor();
            assertEquals((accessor.getObject(0).toString()), (result[idx++]));
        }
        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) SlowTest(org.apache.drill.categories.SlowTest) VectorTest(org.apache.drill.categories.VectorTest)

Example 64 with RemoteServiceSet

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

the class TestDateTypes method testDateAdd.

@Test
public void testDateAdd() 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.asCharSource(DrillFileUtils.getResourceAsFile("/record/vector/test_date_add.json"), Charsets.UTF_8).read().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()), ("2008-03-27 00:00:00.000"));
        }
        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) SlowTest(org.apache.drill.categories.SlowTest) VectorTest(org.apache.drill.categories.VectorTest)

Example 65 with RemoteServiceSet

use of org.apache.drill.exec.server.RemoteServiceSet 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();
        }
    }
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) ZKClusterCoordinator(org.apache.drill.exec.coord.zk.ZKClusterCoordinator)

Aggregations

RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)136 Drillbit (org.apache.drill.exec.server.Drillbit)132 Test (org.junit.Test)122 DrillClient (org.apache.drill.exec.client.DrillClient)119 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)119 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)79 SlowTest (org.apache.drill.categories.SlowTest)65 ValueVector (org.apache.drill.exec.vector.ValueVector)64 OperatorTest (org.apache.drill.categories.OperatorTest)47 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)28 DrillConfig (org.apache.drill.common.config.DrillConfig)17 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)16 ExecTest (org.apache.drill.exec.ExecTest)13 VectorTest (org.apache.drill.categories.VectorTest)12 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)11 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)10 QueryContext (org.apache.drill.exec.ops.QueryContext)8 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)7 ZookeeperHelper (org.apache.drill.exec.ZookeeperHelper)6 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)6