granthenke commented on a change in pull request #3387: NIFI-6009 ScanKudu
Processor & KuduPut Processor Delete Operation
URL: https://github.com/apache/nifi/pull/3387#discussion_r273568584
##########
File path:
nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-processors/src/main/java/org/apache/nifi/kudu/PutKudu.java
##########
@@ -279,43 +217,56 @@ public void onTrigger(final ProcessContext context,
final ProcessSession session
if (flowFiles.isEmpty()) {
return;
}
+ final KuduClientService clientService =
context.getProperty(KUDU_CLIENT_SERVICE).asControllerService(KuduClientService.class);
+ kerberosUser = clientService.getKerberosUser();
final KerberosUser user = kerberosUser;
if (user == null) {
- trigger(context, session, flowFiles);
+ trigger(context, session, flowFiles, clientService);
return;
}
final PrivilegedExceptionAction<Void> privelegedAction = () -> {
- trigger(context, session, flowFiles);
+ trigger(context, session, flowFiles, clientService);
return null;
};
final KerberosAction<Void> action = new KerberosAction<>(user,
privelegedAction, getLogger());
action.execute();
}
- private void trigger(final ProcessContext context, final ProcessSession
session, final List<FlowFile> flowFiles) throws ProcessException {
- final KuduSession kuduSession = getKuduSession(kuduClient);
+ private void trigger(final ProcessContext context, final ProcessSession
session, final List<FlowFile> flowFiles, KuduClientService clientService)
throws ProcessException {
final RecordReaderFactory recordReaderFactory =
context.getProperty(RECORD_READER).asControllerService(RecordReaderFactory.class);
+ try {
+ kuduTable = clientService.getKuduClient().openTable(tableName);
+ } catch (KuduException e) {
+ e.printStackTrace();
+ }
+
+ final KuduClient kuduClient = clientService.getKuduClient();
+ kuduSession = getKuduSession(kuduClient);
+
final Map<FlowFile, Integer> numRecords = new HashMap<>();
final Map<FlowFile, Object> flowFileFailures = new HashMap<>();
final Map<Operation, FlowFile> operationFlowFileMap = new HashMap<>();
int numBuffered = 0;
final List<RowError> pendingRowErrors = new ArrayList<>();
for (FlowFile flowFile : flowFiles) {
+ operationType =
OperationType.valueOf(context.getProperty(INSERT_OPERATION).evaluateAttributeExpressions(flowFile).getValue());
try (final InputStream in = session.read(flowFile);
final RecordReader recordReader =
recordReaderFactory.createRecordReader(flowFile, in, getLogger())) {
final List<String> fieldNames =
recordReader.getSchema().getFieldNames();
final RecordSet recordSet = recordReader.createRecordSet();
Record record = recordSet.next();
while (record != null) {
- Operation operation = operationType == OperationType.UPSERT
- ? upsertRecordToKudu(kuduTable, record, fieldNames)
- : insertRecordToKudu(kuduTable, record, fieldNames);
+ Operation operation = operationType == OperationType.DELETE
Review comment:
This is a pretty complicated ternary statement, it would probably be easier
to read as a switch statement or an if/else.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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