This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new a0d4670ad829 fix: close JDBC connection in UtilHelpers.getJDBCSchema
to prevent connection leak (#19772)
a0d4670ad829 is described below
commit a0d4670ad829669876448db46484f5cacad99641
Author: Venkateswarlu Boggavarapu <[email protected]>
AuthorDate: Thu Aug 27 22:28:20 2026 -0400
fix: close JDBC connection in UtilHelpers.getJDBCSchema to prevent
connection leak (#19772)
---
.../org/apache/hudi/utilities/UtilHelpers.java | 35 ++++++----------------
1 file changed, 9 insertions(+), 26 deletions(-)
diff --git
a/hudi-utilities/src/main/java/org/apache/hudi/utilities/UtilHelpers.java
b/hudi-utilities/src/main/java/org/apache/hudi/utilities/UtilHelpers.java
index a416bb82bb37..fd048a7f96f3 100644
--- a/hudi-utilities/src/main/java/org/apache/hudi/utilities/UtilHelpers.java
+++ b/hudi-utilities/src/main/java/org/apache/hudi/utilities/UtilHelpers.java
@@ -518,36 +518,19 @@ public class UtilHelpers {
* @throws Exception
*/
public static HoodieSchema getJDBCSchema(Map<String, String> options) {
- Connection conn;
- String url;
- String table;
- boolean tableExists;
- try {
- conn = createConnection(options);
- url = options.get(JDBCOptions.JDBC_URL());
- table = options.get(JDBCOptions.JDBC_TABLE_NAME());
- tableExists = tableExists(conn, options);
- } catch (Exception e) {
- throw new HoodieSchemaFetchException("Failed to connect to jdbc", e);
- }
-
- if (!tableExists) {
- throw new HoodieSchemaFetchException(String.format("%s table does not
exists!", table));
- }
-
- try {
+ String url = options.get(JDBCOptions.JDBC_URL());
+ String table = options.get(JDBCOptions.JDBC_TABLE_NAME());
+ try (Connection conn = createConnection(options)) {
+ if (!tableExists(conn, options)) {
+ throw new HoodieSchemaFetchException(String.format("%s table does not
exist!", table));
+ }
JdbcDialect dialect = JdbcDialects.get(url);
try (PreparedStatement statement =
conn.prepareStatement(dialect.getSchemaQuery(table))) {
statement.setQueryTimeout(Integer.parseInt(options.get("queryTimeout")));
try (ResultSet rs = statement.executeQuery()) {
- StructType structType;
- if (Boolean.parseBoolean(options.get("nullable"))) {
- structType =
SparkAdapterSupport$.MODULE$.sparkAdapter().getSchemaUtils()
- .getSchema(conn, rs, dialect, true, false);
- } else {
- structType =
SparkAdapterSupport$.MODULE$.sparkAdapter().getSchemaUtils()
- .getSchema(conn, rs, dialect, false, false);
- }
+ boolean nullable = Boolean.parseBoolean(options.get("nullable"));
+ StructType structType =
SparkAdapterSupport$.MODULE$.sparkAdapter().getSchemaUtils()
+ .getSchema(conn, rs, dialect, nullable, false);
return
HoodieSchemaConversionUtils.convertStructTypeToHoodieSchema(structType, table,
"hoodie." + table);
}
}