微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 JDBC 准备好的语句在 ClickHouse 中插入日期时解析错误

如何解决使用 JDBC 准备好的语句在 ClickHouse 中插入日期时解析错误

我在 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 举报,一经查实,本站将立刻删除。