Skip to content

Conversation

@spects
Copy link

@spects spects commented Nov 15, 2025

Summary

NIFI-15224

Implement SQL Pre-Query and SQL Post-Query in PutDatabaseRecord. Implementation draws from AbstractExecuteSQL's implementation.

  • Create pre- and post-query properties in PutDatabaseRecord.java. Process statements into lists, execute statements before and after putToDatabase()
  • Add unit tests: test insert with Pre- and Post- queries, with and without an expected failure

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for proposing this improvement @spects.

The general approach looks good, aligning with the feature implemented in ExecuteSQL.

I noted a few minor implementation recommendations.

* Executes given queries using pre-defined connection.
* Returns null on success, or a query string if failed.
*/
private Pair<String, SQLException> executeConfigStatements(final Connection con, final List<String> configQueries) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching and returning the exception, just to throw it from the calling method, does not seem like the best approach. I recommend simply declaring throws SQLException on this method and not returning anything.

Comment on lines +419 to +422
.description("A semicolon-delimited list of queries executed before the main SQL query is executed. " +
"For example, set session properties before main query. " +
"It's possible to include semicolons in the statements themselves by escaping them with a backslash ('\\;'). " +
"Results/outputs from these queries will be suppressed if there are no errors.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A multiline string can be used instead of string concatenation to build the description.

Comment on lines +2198 to +2223
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals("rec1", rs.getString(2));
assertEquals(101, rs.getInt(3));
assertEquals(jdbcDate1.toString(), rs.getDate(4).toString());
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertEquals("rec2", rs.getString(2));
assertEquals(102, rs.getInt(3));
assertEquals(jdbcDate2.toString(), rs.getDate(4).toString());
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
assertEquals("rec3", rs.getString(2));
assertEquals(103, rs.getInt(3));
assertNull(rs.getDate(4));
assertTrue(rs.next());
assertEquals(4, rs.getInt(1));
assertEquals("rec4", rs.getString(2));
assertEquals(104, rs.getInt(3));
assertNull(rs.getDate(4));
assertTrue(rs.next());
assertEquals(5, rs.getInt(1));
assertNull(rs.getString(2));
assertEquals(105, rs.getInt(3));
assertNull(rs.getDate(4));
assertFalse(rs.next());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions appear to be duplicated in the other test method. Recommend creating a shared private assertResultsFound() method or similar to delegate the evaluation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants