Search in sources :

Example 1 with FindQuery

use of org.apache.beam.sdk.io.mongodb.FindQuery in project beam by apache.

the class MongoDbTable method buildIOReader.

@Override
public PCollection<Row> buildIOReader(PBegin begin, BeamSqlTableFilter filters, List<String> fieldNames) {
    MongoDbIO.Read readInstance = MongoDbIO.read().withUri(dbUri).withDatabase(dbName).withCollection(dbCollection);
    final FieldAccessDescriptor resolved = FieldAccessDescriptor.withFieldNames(fieldNames).resolve(getSchema());
    final Schema newSchema = SelectHelpers.getOutputSchema(getSchema(), resolved);
    FindQuery findQuery = FindQuery.create();
    if (!(filters instanceof DefaultTableFilter)) {
        MongoDbFilter mongoFilter = (MongoDbFilter) filters;
        if (!mongoFilter.getSupported().isEmpty()) {
            Bson filter = constructPredicate(mongoFilter.getSupported());
            LOG.info("Pushing down the following filter: " + filter.toString());
            findQuery = findQuery.withFilters(filter);
        }
    }
    if (!fieldNames.isEmpty()) {
        findQuery = findQuery.withProjection(fieldNames);
    }
    readInstance = readInstance.withQueryFn(findQuery);
    return readInstance.expand(begin).apply(DocumentToRow.withSchema(newSchema));
}
Also used : FindQuery(org.apache.beam.sdk.io.mongodb.FindQuery) FieldAccessDescriptor(org.apache.beam.sdk.schemas.FieldAccessDescriptor) Schema(org.apache.beam.sdk.schemas.Schema) DefaultTableFilter(org.apache.beam.sdk.extensions.sql.meta.DefaultTableFilter) MongoDbIO(org.apache.beam.sdk.io.mongodb.MongoDbIO) Bson(org.bson.conversions.Bson)

Aggregations

DefaultTableFilter (org.apache.beam.sdk.extensions.sql.meta.DefaultTableFilter)1 FindQuery (org.apache.beam.sdk.io.mongodb.FindQuery)1 MongoDbIO (org.apache.beam.sdk.io.mongodb.MongoDbIO)1 FieldAccessDescriptor (org.apache.beam.sdk.schemas.FieldAccessDescriptor)1 Schema (org.apache.beam.sdk.schemas.Schema)1 Bson (org.bson.conversions.Bson)1