tpalfy commented on a change in pull request #3977: NIFI-7007 Add update 
functionality to the PutCassandraRecord processor.
URL: https://github.com/apache/nifi/pull/3977#discussion_r368658975
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-processors/src/main/java/org/apache/nifi/processors/cassandra/PutCassandraRecord.java
 ##########
 @@ -193,6 +298,74 @@ public void onTrigger(ProcessContext context, 
ProcessSession session) throws Pro
 
     }
 
+    private Statement generateUpdate(String cassandraTable, RecordSchema 
schema, String updateKeys, String updateMethod, Map<String, Object> 
recordContentMap) {
+        Update updateQuery;
+
+        // Split up the update key names separated by a comma, we need at 
least 1 key.
+        final Set<String> updateKeyNames;
+        updateKeyNames = Arrays.stream(updateKeys.split(","))
+                .map(String::trim)
+                .filter(StringUtils::isNotEmpty)
+                .collect(Collectors.toSet());
+        if (updateKeyNames.isEmpty()) {
+            throw new IllegalArgumentException("No Update Keys were 
specified");
+        }
+
+        // Prepare keyspace/table names
+        if (cassandraTable.contains(".")) {
+            String[] keyspaceAndTable = cassandraTable.split("\\.");
+            updateQuery = QueryBuilder.update(keyspaceAndTable[0], 
keyspaceAndTable[1]);
+        } else {
+            updateQuery = QueryBuilder.update(cassandraTable);
+        }
+
+        // Loop through the field names, setting those that are not in the 
update key set, and using those
+        // in the update key set as conditions.
+        for (String fieldName : schema.getFieldNames()) {
 
 Review comment:
   Maybe it would be useful to check if the schema has all the `updateKeyNames`?

----------------------------------------------------------------
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

Reply via email to