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

[Bug]: ClassCastException when deserializing date column #151

Closed
2 tasks done
qingfei1994 opened this issue Aug 20, 2024 · 1 comment
Closed
2 tasks done

[Bug]: ClassCastException when deserializing date column #151

qingfei1994 opened this issue Aug 20, 2024 · 1 comment

Comments

@qingfei1994
Copy link
Contributor

qingfei1994 commented Aug 20, 2024

What happened?

When I was running E2E test case reading a date column from clickhouse container, ClassCastException was thrown.

[docker-java-stream-107643741] INFO  org.apache.flink.connector.clickhouse.FlinkContainerTestEnviroment - STDOUT:         at org.apache.flink.connector.clickhouse.internal.converter.ClickHouseRowConverter.lambda$createToInternalConverter$f8d94b9$6(ClickHouseRowConverter.java:130)
[docker-java-stream-107643741] INFO  org.apache.flink.connector.clickhouse.FlinkContainerTestEnviroment - STDOUT:         at org.apache.flink.connector.clickhouse.internal.converter.ClickHouseRowConverter.toInternal(ClickHouseRowConverter.java:83)
 [docker-java-stream-107643741] INFO  org.apache.flink.connector.clickhouse.FlinkContainerTestEnviroment - STDOUT:         at org.apache.flink.connector.clickhouse.internal.ClickHouseBatchInputFormat.nextRecord(ClickHouseBatchInputFormat.java:135)

Affects Versions

master

What are you seeing the problem on?

No response

How to reproduce

running E2E case(ClickhouseE2ECase.java) with date column.

        sqlLines.add(
                "create table clickhouse_test (id int, name varchar,float32_column FLOAT,"
                        + "    date_column Date,\n"
                        + "    datetime_column TIMESTAMP(3),\n"
                        + "    array_column ARRAY<INT>) with ('connector' = 'clickhouse',\n"
                        + "  'url' = '"
                        + jdbcUrl
                        + "',\n"
                        + "  'table-name' = 'test',\n"
                        + "  'username'='test_username',\n"
                        + "  'password'='test_password'\n"
                        + ");");
        sqlLines.add(
                "create table test (id int, name varchar,float32_column FLOAT,\n"
                        + "date_column Date,\n"
                        + "    datetime_column TIMESTAMP(3),\n"
                        + "    array_column ARRAY<INT>) with ('connector' = 'clickhouse',\n"
                        + "  'url' = '"
                        + jdbcUrl
                        + "',\n"
                        + "  'table-name' = 'test_insert',\n"
                        + "  'username'='test_username',\n"
                        + "  'password'='test_password'\n"
                        + ");");
        sqlLines.add("insert into test select * from clickhouse_test;");
        submitSQLJob(
                sqlLines,
                SQL_CONNECTOR_CLICKHOUSE_JAR,
                CLICKHOUSE_JDBC_JAR,
                HTTPCORE_JAR,
                HTTPCLIENT_JAR,
                HTTPCLIENT_H2_JAR);

Relevant log output

No response

Anything else

I've figured out how to fix it.
In ClickHouseRowConverter.java
case DATE: return val -> (int) ((Date) val).toLocalDate().toEpochDay();

changed into

case DATE: return val -> (int) ((LocalDate)val).toEpochDay();

As val is already LocalDate type, no need to cast it to java.sql.Date.

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@qingfei1994
Copy link
Contributor Author

I just found out #145 already fix the issue. Will supplement a test case for date column then.

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

No branches or pull requests

1 participant