Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented getColumnClassName #2113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

livk-cloud
Copy link

Implement the getColumnClassName method to accommodate Spring Jdbc and Mybatis

@CLAassistant
Copy link

CLAassistant commented Jan 25, 2025

CLA assistant check
All committers have signed the CLA.

@livk-cloud
Copy link
Author

#2112

@chernser
Copy link
Contributor

@livk-cloud the build failed:

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project jdbc-v2: Compilation failure: Compilation failure: 
Error:  /home/runner/work/clickhouse-java/clickhouse-java/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaData.java:[7,27] cannot find symbol
Error:    symbol:   class JdbcTypeMapping
Error:    location: package com.clickhouse.jdbc
Error:  /home/runner/work/clickhouse-java/clickhouse-java/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaData.java:[169,9] cannot find symbol
Error:    symbol:   class JdbcTypeMapping
Error:    location: class com.clickhouse.jdbc.metadata.ResultSetMetaData
Error:  /home/runner/work/clickhouse-java/clickhouse-java/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaData.java:[169,35] cannot find symbol
Error:    symbol:   variable JdbcTypeMapping
Error:    location: class com.clickhouse.jdbc.metadata.ResultSetMetaData
Error:  /home/runner/work/clickhouse-java/clickhouse-java/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/ResultSetMetaData.java:[170,63] cannot find symbol
Error:    symbol:   variable Map
Error:    location: class com.clickhouse.jdbc.metadata.ResultSetMetaData
Error:  -> [Help 1]
Error:  

@livk-cloud
Copy link
Author

@chernser Hey, bro。I've tried to fix the above and remove the API introduced in JDK9,Thanks for the review

@mshustov mshustov requested review from mzitnik and chernser January 26, 2025 09:19
case Enum16:
case IPv4:
case IPv6:
case JSON:
Copy link
Contributor

@chernser chernser Jan 27, 2025

Choose a reason for hiding this comment

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

JSON - it depends on query settings com.clickhouse.client.api.internal.ServerSettings#OUTPUT_FORMAT_BINARY_WRITE_JSON_AS_STRING.
Object - is deprecated. We should use OTHER .

break;
case Enum8:
case Enum16:
case IPv4:
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically IP addresses are stored as series of numbers, but we can return them either way. If we put VARCHAR for it - what will be Spring behavior?

typeName = "ARRAY";
break;
case Enum8:
case Enum16:
Copy link
Contributor

Choose a reason for hiding this comment

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

Enum s are SMALLINT as they are stored as int8, int16.
What will be Spring behavior in this case?

typeName = "VARCHAR";
break;
default:
typeName = "BINARY";
Copy link
Contributor

Choose a reason for hiding this comment

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

it cannot be BINARY by default. Is there options like VARIANT or OTHER?

}

@Override
public int toSqlType(ClickHouseColumn column, Map<String, Class<?>> typeMap) {
Copy link
Contributor

@chernser chernser Jan 27, 2025

Choose a reason for hiding this comment

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

we have this mapping already com.clickhouse.jdbc.internal.JdbcUtils#CLICKHOUSE_TO_SQL_TYPE_MAP

/**
* Inner class for static initialization.
*/
static final class InstanceHolder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need an instance holder? can we have just simple static block in JdbcTypeMapping class?
We are trying to have classes with some meaningful functions that can be reused in different places. Current class is private and just holds static values.

* @param sqlType generic SQL types defined in JDBC
* @return non-null ClickHouse data type
*/
protected ClickHouseDataType getDataType(int sqlType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we have this mapping in com.clickhouse.jdbc.internal.JdbcUtils#SQL_TYPE_TO_CLASS_MAP

*/
static final class InstanceHolder {
private static final JdbcTypeMapping defaultMapping = ClickHouseUtils
.getService(JdbcTypeMapping.class, JdbcTypeMapping::new);
Copy link
Contributor

Choose a reason for hiding this comment

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

who else will implement JdbcTypeMapping ?
Is there a glue code in application for that?

@chernser
Copy link
Contributor

There is good idea of customizable mappings. With different dialects and variety of tools should help.
But I think, it needs more work to fit it current JDBC implementation.

@livk-cloud
Copy link
Author

livk-cloud commented Jan 27, 2025

There is good idea of customizable mappings. With different dialects and variety of tools should help. But I think, it needs more work to fit it current JDBC implementation.

I'm coming up with a New Year's holiday in the coming days, and I probably don't have much time to code. Considering the multiple dialects, I think there should be a common interface that uses SPI for loading processing, what do you think about this?

@chernser
Copy link
Contributor

@livk-cloud I think we can do with simple properties. Besides not always it is possible to manipulate a service loader when only URL is available to setup.
What mapping should be returned for your case?

@livk-cloud
Copy link
Author

livk-cloud commented Feb 5, 2025

@livk-cloud I think we can do with simple properties. Besides not always it is possible to manipulate a service loader when only URL is available to setup. What mapping should be returned for your case?

After some trying, I found that the getColumnClassName method returns Null and works fine with these frameworks, what do you think?

@chernser
Copy link
Contributor

chernser commented Feb 5, 2025

Hi @livk-cloud !
I think we can just return null as a quick fix or just use com.clickhouse.jdbc.internal.JdbcUtils#CLICKHOUSE_TO_SQL_TYPE_MAP.
Current PR seems more complex for this problem.

@livk-cloud
Copy link
Author

@chernser Of course, the easiest way to do this is to return Null. But I don't know if this has a bad effect on other ORM frameworks

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.

3 participants