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

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String #488

Closed
terriblegirl opened this issue May 11, 2020 · 7 comments

Comments

@terriblegirl
Copy link

terriblegirl commented May 11, 2020

**Waterdrop Version(waterdrop-1.4.3)

A clear version of Waterdrop.

**Spark Version(spark-2.4.5-bin-hadoop2.7)

A clear version of Spark.

**Java Version(1.8.0_242)

A clear version of Java.

Waterdrop Config(Waterdrop配置文件)

Please delete sensitive information(请注意删除敏感信息)

spark {
  spark.app.name = "Waterdrop"
  spark.executor.instances = 2
  spark.executor.cores = 1
  spark.executor.memory = "1g"
  spark.sql.catalogImplementation = "hive"
}
input {
    hive {
        pre_sql = "select * from cc_dw.t_dim_city"
        table_name = "cms_msg"
    }

}
filter {
remove {
        source_field = ["weather_code"]
    }
  }

output {
    clickhouse {
        host = "IP:8123"
        database = "waterdrop"
        table = "t_dim_city"
        fields = ["city_name", "pinyin", "city_code", "area_code", "start_date"]
        username = ""
        password = ""
    }
}

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.
ISSUE:在从hive到clickhouse的过程中,报错如下:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

截图:
image

hive的建表情况
image
clickhouse的建表情况
image

猜测是数据类型不匹配的问题,但是string已经是最宽泛的一种数据类型了,为什么还会报这种错误?

@RickyHuo
Copy link
Contributor

从Hive里读取的数据是 int,在Waterdrop里面不会对数据类型进行转化,导致写String类型的ClickHouse字段异常。

写入ClickHouse的时候,需要字段类型严格匹配,不匹配的需要进行数据转换,数据转换可以通过

  1. Convert插件
  2. Sql插件

详细的数据类型参考:https://interestinglab.github.io/waterdrop-docs/#/zh-cn/v1/configuration/output-plugins/Clickhouse?id=clickhouse%e7%b1%bb%e5%9e%8b%e5%af%b9%e7%85%a7%e8%a1%a8

@terriblegirl
Copy link
Author

image
我在clickhouse中创建的表的数据类型是这样的,start_date设置了date类型,但是在倒数据的时候还是报一个这样的错误
(TID 0, localhost, executor driver): java.lang.ClassCastException: java.sql.Date cannot be cast to java.lang.String
image
这样就很奇怪了,我明明是date类型 为啥还是会出现不能转成String类型呢?

@RickyHuo
Copy link
Contributor

这是因为Waterdrop封装的时候Date 和 DateTime 格式都必要转成字符串才可以写入。上述链接也有说明的。

@terriblegirl
Copy link
Author

也就是说我要在从hive通过sql获取数据的时候就通过sql把date类型转换成string类型对么?

@RickyHuo
Copy link
Contributor

@terriblegirl 是的。

@terriblegirl
Copy link
Author

image
你好,这里的意思是我只有安装了这两个插件就不需要进行数据类型转换了,直接在配置文件中配置就可以了对么?如果是的话,请问这个插件的部署有相关文档以及demo吗?

@RickyHuo
Copy link
Contributor

我的意思是使用这两个插件进行数据转换, 插件的使用参考https://interestinglab.github.io/waterdrop-docs/#/zh-cn/v1/configuration/base 具体的文档即可。

@RickyHuo RickyHuo mentioned this issue Oct 23, 2020
Closed
ruanwenjun added a commit to ruanwenjun/incubator-seatunnel that referenced this issue Nov 6, 2023
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

2 participants