Search in sources :

Example 6 with FieldReader

use of org.apache.drill.exec.vector.complex.reader.FieldReader in project drill by axbaretto.

the class ListVector method copyFrom.

public void copyFrom(int inIndex, int outIndex, ListVector from) {
    FieldReader in = from.getReader();
    in.setPosition(inIndex);
    FieldWriter out = getWriter();
    out.setPosition(outIndex);
    ComplexCopier.copy(in, out);
}
Also used : FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader) FieldWriter(org.apache.drill.exec.vector.complex.writer.FieldWriter)

Example 7 with FieldReader

use of org.apache.drill.exec.vector.complex.reader.FieldReader in project drill by apache.

the class ComplexSchemaUtils method getFields.

public static DrillBuf getFields(FieldReader reader, BaseWriter.ComplexWriter outWriter, DrillBuf buffer) {
    BaseWriter.MapWriter queryMapWriter = outWriter.rootAsMap();
    if (reader.getType().getMinorType() != MinorType.MAP) {
        // If the field is not a map, return an empty map
        queryMapWriter.start();
        queryMapWriter.end();
    }
    Iterator<String> fieldIterator = reader.iterator();
    queryMapWriter.start();
    while (fieldIterator.hasNext()) {
        String fieldName = fieldIterator.next();
        FieldReader fieldReader = reader.reader(fieldName);
        String dataType = fieldReader.getType().getMinorType().toString();
        DataMode dataMode = fieldReader.getType().getMode();
        if (dataMode == DataMode.REPEATED) {
            dataType = dataMode + "_" + dataType;
        }
        VarCharHolder rowHolder = new VarCharHolder();
        byte[] rowStringBytes = dataType.getBytes();
        buffer = buffer.reallocIfNeeded(rowStringBytes.length);
        buffer.setBytes(0, rowStringBytes);
        rowHolder.start = 0;
        rowHolder.end = rowStringBytes.length;
        rowHolder.buffer = buffer;
        queryMapWriter.varChar(fieldName).write(rowHolder);
    }
    queryMapWriter.end();
    return buffer;
}
Also used : BaseWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader)

Example 8 with FieldReader

use of org.apache.drill.exec.vector.complex.reader.FieldReader in project drill by apache.

the class AbstractRepeatedMapReaderImpl method reader.

@Override
public FieldReader reader(String name) {
    FieldReader reader = fields.get(name);
    if (reader == null) {
        ValueVector child = vector.getChild(name);
        if (child == null) {
            reader = NullReader.INSTANCE;
        } else {
            reader = child.getReader();
        }
        fields.put(name, reader);
        reader.setPosition(currentOffset);
    }
    return reader;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader)

Example 9 with FieldReader

use of org.apache.drill.exec.vector.complex.reader.FieldReader in project drill by apache.

the class TestBsonRecordReader method testBinaryTypes.

@Test
public void testBinaryTypes() throws IOException {
    // test with different binary types
    BsonDocument bsonDoc = new BsonDocument();
    // Binary
    // String
    byte[] bytes = "binaryValue".getBytes();
    bsonDoc.append("binaryKey", new BsonBinary(BsonBinarySubType.BINARY, bytes));
    // String
    byte[] bytesString = "binaryStringValue".getBytes();
    bsonDoc.append("binaryStringKey", new BsonBinary((byte) 2, bytesString));
    // Double
    byte[] bytesDouble = new byte[8];
    java.nio.ByteBuffer.wrap(bytesDouble).putDouble(23.0123);
    BsonBinary bsonDouble = new BsonBinary((byte) 1, bytesDouble);
    bsonDoc.append("binaryDouble", bsonDouble);
    // Boolean
    byte[] booleanBytes = new byte[8];
    java.nio.ByteBuffer.wrap(booleanBytes).put((byte) 1);
    BsonBinary bsonBoolean = new BsonBinary((byte) 8, booleanBytes);
    bsonDoc.append("bsonBoolean", bsonBoolean);
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertArrayEquals(bytes, mapReader.reader("binaryKey").readByteArray());
    assertEquals("binaryStringValue", mapReader.reader("binaryStringKey").readText().toString());
    assertEquals(23.0123, mapReader.reader("binaryDouble").readDouble(), 0);
    FieldReader reader = mapReader.reader("bsonBoolean");
    assertEquals(true, reader.readBoolean());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonBinary(org.bson.BsonBinary) BsonDocumentReader(org.bson.BsonDocumentReader) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 10 with FieldReader

use of org.apache.drill.exec.vector.complex.reader.FieldReader in project drill by apache.

the class TestBsonRecordReader method testArrayOfDocumentType.

@Test
public void testArrayOfDocumentType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    BsonWriter bw = new BsonDocumentWriter(bsonDoc);
    bw.writeStartDocument();
    bw.writeName("a");
    bw.writeString("MongoDB");
    bw.writeName("b");
    bw.writeStartArray();
    bw.writeStartDocument();
    bw.writeName("c");
    bw.writeInt32(1);
    bw.writeEndDocument();
    bw.writeEndArray();
    bw.writeEndDocument();
    bw.flush();
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    FieldReader reader = writer.getMapVector().getReader();
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) reader;
    FieldReader reader3 = mapReader.reader("b");
    assertEquals("MongoDB", mapReader.reader("a").readText().toString());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDocumentWriter(org.bson.BsonDocumentWriter) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonWriter(org.bson.BsonWriter) BsonDocumentReader(org.bson.BsonDocumentReader) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Aggregations

FieldReader (org.apache.drill.exec.vector.complex.reader.FieldReader)30 Test (org.junit.Test)8 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)6 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)6 BaseWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter)6 BsonDocument (org.bson.BsonDocument)6 BsonDocumentReader (org.bson.BsonDocumentReader)6 ValueVector (org.apache.drill.exec.vector.ValueVector)5 VarCharHolder (org.apache.drill.exec.expr.holders.VarCharHolder)4 BaseTest (org.apache.drill.test.BaseTest)4 BsonDocumentWriter (org.bson.BsonDocumentWriter)4 BsonWriter (org.bson.BsonWriter)4 DataMode (org.apache.drill.common.types.TypeProtos.DataMode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Annotation (java.lang.annotation.Annotation)2 Inject (javax.inject.Inject)2 FieldDescriptor (org.apache.drill.common.scanner.persistence.FieldDescriptor)2 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)2