Search in sources :

Example 1 with VarBinaryHolder

use of org.apache.drill.exec.expr.holders.VarBinaryHolder in project drill by apache.

the class TestOptiqPlans method testOrderVarbinary.

@Test
public void testOrderVarbinary() 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_order_varbinary.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);
                    if (vv instanceof VarBinaryVector) {
                        final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor();
                        final VarBinaryHolder vbh = new VarBinaryHolder();
                        x.get(i, vbh);
                        System.out.printf("%d..%d", vbh.start, vbh.end);
                        System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]");
                    } else {
                        System.out.println(vv.getAccessor().getObject(i));
                    }
                }
            }
            loader.clear();
            b.release();
        }
        client.close();
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) VarBinaryVector(org.apache.drill.exec.vector.VarBinaryVector) 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) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 2 with VarBinaryHolder

use of org.apache.drill.exec.expr.holders.VarBinaryHolder in project drill by apache.

the class TestOptiqPlans method testFilterString.

@Test
public void testFilterString() 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.LOGICAL, Resources.toString(Resources.getResource("logical_string_filter.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);
                    if (vv instanceof VarBinaryVector) {
                        final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor();
                        final VarBinaryHolder vbh = new VarBinaryHolder();
                        x.get(i, vbh);
                        System.out.printf("%d..%d", vbh.start, vbh.end);
                        System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]");
                    } else {
                        System.out.println(vv.getAccessor().getObject(i));
                    }
                }
            }
            loader.clear();
            b.release();
        }
        client.close();
    }
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) VarBinaryVector(org.apache.drill.exec.vector.VarBinaryVector) 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) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 3 with VarBinaryHolder

use of org.apache.drill.exec.expr.holders.VarBinaryHolder in project drill by axbaretto.

the class BsonRecordReader method writeObjectId.

private void writeObjectId(BsonReader reader, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
    final VarBinaryHolder vObj = new VarBinaryHolder();
    final byte[] objBytes = reader.readObjectId().toByteArray();
    writeBinary(writer, fieldName, isList, vObj, objBytes);
}
Also used : VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder)

Example 4 with VarBinaryHolder

use of org.apache.drill.exec.expr.holders.VarBinaryHolder in project drill by apache.

the class BsonRecordReader method writeObjectId.

private void writeObjectId(BsonReader reader, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
    final VarBinaryHolder vObj = new VarBinaryHolder();
    final byte[] objBytes = reader.readObjectId().toByteArray();
    writeBinary(writer, fieldName, isList, vObj, objBytes);
}
Also used : VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder)

Example 5 with VarBinaryHolder

use of org.apache.drill.exec.expr.holders.VarBinaryHolder in project drill by apache.

the class BsonRecordReader method writeBinary.

private void writeBinary(BsonReader reader, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
    final VarBinaryHolder vb = new VarBinaryHolder();
    BsonBinary readBinaryData = reader.readBinaryData();
    byte[] data = readBinaryData.getData();
    Byte type = (Byte) readBinaryData.getType();
    // Based on specified binary type, cast it accordingly
    switch(type.intValue()) {
        case 1:
            // Double 1
            writeDouble(ByteBuffer.wrap(data).getDouble(), writer, fieldName, isList);
            break;
        case 2:
            // String 2
            writeString(new String(data), writer, fieldName, isList);
            break;
        case 8:
            // Boolean 8
            boolean boolValue = (data == null || data.length == 0) ? false : data[0] != 0x00;
            writeBoolean(boolValue, writer, fieldName, isList);
            break;
        case 9:
            // Date 9
            writeDateTime(ByteBuffer.wrap(data).getLong(), writer, fieldName, isList);
            break;
        case 13:
            // JavaScript 13
            writeString(new String(data), writer, fieldName, isList);
            break;
        case 14:
            // Symbol 14
            writeString(new String(data), writer, fieldName, isList);
            break;
        case 15:
            // JavaScript (with scope) 15
            writeString(new String(data), writer, fieldName, isList);
            break;
        case 16:
            // 32-bit integer 16
            writeInt32(ByteBuffer.wrap(data).getInt(), writer, fieldName, isList);
            break;
        case 17:
            // Timestamp 17
            writeTimeStamp(ByteBuffer.wrap(data).getInt(), writer, fieldName, isList);
            break;
        case 18:
            // 64-bit integer 18
            writeInt64(ByteBuffer.wrap(data).getInt(), writer, fieldName, isList);
            break;
        default:
            // In case of Object(3)/Binary data (5)/Object id (7) or in other case
            // considering as VarBinary
            final byte[] bytes = readBinaryData.getData();
            writeBinary(writer, fieldName, isList, vb, bytes);
            break;
    }
}
Also used : VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder) BsonBinary(org.bson.BsonBinary)

Aggregations

VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)13 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)9 Test (org.junit.Test)9 ExecTest (org.apache.drill.exec.ExecTest)6 DrillClient (org.apache.drill.exec.client.DrillClient)6 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)6 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)6 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)6 Drillbit (org.apache.drill.exec.server.Drillbit)6 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)6 ValueVector (org.apache.drill.exec.vector.ValueVector)6 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)4 PlannerTest (org.apache.drill.categories.PlannerTest)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)3 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)3 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)3 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)3 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)2 UserClientConnection (org.apache.drill.exec.rpc.UserClientConnection)2