Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

client-v2: serializePrimitiveData rejects or silently corrupts String values for UInt64, UUID, Date and DateTime

未关闭
#3,132 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
databases

调研方向

从 client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java 中的 serializePrimitiveData 开始,跟踪 UInt64、UUID、日期和日期时间的辅助路径。验证现有的转换行为,以及 BinaryStreamUtils 中相关的 unsigned long 范围检查。完成的标准是:对于这些类型,String 值得到一致处理;无效的 UInt64 值会失败,而不是静默回绕;现有的 signed 或数值路径保持不变。

由索引模型根据 Issue 内容生成。

描述

area:data-type bug client-api-v2 jdbc-v2

Summary

SerializerUtils.serializePrimitiveData accepts String input for most scalar column types via the convertToInteger / convertToLong / convertToBigInteger / convertToBigDecimal / convertToString helpers, but a subset of types either reject a String outright or — for UInt64 — silently corrupt it. This makes String coercion inconsistent across the type switch.

Line references are against 0.9.5, file client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java.

Behaviour today

Column type String input Result
Int8/16/32, UInt8/16, Int64, UInt32 convertToInteger / convertToLong works
Int128/256, UInt128/256 convertToBigInteger works
Decimal* convertToBigDecimal works
String, FixedString convertToString works
UInt64 (:522) convertToLongLong.parseLong (:760) throws above 2^63-1; silently wraps a negative
UUID (:575) (UUID) value ClassCastException
Date, Date32 (:553, :556) writeDate / writeDate32 (:1105) IllegalArgumentException: Cannot convert … to Long
DateTime, DateTime64 (:559, :563) writeDateTime / writeDateTime64 (:1141) same
The UInt64 case is a silent-corruption bug
convertToLong("-1")      // -> -1L        (Long.parseLong, signed)
writeUnsignedInt64(-1L)  // -> writeInt64 -> FF FF FF FF FF FF FF FF

ClickHouse reads that back as 18446744073709551615. So a negative String is written as the maximum UInt64 with no error.

This is already inconsistent within the library: BinaryStreamUtils.writeUnsignedInt64(OutputStream, BigInteger) range-checks via ClickHouseChecker.between(value, TYPE_BIG_INTEGER, BigInteger.ZERO, U_INT64_MAX), so a BigInteger of -1 is correctly rejected. Only the String path wraps.

Values in [2^63, 2^64-1] are legal UInt64 values and are encodable on the wire (writeUnsignedInt64(long) just emits the raw 8 bytes), but unreachable through the String path.

Proposed fix

  1. UInt64 — use an unsigned-aware conversion at :522 rather than changing the shared convertToLong, which Int64 (:504) and UInt32 (:519) also use and which needs signed parsing:
/** UInt64 runs past Long.MAX_VALUE; the returned long carries the raw bit pattern. */
public static Long convertToUnsignedLong(Object value) {
    if (value instanceof String) {
        return Long.parseUnsignedLong((String) value);
    }
    return convertToLong(value);
}
  1. UUID — add a String branch using UUID.fromString.
  2. Date / Date32 / DateTime / DateTime64 — add a String branch in the writeDate / writeDate32 / writeDateTime / writeDateTime64 helpers, which already dispatch on LocalDate / ZonedDateTime / OffsetDateTime / Timestamp. Fixing them there also covers their other callers.
Backward compatibility

Items 2 and 3 are purely additive: those inputs throw today, so nothing that currently succeeds changes behaviour.

Item 1 has one deliberate behaviour change: "-1" into a UInt64 column currently writes 18446744073709551615 and would now throw NumberFormatException. That replaces silent corruption with a loud error and aligns the String path with the existing BigInteger overload. Suggest keeping it as its own commit so it can be reviewed separately from the additive branches.

The Long / Number path stays permissive and passes raw bits through unchanged — callers legitimately supply the bit pattern for values above 2^63.

Why it matters

Reported from the ClickHouse Flink connector. Its checkpoint state format serialises map keys as strings, so for a Map(K, V) column the key reaches serializeMapData (:478) → serializePrimitiveData as a String. The connector currently has to reject Map(UInt64, …), Map(UUID, …), Map(Date, …), Map(Date32, …) and Map(DateTime(64), …) at planning time and tell users to change their table DDL, even though all of these are legal ClickHouse map key types.

More generally, any caller passing a String value for one of these types — nested or top-level — hits the same behaviour.

主要语言
Java
星标
1.6k
派生
637
平均合并
2 天 16 小时
30 天内合并 PR
30

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ClickHouse/clickhouse-java 的其他 Issue

查看 ClickHouse/clickhouse-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。