问题描述
我在 CH 中有以下表格:
(
msisdn UInt64,time_stamp DateTime64(3,'Europe/Moscow'),user_id UInt64,imsi String,iccid Nullable(UInt64)
)
engine = MergeTree()
PARTITION BY toYYYYMM(time_stamp)
ORDER BY (msisdn,time_stamp)
SETTINGS index_granularity = 8192;
如果我尝试使用带有查询的 intellij idea 控制台手动插入新行:
insert into raw_mobile_data.identifier (msisdn,time_stamp,user_id,imsi,iccid)
VALUES (1,parseDateTime64BestEffort('2021-04-02T17:22:32.999+03:00'),1,null);
插入成功!
在我的java代码中:
private static final String INSERT_IDENTIFIERS = "INSERT INTO identifier (msisdn,iccid) VALUES (:msisdn,parseDateTime64BestEffort(:time_stamp),:user_id,:imsi,:iccid)";
@Override
public Integer save(List<IdentifierDto> identifiers) {
if (CollectionUtils.isEmpty(identifiers)) {
log.info("identifiers list for insert is empty");
return 0;
}
int[] batchInsertResult = namedParameterJdbcTemplate.batchUpdate(INSERT_IDENTIFIERS,getParameteRSSource(identifiers));
return Arrays.stream(batchInsertResult).Boxed().mapToInt(it -> it).sum();
}
private sqlParameterSource[] getParameteRSSource(List<IdentifierDto> identifiers) {
return identifiers.stream()
.map(i -> {
return new MapsqlParameterSource()
.addValue("msisdn",i.getMsisdn())
.addValue("time_stamp",i.getTimestamp())
.addValue("user_id",i.getUserId())
.addValue("imsi",i.getimsi())
.addValue("iccid",i.geticcid());
})
.toArray(sqlParameterSource[]::new);
}
java对象timestamp
中的IdentifierDto
字段是String类型。
执行 save(...) 时,出现以下错误:
Caused by: ru.yandex.clickhouse.except.ClickHouseException: ClickHouse exception,code: 27,host: ХХ.ХХ.ХХ.ХХХ,port: 8123; Code: 27,e.displayText() = DB::Exception: Cannot parse input: expected '\t' before: '+03:00\t123\t19750666\t\\N\n': (at row 1)
Row 1:
Column 0,name: msisdn,type: UInt64,parsed text: "79160300666"
Column 1,name: time_stamp,type: DateTime64(3,parsed text: "2021-04-02T17:22:32.999"
ERROR: garbage after DateTime64(3,'Europe/Moscow'): "+03:00<TAB>123"
(version 20.11.4.13 (official build))
可能是什么原因?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)