mirror of https://github.com/apache/nifi.git
NIFI-6293
Add support to Mongo Extended JSON v2 Add org.json lib Replace evil json Replace evil json for alternative Include testExtendedJsonSupport Style adjustment Remove unecessary new JSON parser Fix query in testExtendedJsonSupport Parse with Jackson and BSON Back to default MONGO_URI This closes #4068 Signed-off-by: Mike Thomsen <mthomsen@apache.org>
This commit is contained in:
parent
f91d6c420d
commit
943de310ad
|
@ -75,9 +75,10 @@ public class RunMongoAggregation extends AbstractMongoProcessor {
|
|||
List<Bson> result = new ArrayList<>();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
List<Map> values = mapper.readValue(query, List.class);
|
||||
for (Map<?, ?> val : values) {
|
||||
result.add(new BasicDBObject(val));
|
||||
List<Map> querySteps = mapper.readValue(query, List.class);
|
||||
for (Map<?, ?> queryStep : querySteps) {
|
||||
BasicDBObject bson = BasicDBObject.parse(mapper.writeValueAsString(queryStep));
|
||||
result.add(bson);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -236,4 +236,31 @@ public class RunMongoAggregationIT {
|
|||
runner.run();
|
||||
runner.assertTransferCount(RunMongoAggregation.REL_RESULTS, 9);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedJsonSupport() throws Exception {
|
||||
String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
|
||||
final String queryInput = "[\n" +
|
||||
" {\n" +
|
||||
" \"$match\": {\n" +
|
||||
" \"date\": { \"$gte\": { \"$date\": \"2019-01-01T00:00:00Z\" }, \"$lte\": { \"$date\": \"" + simpleDateFormat.format(now.getTime()) + "\" } }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"$group\": {\n" +
|
||||
" \"_id\": \"$val\",\n" +
|
||||
" \"doc_count\": {\n" +
|
||||
" \"$sum\": 1\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"]\n";
|
||||
|
||||
runner.setProperty(RunMongoAggregation.QUERY, queryInput);
|
||||
runner.enqueue("test");
|
||||
runner.run(1, true, true);
|
||||
|
||||
runner.assertTransferCount(RunMongoAggregation.REL_RESULTS, mappings.size());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue