markap14 commented on a change in pull request #3223: NIFI-5903: Allow
RecordPath to be used in QueryRecord processor. Also…
URL: https://github.com/apache/nifi/pull/3223#discussion_r255561877
##########
File path:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/QueryRecord.java
##########
@@ -640,4 +667,233 @@ public Connection getConnection() {
return connection;
}
}
+
+
+ // ------------------------------------------------------------
+ // User-Defined Functions for Calcite
+ // ------------------------------------------------------------
+
+
+ public static class ObjectRecordPath extends RecordPathFunction {
+ public Object eval(Object record, String recordPath) {
+ if (record == null) {
+ return null;
+ }
+
+ if (record instanceof Record) {
+ return eval((Record) record, recordPath);
+ }
+ if (record instanceof Record[]) {
+ return eval((Record[]) record, recordPath);
+ }
+
+ throw new RuntimeException("Cannot evaluate RecordPath " +
recordPath + " against given argument because the argument is of type " +
record.getClass() + " instead of Record");
+ }
+
+ private Object eval(final Record record, final String recordPath) {
+ final RecordPath compiled =
RECORD_PATH_CACHE.getCompiled(recordPath);
+ final RecordPathResult result = compiled.evaluate((Record) record);
+
+ final List<FieldValue> selectedFields =
result.getSelectedFields().collect(Collectors.toList());
+ if (selectedFields.isEmpty()) {
+ return null;
+ }
+
+ if (selectedFields.size() == 1) {
+ return selectedFields.get(0).getValue();
+ }
+
+ return selectedFields.stream()
+ .map(FieldValue::getValue)
+ .toArray();
+ }
+
+ // TODO: Test this
Review comment:
Pushed another commit to address.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services