Search in sources :

Example 6 with SingleMapReaderImpl

use of org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl in project drill by apache.

the class TestBsonRecordReader method testTimeStampType.

@Test
public void testTimeStampType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("ts", new BsonTimestamp(1000, 10));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(1000l, mapReader.reader("ts").readDateTime().getMillis());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) BsonTimestamp(org.bson.BsonTimestamp) Test(org.junit.Test)

Example 7 with SingleMapReaderImpl

use of org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl in project drill by apache.

the class TestBsonRecordReader method testNullType.

@Test
public void testNullType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("nullKey", new BsonNull());
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(null, mapReader.reader("nullKey").readObject());
}
Also used : BsonNull(org.bson.BsonNull) BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) Test(org.junit.Test)

Example 8 with SingleMapReaderImpl

use of org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl in project drill by apache.

the class TestBsonRecordReader method testObjectIdType.

@Test
public void testObjectIdType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    BsonObjectId value = new BsonObjectId(new ObjectId());
    bsonDoc.append("_idKey", value);
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
    assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonDocumentReader(org.bson.BsonDocumentReader) BsonObjectId(org.bson.BsonObjectId) Test(org.junit.Test)

Example 9 with SingleMapReaderImpl

use of org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl in project drill by apache.

the class TestBsonRecordReader method testRecursiveDocuments.

@Test
public void testRecursiveDocuments() throws IOException {
    BsonDocument topDoc = new BsonDocument();
    final int count = 3;
    for (int i = 0; i < count; ++i) {
        BsonDocument bsonDoc = new BsonDocument();
        BsonWriter bw = new BsonDocumentWriter(bsonDoc);
        bw.writeStartDocument();
        bw.writeName("k1" + i);
        bw.writeString("drillMongo1" + i);
        bw.writeName("k2" + i);
        bw.writeString("drillMongo2" + i);
        bw.writeEndDocument();
        bw.flush();
        topDoc.append("doc" + i, bsonDoc);
    }
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(topDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    for (int i = 0; i < count; ++i) {
        SingleMapReaderImpl reader = (SingleMapReaderImpl) mapReader.reader("doc" + i);
        assertEquals("drillMongo1" + i, reader.reader("k1" + i).readText().toString());
        assertEquals("drillMongo2" + i, reader.reader("k2" + i).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) Test(org.junit.Test)

Example 10 with SingleMapReaderImpl

use of org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl in project drill by apache.

the class TestBsonRecordReader method testSymbolType.

@Test
public void testSymbolType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("symbolKey", new BsonSymbol("test_symbol"));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals("test_symbol", mapReader.reader("symbolKey").readText().toString());
}
Also used : BsonSymbol(org.bson.BsonSymbol) BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) Test(org.junit.Test)

Aggregations

SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)14 BsonDocument (org.bson.BsonDocument)14 BsonDocumentReader (org.bson.BsonDocumentReader)14 Test (org.junit.Test)14 FieldReader (org.apache.drill.exec.vector.complex.reader.FieldReader)3 BsonDocumentWriter (org.bson.BsonDocumentWriter)3 BsonWriter (org.bson.BsonWriter)3 BsonString (org.bson.BsonString)2 BsonBinary (org.bson.BsonBinary)1 BsonBoolean (org.bson.BsonBoolean)1 BsonDateTime (org.bson.BsonDateTime)1 BsonDouble (org.bson.BsonDouble)1 BsonInt64 (org.bson.BsonInt64)1 BsonNull (org.bson.BsonNull)1 BsonObjectId (org.bson.BsonObjectId)1 BsonSymbol (org.bson.BsonSymbol)1 BsonTimestamp (org.bson.BsonTimestamp)1 ObjectId (org.bson.types.ObjectId)1