Search in sources :

Example 41 with DrillClient

use of org.apache.drill.exec.client.DrillClient in project drill by apache.

the class TestDecimal method testSimpleDecimalArithmetic.

@Test
public void testSimpleDecimalArithmetic() throws Exception {
    // Function checks arithmetic operations on Decimal18
    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("/decimal/simple_decimal_arithmetic.json"), Charsets.UTF_8).replace("#{TEST_FILE}", "/input_simple_decimal.json"));
        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
        QueryDataBatch batch = results.get(0);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
        String[] addOutput = { "123456888.0", "22.2", "0.2", "-0.2", "-987654444.2", "-3.0" };
        String[] subtractOutput = { "123456690.0", "0.0", "0.0", "0.0", "-987654198.0", "-1.0" };
        String[] multiplyOutput = { "12222222111.00", "123.21", "0.01", "0.01", "121580246927.41", "2.00" };
        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
        // Check the output of add
        ValueVector.Accessor addAccessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor subAccessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor mulAccessor = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < addAccessor.getValueCount(); i++) {
            assertEquals(addAccessor.getObject(i).toString(), addOutput[i]);
            assertEquals(subAccessor.getObject(i).toString(), subtractOutput[i]);
            assertEquals(mulAccessor.getObject(i).toString(), multiplyOutput[i]);
        }
        assertEquals(6, addAccessor.getValueCount());
        assertEquals(6, subAccessor.getValueCount());
        assertEquals(6, mulAccessor.getValueCount());
        batchLoader.clear();
        for (QueryDataBatch result : results) {
            result.release();
        }
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) 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) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 42 with DrillClient

use of org.apache.drill.exec.client.DrillClient in project drill by apache.

the class TestOptiqPlans method testJoinPlan.

@Test
public void testJoinPlan() 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_join.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);
                    System.out.println(o);
                }
            }
            loader.clear();
            b.release();
        }
        client.close();
    }
}
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) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 43 with DrillClient

use of org.apache.drill.exec.client.DrillClient in project drill by apache.

the class TestHashJoin method simpleEqualityJoin.

@Test
public void simpleEqualityJoin() throws Throwable {
    // Function checks hash join with single equality condition
    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("/join/hash_join.json"), Charsets.UTF_8).replace("#{TEST_FILE_1}", FileUtils.getResourceAsFile("/build_side_input.json").toURI().toString()).replace("#{TEST_FILE_2}", FileUtils.getResourceAsFile("/probe_side_input.json").toURI().toString()));
        RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
        QueryDataBatch batch = results.get(1);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
        // Just test the join key
        long[] colA = { 1, 1, 2, 2, 1, 1 };
        // Check the output of decimal9
        ValueVector.Accessor intAccessor1 = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < intAccessor1.getValueCount(); i++) {
            assertEquals(intAccessor1.getObject(i), colA[i]);
        }
        assertEquals(6, intAccessor1.getValueCount());
        batchLoader.clear();
        for (QueryDataBatch result : results) {
            result.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) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Example 44 with DrillClient

use of org.apache.drill.exec.client.DrillClient in project drill by apache.

the class TestHashJoin method hjWithExchange1.

@Test
public void hjWithExchange1(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    // Another test for hash join with exchanges
    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(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile("/join/hj_exchanges1.json"), Charsets.UTF_8));
        int count = 0;
        for (final QueryDataBatch b : results) {
            if (b.getHeader().getRowCount() != 0) {
                count += b.getHeader().getRowCount();
            }
            b.release();
        }
        System.out.println("Total records: " + count);
        assertEquals(272, 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) Test(org.junit.Test)

Example 45 with DrillClient

use of org.apache.drill.exec.client.DrillClient in project drill by apache.

the class TestHashJoin method multipleConditionJoin.

@Test
public void multipleConditionJoin(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    // Function tests hash join with multiple join conditions
    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(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile("/join/hj_multi_condition_join.json"), Charsets.UTF_8).replace("#{TEST_FILE_1}", FileUtils.getResourceAsFile("/build_side_input.json").toURI().toString()).replace("#{TEST_FILE_2}", FileUtils.getResourceAsFile("/probe_side_input.json").toURI().toString()));
        final RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());
        final QueryDataBatch batch = results.get(1);
        assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));
        final Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
        // Just test the join key
        final long[] colA = { 1, 2, 1 };
        final long[] colC = { 100, 200, 500 };
        // Check the output of decimal9
        final ValueVector.Accessor intAccessor1 = itr.next().getValueVector().getAccessor();
        final ValueVector.Accessor intAccessor2 = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < intAccessor1.getValueCount(); i++) {
            assertEquals(intAccessor1.getObject(i), colA[i]);
            assertEquals(intAccessor2.getObject(i), colC[i]);
        }
        assertEquals(3, intAccessor1.getValueCount());
        batchLoader.clear();
        for (final QueryDataBatch result : results) {
            result.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) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) DrillClient(org.apache.drill.exec.client.DrillClient) Test(org.junit.Test)

Aggregations

DrillClient (org.apache.drill.exec.client.DrillClient)61 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)57 Drillbit (org.apache.drill.exec.server.Drillbit)55 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)55 Test (org.junit.Test)53 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)37 ValueVector (org.apache.drill.exec.vector.ValueVector)28 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)13 ExecTest (org.apache.drill.exec.ExecTest)8 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)6 DrillConfig (org.apache.drill.common.config.DrillConfig)4 VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)3 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)3 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 BigIntVector (org.apache.drill.exec.vector.BigIntVector)2 Ignore (org.junit.Ignore)2 Stopwatch (com.google.common.base.Stopwatch)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1