pvillard31 commented on code in PR #10771:
URL: https://github.com/apache/nifi/pull/10771#discussion_r2691554548


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java:
##########
@@ -1195,6 +1226,38 @@ private void putToDatabase(final ProcessContext context, 
final ProcessSession se
                 executeDML(context, session, flowFile, connection, 
recordReader, statementType, settings);
             }
         }
+
+        final List<String> postProcessingSqlStatements = 
getSqlStatements(context, flowFile, POST_PROCESSING_SQL);
+        executeSqlStatements(connection, postProcessingSqlStatements, 
POST_PROCESSING_SQL);
+    }
+
+    private List<String> getSqlStatements(final ProcessContext context, final 
FlowFile flowFile, final PropertyDescriptor propertyDescriptor) {
+        final List<String> sqlStatements;
+
+        final String propertyValue = 
context.getProperty(propertyDescriptor).evaluateAttributeExpressions(flowFile).getValue();
+        if (propertyValue == null || propertyValue.isBlank()) {
+            sqlStatements = List.of();
+        } else {
+            final String[] statements = 
UNESCAPED_SEMICOLON_PATTERN.split(propertyValue);
+            sqlStatements = new ArrayList<>(statements.length);
+            for (String statement : statements) {
+                final String sqlStatement = 
statement.replaceAll(ESCAPED_SEMICOLON, SEMICOLON);
+                sqlStatements.add(sqlStatement);

Review Comment:
   Do we want to check that the sqlStatement is not empty like in 
https://github.com/apache/nifi/blob/main/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java#L559
 ?



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java:
##########
@@ -215,6 +215,28 @@ public class PutDatabaseRecord extends AbstractProcessor {
             .expressionLanguageSupported(NONE)
             .build();
 
+    static final PropertyDescriptor PRE_PROCESSING_SQL = new Builder()
+            .name("Pre-Processing SQL")
+            .description("""
+                    One or more SQL statements, separated by semicolons, 
executed on the current database connection,

Review Comment:
   Do we want to mention escaped semicolons like in 
https://github.com/apache/nifi/blob/main/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java#L97
 ? Not sure that's used a lot but maybe for consistency?



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java:
##########
@@ -1195,6 +1226,38 @@ private void putToDatabase(final ProcessContext context, 
final ProcessSession se
                 executeDML(context, session, flowFile, connection, 
recordReader, statementType, settings);
             }
         }
+
+        final List<String> postProcessingSqlStatements = 
getSqlStatements(context, flowFile, POST_PROCESSING_SQL);
+        executeSqlStatements(connection, postProcessingSqlStatements, 
POST_PROCESSING_SQL);
+    }
+
+    private List<String> getSqlStatements(final ProcessContext context, final 
FlowFile flowFile, final PropertyDescriptor propertyDescriptor) {
+        final List<String> sqlStatements;
+
+        final String propertyValue = 
context.getProperty(propertyDescriptor).evaluateAttributeExpressions(flowFile).getValue();
+        if (propertyValue == null || propertyValue.isBlank()) {
+            sqlStatements = List.of();
+        } else {
+            final String[] statements = 
UNESCAPED_SEMICOLON_PATTERN.split(propertyValue);
+            sqlStatements = new ArrayList<>(statements.length);
+            for (String statement : statements) {
+                final String sqlStatement = 
statement.replaceAll(ESCAPED_SEMICOLON, SEMICOLON);

Review Comment:
   Should we trim() like in 
https://github.com/apache/nifi/blob/main/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java#L560
 ?



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to