Search in sources :

Example 96 with QueryDataBatch

use of org.apache.drill.exec.rpc.user.QueryDataBatch in project drill by apache.

the class TestHashToRandomExchange 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/hash_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(200, 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 97 with QueryDataBatch

use of org.apache.drill.exec.rpc.user.QueryDataBatch in project drill by apache.

the class TestDecimal method testSimpleDecimal.

@Test
public void testSimpleDecimal() throws Exception {
    /* Function checks casting from VarChar to Decimal9, Decimal18 and vice versa
         * Also tests instances where the scale might have to truncated when scale provided < input fraction
         */
    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("/decimal/cast_simple_decimal.json"), Charsets.UTF_8).read().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[] decimal9Output = { "99.0000", "11.1235", "0.1000", "-0.1200", "-123.1234", "-1.0001" };
        String[] decimal18Output = { "123456789.000000000", "11.123456789", "0.100000000", "-0.100400000", "-987654321.123456789", "-2.030100000" };
        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
        // Check the output of decimal9
        ValueVector.Accessor dec9Accessor = itr.next().getValueVector().getAccessor();
        ValueVector.Accessor dec18Accessor = itr.next().getValueVector().getAccessor();
        for (int i = 0; i < dec9Accessor.getValueCount(); i++) {
            assertEquals(dec9Accessor.getObject(i).toString(), decimal9Output[i]);
            assertEquals(dec18Accessor.getObject(i).toString(), decimal18Output[i]);
        }
        assertEquals(6, dec9Accessor.getValueCount());
        assertEquals(6, dec18Accessor.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) SlowTest(org.apache.drill.categories.SlowTest)

Example 98 with QueryDataBatch

use of org.apache.drill.exec.rpc.user.QueryDataBatch in project drill by apache.

the class TestDecimal method testSimpleDecimalMathFunc.

@Test
public void testSimpleDecimalMathFunc() 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("/decimal/simple_decimal_math.json"), Charsets.UTF_8).read().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()));
        Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
        // Check the output of decimal18
        ValueVector.Accessor dec18Accessor = itr.next().getValueVector().getAccessor();
        assertEquals(6, dec18Accessor.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) SlowTest(org.apache.drill.categories.SlowTest)

Example 99 with QueryDataBatch

use of org.apache.drill.exec.rpc.user.QueryDataBatch 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 100 with QueryDataBatch

use of org.apache.drill.exec.rpc.user.QueryDataBatch 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)

Aggregations

QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)254 Test (org.junit.Test)172 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)155 DrillClient (org.apache.drill.exec.client.DrillClient)125 Drillbit (org.apache.drill.exec.server.Drillbit)119 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)119 SlowTest (org.apache.drill.categories.SlowTest)77 ValueVector (org.apache.drill.exec.vector.ValueVector)73 OperatorTest (org.apache.drill.categories.OperatorTest)52 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)34 BigIntVector (org.apache.drill.exec.vector.BigIntVector)17 ArrayList (java.util.ArrayList)14 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)13 ClusterFixture (org.apache.drill.test.ClusterFixture)13 ClusterTest (org.apache.drill.test.ClusterTest)13 HashMap (java.util.HashMap)12 TreeMap (java.util.TreeMap)12 VectorTest (org.apache.drill.categories.VectorTest)12 ExecTest (org.apache.drill.exec.ExecTest)12 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)12