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