Search in sources :

Example 31 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project drill by axbaretto.

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 32 with BsonDocumentReader

use of org.bson.BsonDocumentReader 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) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 33 with BsonDocumentReader

use of org.bson.BsonDocumentReader 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) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 34 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project drill by apache.

the class TestBsonRecordReader method testDateTimeType.

@Test
public void testDateTimeType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("dateTimeKey", new BsonDateTime(5262729712L));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(5262729712L, mapReader.reader("dateTimeKey").readLocalDateTime().atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDateTime(org.bson.BsonDateTime) BsonDocumentReader(org.bson.BsonDocumentReader) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 35 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project drill by apache.

the class TestBsonRecordReader method testArrayType.

@Test
public void testArrayType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    BsonWriter bw = new BsonDocumentWriter(bsonDoc);
    bw.writeStartDocument();
    bw.writeName("arrayKey");
    bw.writeStartArray();
    bw.writeInt32(1);
    bw.writeInt32(2);
    bw.writeInt32(3);
    bw.writeEndArray();
    bw.writeEndDocument();
    bw.flush();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    FieldReader reader = mapReader.reader("arrayKey");
    assertEquals(3, reader.size());
}
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

BsonDocumentReader (org.bson.BsonDocumentReader)43 BsonDocument (org.bson.BsonDocument)42 Test (org.junit.Test)30 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)29 BaseTest (org.apache.drill.test.BaseTest)15 BsonString (org.bson.BsonString)9 FieldReader (org.apache.drill.exec.vector.complex.reader.FieldReader)6 BsonDocumentWriter (org.bson.BsonDocumentWriter)6 BsonWriter (org.bson.BsonWriter)6 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)3 BsonBoolean (org.bson.BsonBoolean)3 BsonDateTime (org.bson.BsonDateTime)3 BsonDouble (org.bson.BsonDouble)3 BsonInt32 (org.bson.BsonInt32)3 BsonInt64 (org.bson.BsonInt64)3 BsonNull (org.bson.BsonNull)3 ProjectedTuple (org.immutables.criteria.backend.ProjectedTuple)3 Path (org.immutables.criteria.expression.Path)3 Query (org.immutables.criteria.expression.Query)3