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);
}
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;
}
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;
}
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());
}
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());
}
Aggregations