You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Caideyipi (via GitHub)" <gi...@apache.org> on 2026/06/08 08:14:35 UTC
[PR] Improve JDBC driver metadata [iotdb]
Caideyipi opened a new pull request, #17865:
URL: https://github.com/apache/iotdb/pull/17865
### Description
- Implement JDBC Driver version and connection property metadata.
- Make acceptsURL(null) return false.
- Add IoTDBDriver unit coverage.
### Tests
- mvn -pl iotdb-client/jdbc spotless:apply
- MAVEN_OPTS='-Xms64m -Xmx256m -XX:MaxMetaspaceSize=256m -XX:ReservedCodeCacheSize=64m' mvn -Ddevelocity.off=true -pl iotdb-client/jdbc -Dtest=IoTDBDriverTest test
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Improve JDBC driver metadata [iotdb]
Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #17865:
URL: https://github.com/apache/iotdb/pull/17865#discussion_r4373563380
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java:
##########
@@ -722,49 +818,97 @@ public int getResultSetType() throws SQLException {
}
@Override
- public int getUpdateCount() {
+ public int getUpdateCount() throws SQLException {
+ checkConnection("getUpdateCount");
return -1;
}
@Override
- public SQLWarning getWarnings() {
+ public SQLWarning getWarnings() throws SQLException {
+ checkConnection("getWarnings");
return warningChain;
}
@Override
public boolean isCloseOnCompletion() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_IS_CLOSE_ON_COMPLETION);
+ throw unsupportedOperation(
+ "isCloseOnCompletion", JdbcMessages.NOT_SUPPORT_IS_CLOSE_ON_COMPLETION);
}
@Override
public boolean isClosed() {
- return isClosed;
+ return isClosed || connection == null || connection.isClosed();
}
@Override
public boolean isPoolable() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_IS_POOLABLE);
+ throw unsupportedOperation("isPoolable", JdbcMessages.NOT_SUPPORT_IS_POOLABLE);
}
@Override
public void setPoolable(boolean arg0) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_POOLABLE);
+ throw unsupportedOperation("setPoolable", JdbcMessages.NOT_SUPPORT_SET_POOLABLE);
}
@Override
public void setCursorName(String arg0) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_CURSOR_NAME);
+ throw unsupportedOperation("setCursorName", JdbcMessages.NOT_SUPPORT_SET_CURSOR_NAME);
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_ESCAPE_PROCESSING);
+ throw unsupportedOperation(
+ "setEscapeProcessing", JdbcMessages.NOT_SUPPORT_SET_ESCAPE_PROCESSING);
}
- private void checkConnection(String action) throws SQLException {
+ protected void checkConnection(String action) throws SQLException {
if (connection == null || connection.isClosed()) {
throw new SQLException(String.format(JdbcMessages.CANNOT_AFTER_CONNECTION_CLOSED, action));
}
+ if (isClosed) {
+ throw new SQLException(String.format(CANNOT_AFTER_STATEMENT_CLOSED, action));
+ }
+ }
+
+ protected void closeCurrentResultSet() throws SQLException {
+ if (resultSet != null) {
+ ResultSet currentResultSet = resultSet;
Review Comment:
[P2] Retain failed query cleanup before reusing the statement
If closing the current ResultSet fails, this method discards its reference before cleanup succeeds. ResultSet.close() also refuses subsequent cleanup attempts, so the next execution can overwrite the old query ID without releasing that query. Retain the ResultSet until successful cleanup, allow close retries while continuing to reject reads, and retry any pending query cleanup after result-set construction fails.
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java:
##########
@@ -51,6 +51,9 @@ private Config() {
static final int RETRY_NUM = 3;
static final long RETRY_INTERVAL_MS = 1000;
+ static final int DRIVER_MAJOR_VERSION = 4;
Review Comment:
[P2] Report the driver build version separately from the JDBC API version
The artifact is 2.0.11-SNAPSHOT, but Driver.getMajorVersion()/getMinorVersion() report 4.3. Those methods describe the driver release; getJDBCMajorVersion()/getJDBCMinorVersion() already describe JDBC 4.3. Read the release from a Maven-filtered resource and share it with both database metadata implementations.
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -786,119 +853,135 @@ public Time getTime(String columnName) throws SQLException {
@Override
public Time getTime(int arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Time getTime(String arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ checkOpen();
try {
return ioTDBRpcDataSet.getTimestamp(columnIndex);
- } catch (StatementExecutionException e) {
+ } catch (StatementExecutionException | IllegalArgumentException | IndexOutOfBoundsException e) {
throw new SQLException(e.getMessage());
}
}
@Override
public Timestamp getTimestamp(String columnName) throws SQLException {
+ checkOpen();
try {
return ioTDBRpcDataSet.getTimestamp(columnName);
- } catch (StatementExecutionException | IllegalArgumentException e) {
+ } catch (StatementExecutionException | IllegalArgumentException | IndexOutOfBoundsException e) {
throw new SQLException(e.getMessage());
}
}
@Override
public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Timestamp getTimestamp(String arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
- public int getType() {
+ public int getType() throws SQLException {
+ checkOpen();
return ResultSet.TYPE_FORWARD_ONLY;
}
@Override
public URL getURL(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public URL getURL(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getUnicodeStream(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getUnicodeStream(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
- public SQLWarning getWarnings() {
+ public SQLWarning getWarnings() throws SQLException {
+ checkOpen();
return warningChain;
}
@Override
public void insertRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean isAfterLast() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean isBeforeFirst() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean isClosed() {
- return ioTDBRpcDataSet.isClosed();
+ return explicitlyClosed;
+ }
+
+ private void checkOpen() throws SQLException {
+ if (explicitlyClosed) {
+ throw new SQLException("ResultSet has been closed");
Review Comment:
[P2] Localize the newly added JDBC messages
The new ResultSet/Statement/parameter/URL validation errors and DriverPropertyInfo descriptions use inline English strings. Under with-zh-locale these new paths remain English, contrary to the repository's i18n requirement. Move the complete messages to matching en/zh JdbcMessages constants and make the affected assertions locale-independent.
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDriver.java:
##########
@@ -90,13 +97,87 @@ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
}
@Override
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
- // TODO Auto-generated method stub
- return new DriverPropertyInfo[0];
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
+ Properties properties = info == null ? new Properties() : (Properties) info.clone();
+ if (url != null && acceptsURL(url)) {
+ Utils.parseUrl(url, properties);
+ }
+ return new DriverPropertyInfo[] {
+ createProperty(
+ Config.AUTH_USER, Config.DEFAULT_USER, "User name for authentication.", properties),
+ createSensitiveProperty(Config.AUTH_PASSWORD, "Password for authentication."),
+ createProperty(
+ Config.DEFAULT_BUFFER_CAPACITY,
+ String.valueOf(RpcUtils.THRIFT_DEFAULT_BUF_CAPACITY),
+ "Thrift default buffer capacity in bytes.",
+ properties),
+ createProperty(
+ Config.THRIFT_FRAME_MAX_SIZE,
+ String.valueOf(RpcUtils.THRIFT_FRAME_MAX_SIZE),
+ "Thrift max frame size in bytes.",
+ properties),
+ createProperty(
+ Config.VERSION,
+ Config.DEFAULT_VERSION.name(),
+ VERSION_CHOICES,
+ "Client compatibility version.",
+ properties),
+ createProperty(
+ Config.NETWORK_TIMEOUT,
+ String.valueOf(Config.DEFAULT_CONNECTION_TIMEOUT_MS),
+ "Network timeout in milliseconds.",
+ properties),
+ createProperty(
+ Config.TIME_ZONE, ZoneId.systemDefault().toString(), "Connection time zone.", properties),
+ createProperty(
+ Config.CHARSET, TSFileConfig.STRING_CHARSET.name(), "Connection charset.", properties),
+ createProperty(
+ Config.USE_SSL, "false", BOOLEAN_CHOICES, "Whether to enable SSL.", properties),
+ createProperty(
+ Utils.RPC_COMPRESS,
+ String.valueOf(Config.rpcThriftCompressionEnable),
+ BOOLEAN_CHOICES,
+ "Whether to enable RPC thrift compression.",
+ properties),
+ createProperty(Config.TRUST_STORE, null, "SSL trust store path.", properties),
+ createSensitiveProperty(Config.TRUST_STORE_PWD, "SSL trust store password."),
Review Comment:
[P2] Include the supported client-key and protocol properties
The parser and connection now support key_store, key_store_pwd and ssl_protocol, but getPropertyInfo() omits all three. JDBC tools that build their configuration UI from this metadata cannot discover the client certificate settings or protocol selection. Include these properties and keep the key-store password value redacted.
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDataSource.java:
##########
@@ -89,61 +154,110 @@ public void setUrl(String url) {
this.url = url;
}
+ String getConnectionProperty(String key) {
+ return properties.getProperty(key);
+ }
+
+ void setConnectionProperty(String key, String value) {
+ setProperty(key, value);
+ }
+
@Override
public Connection getConnection() throws SQLException {
- try {
- return new IoTDBConnection(url, properties);
- } catch (TTransportException e) {
- LOGGER.error(JdbcMessages.GET_CONNECTION_ERROR, e);
- }
- return null;
+ return createConnection((Properties) properties.clone());
}
@Override
- public Connection getConnection(String username, String password) {
- try {
- Properties newProp = new Properties();
- newProp.setProperty("user", username);
- newProp.setProperty(PWD_STR, password);
- return new IoTDBConnection(url, newProp);
- } catch (Exception e) {
- LOGGER.error(JdbcMessages.GET_CONNECTION_ERROR, e);
- }
- return null;
+ public Connection getConnection(String username, String password) throws SQLException {
+ Properties newProp = (Properties) properties.clone();
+ setProperty(newProp, Config.AUTH_USER, username);
+ setProperty(newProp, Config.AUTH_PASSWORD, password);
+ return createConnection(newProp);
}
@Override
public PrintWriter getLogWriter() {
- return null;
+ return logWriter;
}
@Override
public void setLogWriter(PrintWriter printWriter) {
- // Do nothing
+ this.logWriter = printWriter;
}
@Override
- public void setLoginTimeout(int i) {
- // Do nothing
+ public void setLoginTimeout(int i) throws SQLException {
+ if (i < 0) {
+ throw new SQLException("loginTimeout must be >= 0");
+ }
+ this.loginTimeout = i;
}
@Override
public int getLoginTimeout() {
- return 0;
+ return loginTimeout;
}
@Override
- public java.util.logging.Logger getParentLogger() {
- return null;
+ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ throw new SQLFeatureNotSupportedException(JdbcMessages.METHOD_NOT_SUPPORTED);
}
@Override
- public <T> T unwrap(Class<T> aClass) {
- return null;
+ public <T> T unwrap(Class<T> aClass) throws SQLException {
+ return JdbcWrapperUtils.unwrap(this, aClass);
}
@Override
public boolean isWrapperFor(Class<?> aClass) {
- return false;
+ return JdbcWrapperUtils.isWrapperFor(this, aClass);
+ }
+
+ private Connection createConnection(Properties connectionProperties) throws SQLException {
+ applyLoginTimeout(connectionProperties);
Review Comment:
[P2] Keep the login timeout from becoming the query socket timeout
setLoginTimeout(2) currently injects network_timeout=2000, so the returned connection retains a two-second read timeout and later queries can time out even though login completed successfully. Apply this limit during connection/session establishment, then restore the separately configured network timeout.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Improve JDBC driver metadata [iotdb]
Posted by "Caideyipi (via GitHub) via reviews" <re...@iotdb.apache.org>.
Caideyipi commented on PR #17865:
URL: https://github.com/apache/iotdb/pull/17865#issuecomment-6969122776
Re-review: one behavioral issue was found and fixed. IoTDBDataSource now brackets IPv6 serverName values when it builds a JDBC URL from standard DataSource properties; regression coverage includes bracketed and unbracketed IPv6 literals.
Reviewed candidate: e27a03454c61392682000a2e645a97a484697b45
Final local commit: 4f014eddfebcaa7c7b6b5b1a8e112f114f55434c
Confirmed PR head: 4f014eddfebcaa7c7b6b5b1a8e112f114f55434c
Verification: Spotless passed; all 249 selected JDBC tests passed (0 failures, 0 errors, 0 skipped). The PR remains draft pending a fresh independent review of the latest head.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Improve JDBC driver metadata [iotdb]
Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on PR #17865:
URL: https://github.com/apache/iotdb/pull/17865#issuecomment-6407151081
Self-review passed for 8cf00e1c5ef4a9e1d5a56d800f102a254252492b. Reviewed the full PR diff and relevant context; all five actionable findings have been fixed and the review threads resolved.
Fixes:
- Derive the driver release version from Maven build metadata, consistently across Driver and both DatabaseMetaData implementations, while retaining JDBC API version 4.3.
- Retain failed ResultSet/query cleanup and retry it before statement reuse; keep closed ResultSets unreadable and preserve cleanup errors.
- Apply DataSource login timeout during connection/session establishment and restore the configured network read timeout afterward.
- Include client key-store and SSL protocol properties in driver metadata, with password values redacted.
- Localize the new JDBC errors and property descriptions in both locales and make affected test assertions locale-independent.
Verification:
- Passed Spotless with `mvn spotless:apply -P with-integration-tests -pl iotdb-client/jdbc,iotdb-client/service-rpc`.
- Passed clean English unit tests: **110 Service-RPC + 237 JDBC**, zero failures/skips.
- Passed clean `with-zh-locale` compilation of both affected modules and all **237 JDBC tests**, zero failures/skips. Surefire selected `org.apache.iotdb.jdbc.*Test` with `surefire.failIfNoSpecifiedTests=false` for the upstream module.
- Passed focused clean packaging of both modules. Verified the build version, manifest and JDBC service registration in both the thin and bundled JDBC JARs.
- Verified all 171 JDBC message keys and format placeholders match between English and Chinese; `git diff --check` passed. Clean test/package runs had task caching disabled.
Verification limits: the complete Chinese Service-RPC test run still fails two unchanged assertions that expect English messages: `DeepCopyRpcTransportFactoryTest#testIndependentMaxFrameSizeConfigurations` and `TElasticFramedTransportTest#testSingularSize`. The fresh-repository full-reactor compile attempt was blocked before compilation by remote Maven Central DNS resolution while loading Develocity. Full-reactor compilation and integration tests remain unverified; no claim is made that all CI checks have passed.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org