fix: cap VarCharType/VarBinaryType MAX_LENGTH at i32::MAX#339
Open
shyjsarah wants to merge 2 commits into
Open
fix: cap VarCharType/VarBinaryType MAX_LENGTH at i32::MAX#339shyjsarah wants to merge 2 commits into
shyjsarah wants to merge 2 commits into
Conversation
`isize::MAX as u32` overflows on 64-bit targets and produces
`u32::MAX = 4294967295`. The Display impl then serializes
`VarCharType::string_type()` as `VARCHAR(4294967295)`, which Java's
`DataTypeJsonParser` (used by Bennett to deserialize REST
`CreateTableRequest` payloads) rejects via `Integer.parseInt`:
Could not parse type at position N: ...
Input type string: VARCHAR(4294967295)
(through reference chain:
org.apache.paimon.rest.requests.CreateTableRequest["schema"]
->org.apache.paimon.schema.Schema["fields"]
->java.util.ArrayList[1])
The wire-format length cap is a protocol constant, not a function of
host pointer width. Pin both `MAX_LENGTH` constants to `i32::MAX`
(2147483647), matching Java `Integer.MAX_VALUE` exactly.
Java-to-Java traffic did not surface this bug because Java's
`asSQLString` short-circuits length==MAX to the bare `STRING` alias,
while paimon-rust's Display always writes the numeric form.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
VarBinaryType exposes `try_new(nullable, length)` (not `with_nullable`, which only exists on VarCharType). Use the right constructor so the new regression test compiles. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
When
paimon-rustis used as the REST client,CreateTableRequestpayloads carrying aSTRINGcolumn are rejected by the REST server with:Could not parse type at position N: ...
Input type string: VARCHAR(4294967295)
Root cause:
VarCharType::MAX_LENGTH(andVarBinaryType::MAX_LENGTH) were defined asisize::MAX as u32. On 64-bit targetsisize::MAX = 2^63 - 1, which truncates tou32::MAX = 4294967295when cast tou32.VarCharType::string_type()therefore produced aVarCharTypewhoseDisplayemitsVARCHAR(4294967295). The server-sideDataTypeJsonParsercallsInteger.parseInton the length token and throwsNumberFormatException, since the value exceeds Java'sInteger.MAX_VALUE(2147483647).Java↔Java traffic does not surface this because Java's
VarCharType.asSQLString()short-circuitslength == MAX_LENGTHto the bareSTRINGalias — only the Rust client wrote the numeric form, exposing the off-by-one against Java'sintrange.The wire-format length cap is a protocol constant, not a function of host pointer width. The fix pins both
MAX_LENGTHconstants toi32::MAX as u32 = 2147483647, exactly matching JavaInteger.MAX_VALUEon all targets (32-bit was already correct by coincidence; 64-bit was broken).Brief change log
crates/paimon/src/spec/types.rsVarCharType::MAX_LENGTH:isize::MAX as u32→i32::MAX as u32, with a comment recording why this must equal JavaInteger.MAX_VALUE.VarBinaryType::MAX_LENGTH: same change, same reason.test_max_length_fits_java_integerasserting:i32::MAX as u32.VarCharType::string_type().to_string()andVarBinaryTypeatMAX_LENGTHproduce length tokens that parse as Javai32.Tests
paimon::spec::types::tests::test_max_length_fits_java_integercovers the wire-format invariant.test_data_type_serialize,test_data_type_deserialize) continue to pass — none of the fixtures used the old overflow value, so no fixture updates were required.CreateTable→ server) on the reporter's side is the verification path; reviewers can synthesize the same payload by serializing a schema containingVarCharType::string_type()and round-tripping throughDataTypeJsonParser.API and Format
VarCharType::MAX_LENGTHandVarBinaryType::MAX_LENGTHarepub constvalues that are now smaller (2147483647instead of the truncated4294967295). Callers that constructed types via these constants will now produce shorter, interoperableVARCHAR(...)/VARBINARY(...)lengths.4294967295length would have produced data unreadable by any Java reader, so the prior behavior was effectively unusable cross-language. New writes match the Java canonical value. No migration is required for tables actually created by paimon-java.Documentation
None. Behavior change is invisible to users at the SQL/API surface; the fix only restores the documented "STRING ==
VarCharType.STRING_TYPE" semantics.