linliu-code opened a new pull request, #18441:
URL: https://github.com/apache/hudi/pull/18441

   ### Describe the issue this Pull Request addresses
   
     HiveIncrementalPuller has two related bugs in executeIncrementalSQL:
   
     1. Resource leak: The Scanner opened on the incremental SQL file is never 
closed — new Scanner(new File(...)).useDelimiter("\\Z").next() leaks the file 
handle on every invocation.
     2. Late validation: The SQL file is validated (checks for correct source 
table reference and _hoodie_commit_time predicate) inside 
executeIncrementalSQL, which is only called after a JDBC connection has been 
established and a DROP TABLE IF EXISTS has already been issued. A misconfigured 
SQL file therefore wastes a connection and mutates state before the error is 
caught.
   
   ### Summary and Changelog
   
     Summary: SQL file validation now happens eagerly before any JDBC work, and 
the file handle is properly released after reading.
   
     - Extracted SQL validation into a new private validateIncrementalSQL() 
method and moved the call to the top of saveDelta(), before the JDBC connection 
is opened.
     - Wrapped Scanner in try-with-resources to guarantee the file handle is 
closed after reading, even on error.
     - Widened executeIncrementalSQL from private to package-private to enable 
unit testing the SQL template rendering logic without a live Hive server.
     - Added TestHiveIncrementalPullerExecuteSQL with three test cases: correct 
SQL rendering and commit-time substitution, FileNotFoundException on missing 
SQL file, and SQLException propagation on JDBC execution failure.
   
   ### Impact
   
     No public API or user-facing behavior change. The only observable 
difference is that a misconfigured incrementalSQLFile now throws before a JDBC 
connection is opened rather than after.
   
   ### Risk Level
   
     Low. The logic is unchanged — validation conditions are identical to 
before. The refactor only reorders when validation occurs (earlier) and ensures 
the Scanner is closed. Covered by new unit tests.
   
   ### Documentation Update
   
   <!-- Describe any necessary documentation update if there is any new 
feature, config, or user-facing change. If not, put "none".
   
   - The config description must be updated if new configs are added or the 
default value of the configs are changed.
   - Any new feature or user-facing change requires updating the Hudi website. 
Please follow the 
     [instruction](https://hudi.apache.org/contribute/developer-setup#website) 
to make changes to the website. -->
   
   ### Contributor's checklist
   
   - [ ] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [ ] Enough context is provided in the sections above
   - [ ] Adequate tests were added if applicable
   


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