Skip to content

GH-1478: Don't split surrogate pairs between ClobConsumer chunks - #1480

Merged
jbonofre merged 1 commit into
apache:mainfrom
jbonofre:clob-consumer-surrogate-pairs
Nov 16, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
jbonofre:clob-consumer-surrogate-pairs

Conversation

@jbonofre

Copy link
Copy Markdown
Member

What's Changed

Follow-up to #1231. ClobConsumer reads a CLOB in chunks of 256 characters and encodes each chunk to UTF-8 on its own, so a character outside the BMP split between two chunks was encoded as ??.

  • A chunk that ends with a high surrogate, while characters remain, now leaves it for the next chunk, so the pair is encoded together.
  • The read position advances by the length of the chunk instead of the requested size. The shorter chunk needs this, and it also stops skipping characters when a driver returns fewer than requested.
  • An empty chunk before the end of the CLOB throws an SQLException instead of looping forever.

ClobConsumerTest covers emojis across chunk boundaries for both consumers. The test fails without the fix: 255 a followed by 😀 read back as 257 bytes instead of 259.

This changes other lines of ClobConsumer than #1479, and the two branches merge cleanly.

Closes #1478.

@jbonofre jbonofre added the bug-fix PRs that fix a big. label Nov 15, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Nov 15, 2026

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needs to be formatted.

Each chunk of a CLOB is encoded to UTF-8 on its own, so a character
outside the BMP split between two chunks was encoded as "??". A chunk
that ends with a high surrogate now leaves it for the next chunk, and the
read position advances by the characters actually read.
@jbonofre
jbonofre force-pushed the clob-consumer-surrogate-pairs branch from 2175f46 to cf48f34 Compare November 16, 2026 04:19
@jbonofre
jbonofre merged commit f8ec4be into apache:main Nov 16, 2026
21 checks passed
@jbonofre
jbonofre deleted the clob-consumer-surrogate-pairs branch November 16, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClobConsumer replaces characters split across 256-character chunks with '??'

2 participants