-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Kafka Connect: Precompute UUID-as-bytes flag in RecordConverter #16654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,11 +95,19 @@ class RecordConverter { | |
| private final NameMapping nameMapping; | ||
| private final IcebergSinkConfig config; | ||
| private final Map<Integer, Map<String, NestedField>> structNameMap = Maps.newHashMap(); | ||
| // Parquet stores UUIDs as a 16-byte fixed; other formats keep the UUID logical type. The write | ||
| // file format is fixed for the converter's lifetime, so resolve this once instead of per value. | ||
| private final boolean writeUuidAsBytes; | ||
|
|
||
| RecordConverter(Table table, IcebergSinkConfig config) { | ||
| this.tableSchema = table.schema(); | ||
| this.nameMapping = createNameMapping(table); | ||
| this.config = config; | ||
| this.writeUuidAsBytes = | ||
| FileFormat.PARQUET | ||
| .name() | ||
| .toLowerCase(Locale.ROOT) | ||
| .equals(config.writeProps().get(TableProperties.DEFAULT_FILE_FORMAT)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing, but since it moved into new code: the comparison is case-sensitive on the property value, so a user who sets
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| Record convert(Object data) { | ||
|
|
@@ -420,10 +428,7 @@ protected Object convertUUID(Object value) { | |
| throw new IllegalArgumentException("Cannot convert to UUID: " + value.getClass().getName()); | ||
| } | ||
|
|
||
| if (FileFormat.PARQUET | ||
| .name() | ||
| .toLowerCase(Locale.ROOT) | ||
| .equals(config.writeProps().get(TableProperties.DEFAULT_FILE_FORMAT))) { | ||
| if (writeUuidAsBytes) { | ||
| return UUIDUtil.convert(uuid); | ||
| } else { | ||
| return uuid; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading
config.writeProps()here means anyRecordConverterbuilt from a bareIcebergSinkConfigmock now NPEs at construction rather than lazily insideconvertUUID. That's arguably the healthier failure mode, and you've covered it with the@BeforeEachdefault — just worth a quick check that no other test in the module constructs a converter with an unstubbed config.It also freezes the value at construction, so a future test that constructs first and re-stubs
writeProps()afterward would silently skip the Parquet branch. Not a problem today, but the ordering constraint is now implicit — a one-line comment on the field would save someone a confusing debug session. wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test was at risk here.
IcebergWriter.initNewWriter()callsRecordUtils.createTableWriterbeforenew RecordConverter(...), and that already doestableProps.putAll(config.writeProps()).TestSinkWriterbuilds a realSinkWriterover a bare mock that never stubswriteProps()and passes on main, because Mockito returns an empty map rather than null forMap-returning methods.