Skip to content

[jdbc-v2] Fix NPE in ResultSetMetaDataImpl#getColumnClassName#2390

Merged
chernser merged 1 commit intoClickHouse:mainfrom
CCweixiao:dev-0.8.6
May 28, 2025
Merged

[jdbc-v2] Fix NPE in ResultSetMetaDataImpl#getColumnClassName#2390
chernser merged 1 commit intoClickHouse:mainfrom
CCweixiao:dev-0.8.6

Conversation

@CCweixiao
Copy link
Copy Markdown

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


jielongping seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@mshustov mshustov requested review from chernser and Copilot May 27, 2025 11:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures getColumnClassName no longer throws an NPE for unmapped data types and adds a new test for MAP columns.

  • Expanded getColumnClassName to explicitly handle missing type mappings
  • Added testGetColumnTypeMap in metadata tests to verify both getColumnType and getColumnClassName for MAP types

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImpl.java Handle null from typeClassMap.get(...) instead of NPEing
jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java New test testGetColumnTypeMap for MAP column type and class
Comments suppressed due to low confidence (2)

jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java:80

  • [nitpick] The method name testGetColumnTypeMap implies testing only the column type; consider renaming to testGetColumnTypeAndClassNameForMap to reflect both assertions.
@Test

jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImpl.java:182

  • [nitpick] This manual null-check can be simplified by using Map#getOrDefault: Class<?> columnClassType = typeClassMap.getOrDefault(getColumn(column).getDataType(), Object.class); for more concise code.
Class<?> columnClassType = typeClassMap.get(getColumn(column).getDataType());

Comment on lines +84 to +87
ResultSet rs = stmt.executeQuery("select map('a', 1) as a");
ResultSetMetaData rsmd = rs.getMetaData();
assertEquals(rsmd.getColumnType(1), Types.JAVA_OBJECT);
assertEquals(rsmd.getColumnClassName(1), Object.class.getName());
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Consider using try-with-resources for ResultSet to ensure it’s closed explicitly, e.g., try (ResultSet rs = stmt.executeQuery(...)).

Suggested change
ResultSet rs = stmt.executeQuery("select map('a', 1) as a");
ResultSetMetaData rsmd = rs.getMetaData();
assertEquals(rsmd.getColumnType(1), Types.JAVA_OBJECT);
assertEquals(rsmd.getColumnClassName(1), Object.class.getName());
try (ResultSet rs = stmt.executeQuery("select map('a', 1) as a")) {
ResultSetMetaData rsmd = rs.getMetaData();
assertEquals(rsmd.getColumnType(1), Types.JAVA_OBJECT);
assertEquals(rsmd.getColumnClassName(1), Object.class.getName());
}

Copilot uses AI. Check for mistakes.
@chernser
Copy link
Copy Markdown
Contributor

@CCweixiao thank you for the contribution !

Tests are failing with latest CH version. Would you please take a look? :

Error:  Tests run: 157, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 14.33 s <<< FAILURE! -- in TestSuite
Error:  com.clickhouse.jdbc.metadata.DatabaseMetaDataTest.testGetTypeInfo -- Time elapsed: 0.033 s <<< FAILURE!
java.lang.IllegalArgumentException: Unknown data type: Time64
	at com.clickhouse.data.ClickHouseDataType.of(ClickHouseDataType.java:460)
	at com.clickhouse.jdbc.metadata.DatabaseMetaDataTest.testGetTypeInfo(DatabaseMetaDataTest.java:234)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:136)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:658)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:219)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:923)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:192)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:808)
	at org.testng.TestRunner.run(TestRunner.java:603)

@chernser
Copy link
Copy Markdown
Contributor

@CCweixiao would you please sign CLA? Thanks!

@CCweixiao
Copy link
Copy Markdown
Author

testGetTypeInfo
I will fix it

@CCweixiao
Copy link
Copy Markdown
Author

@CCweixiao thank you for the contribution !

Tests are failing with latest CH version. Would you please take a look? :

Error:  Tests run: 157, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 14.33 s <<< FAILURE! -- in TestSuite
Error:  com.clickhouse.jdbc.metadata.DatabaseMetaDataTest.testGetTypeInfo -- Time elapsed: 0.033 s <<< FAILURE!
java.lang.IllegalArgumentException: Unknown data type: Time64
	at com.clickhouse.data.ClickHouseDataType.of(ClickHouseDataType.java:460)
	at com.clickhouse.jdbc.metadata.DatabaseMetaDataTest.testGetTypeInfo(DatabaseMetaDataTest.java:234)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:136)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:658)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:219)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:923)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:192)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:808)
	at org.testng.TestRunner.run(TestRunner.java:603)

在ClickHouseDataType中未定义Time64,跟本次PR解决的问题不是一个,需要提新的PR,这个PR可以先帮忙合并?
If Time64 is not defined in ClickHouseDataType, it is not the same problem as this PR, and a new PR needs to be proposed, and this PR can help merge it first?

@chernser
Copy link
Copy Markdown
Contributor

@CCweixiao I see. thank you for looking into it.

@chernser chernser merged commit e7ad3cd into ClickHouse:main May 28, 2025
18 of 23 checks passed
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.

4 participants