使用JDBC准备语句在ClickHouse中插入日期时发生java解析错误
我在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 console和query手动插入新行:
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, 1, null);
插入成功
在我的java代码中,我有:
private static final String INSERT_IDENTIFIERS = "INSERT INTO identifier (msisdn,time_stamp,user_id,imsi,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
是字符串类型。
而保存(…)执行后,我得到以下错误:
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, 'Europe/Moscow'), 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))
原因可能是什么
共 (0) 个答案