[jdbc-v2] Fix NPE in ResultSetMetaDataImpl#getColumnClassName#2390
[jdbc-v2] Fix NPE in ResultSetMetaDataImpl#getColumnClassName#2390chernser merged 1 commit intoClickHouse:mainfrom CCweixiao:dev-0.8.6
Conversation
|
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. |
There was a problem hiding this comment.
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
getColumnClassNameto explicitly handle missing type mappings - Added
testGetColumnTypeMapin metadata tests to verify bothgetColumnTypeandgetColumnClassNamefor 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
testGetColumnTypeMapimplies testing only the column type; consider renaming totestGetColumnTypeAndClassNameForMapto 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());
| 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()); |
There was a problem hiding this comment.
Consider using try-with-resources for ResultSet to ensure it’s closed explicitly, e.g., try (ResultSet rs = stmt.executeQuery(...)).
| 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()); | |
| } |
|
@CCweixiao thank you for the contribution ! Tests are failing with latest CH version. Would you please take a look? : |
|
@CCweixiao would you please sign CLA? Thanks! |
|
在ClickHouseDataType中未定义Time64,跟本次PR解决的问题不是一个,需要提新的PR,这个PR可以先帮忙合并? |
|
@CCweixiao I see. thank you for looking into it. |
#2388