Search in sources :

Example 31 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class ExpressionTest method testSpecial.

@Test
public void testSpecial(@Injectable final RecordBatch batch, @Injectable ValueVector vector) throws Exception {
    final TypeProtos.MajorType type = Types.optional(MinorType.INT);
    final TypedFieldId tfid = new TypedFieldId(type, false, 0);
    new NonStrictExpectations() {

        @NonStrict
        VectorWrapper<?> wrapper;

        {
            batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN));
            result = tfid;
            batch.getValueAccessorById(IntVector.class, tfid.getFieldIds());
            result = wrapper;
            wrapper.getValueVector();
            result = new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c));
        }
    };
    System.out.println(getExpressionCode("1 + 1", batch));
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) TypeProtos(org.apache.drill.common.types.TypeProtos) NonStrictExpectations(mockit.NonStrictExpectations) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 32 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class ParquetRecordReaderTest method testNullableAgg.

@Test
public void testNullableAgg() throws Exception {
    final List<QueryDataBatch> result = testSqlWithResults("select sum(a) as total_sum from dfs.`/tmp/parquet_with_nulls_should_sum_100000_nulls_first.parquet`");
    assertEquals("Only expected one batch with data, and then the empty finishing batch.", 2, result.size());
    final RecordBatchLoader loader = new RecordBatchLoader(getDrillbitContext().getAllocator());
    final QueryDataBatch b = result.get(0);
    loader.load(b.getHeader().getDef(), b.getData());
    final VectorWrapper vw = loader.getValueAccessorById(NullableBigIntVector.class, loader.getValueVectorId(SchemaPath.getCompoundPath("total_sum")).getFieldIds());
    assertEquals(4999950000l, vw.getValueVector().getAccessor().getObject(0));
    b.release();
    loader.clear();
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) Test(org.junit.Test)

Example 33 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper in project drill by apache.

the class ParquetResultListener method printRowMajor.

public void printRowMajor(RecordBatchLoader batchLoader) {
    for (int i = 0; i < batchLoader.getRecordCount(); i++) {
        if (i % 50 == 0) {
            System.out.println();
            for (VectorWrapper vw : batchLoader) {
                ValueVector v = vw.getValueVector();
                System.out.print(Strings.padStart(v.getField().getPath(), 20, ' ') + " ");
            }
            System.out.println();
            System.out.println();
        }
        for (final VectorWrapper vw : batchLoader) {
            final ValueVector v = vw.getValueVector();
            Object o = v.getAccessor().getObject(i);
            if (o instanceof byte[]) {
                try {
                    // TODO - in the dictionary read error test there is some data that does not look correct
                    // the output of our reader matches the values of the parquet-mr cat/head tools (no full comparison was made,
                    // but from a quick check of a few values it looked consistent
                    // this might have gotten corrupted by pig somehow, or maybe this is just how the data is supposed ot look
                    // TODO - check this!!
                    //              for (int k = 0; k < ((byte[])o).length; k++ ) {
                    //                // check that the value at each position is a valid single character ascii value.
                    //
                    //                if (((byte[])o)[k] > 128) {
                    //                  System.out.println("batch: " + batchCounter + " record: " + recordCount);
                    //                }
                    //              }
                    o = new String((byte[]) o, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.print(Strings.padStart(o + "", 20, ' ') + " ");
        }
        System.out.println();
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 34 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper 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 35 with VectorWrapper

use of org.apache.drill.exec.record.VectorWrapper 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

VectorWrapper (org.apache.drill.exec.record.VectorWrapper)36 ValueVector (org.apache.drill.exec.vector.ValueVector)23 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)17 Test (org.junit.Test)17 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)16 DrillClient (org.apache.drill.exec.client.DrillClient)13 Drillbit (org.apache.drill.exec.server.Drillbit)13 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)13 ExecTest (org.apache.drill.exec.ExecTest)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 Stopwatch (com.google.common.base.Stopwatch)3 IOException (java.io.IOException)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 ClassTransformationException (org.apache.drill.exec.exception.ClassTransformationException)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)3 VectorContainer (org.apache.drill.exec.record.VectorContainer)3 VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)2 RecordBatchData (org.apache.drill.exec.physical.impl.sort.RecordBatchData)2 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)2