twalthr commented on code in PR #258:
URL:
https://github.com/apache/flink-connector-kafka/pull/258#discussion_r3318449538
##########
flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/table/DynamicKafkaRecordSerializationSchema.java:
##########
@@ -285,4 +289,14 @@ private <T> T readMetadata(RowData consumedRow,
KafkaDynamicSink.WritableMetadat
}
return (T) metadata.converter.read(consumedRow, pos);
}
+
+ private static @Nullable List<Header> resolveHeaders(
+ @Nullable List<Header> mapHeaders, @Nullable List<Header>
arrayHeaders) {
+ if (mapHeaders != null && arrayHeaders != null) {
+ throw new IllegalStateException(
Review Comment:
Is this really a problem? Can't we simplify the logic and allow this? One
problem less to care about.
##########
flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicSink.java:
##########
@@ -457,6 +465,47 @@ public Object read(RowData row, int pos) {
}
}),
+ /**
+ * Wire-faithful alternative to {@code headers}: preserves duplicate
keys and insertion
+ * order using {@code ARRAY<ROW<key STRING, value BYTES>>} instead of
a lossy MAP.
+ */
+ MULTI_HEADERS(
+ "multi-headers",
+ DataTypes.ARRAY(
+ DataTypes.ROW(
+ DataTypes.FIELD(
+ "key",
DataTypes.STRING().nullable()),
+ DataTypes.FIELD(
+ "value",
DataTypes.BYTES().nullable()))
+ .notNull())
+ .nullable(),
+ new MetadataConverter() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Object read(RowData row, int pos) {
+ if (row.isNullAt(pos)) {
+ return null;
+ }
+ final ArrayData arrayData = row.getArray(pos);
+ final List<Header> headers = new ArrayList<>();
+ for (int i = 0; i < arrayData.size(); i++) {
+ if (!arrayData.isNullAt(i)) {
+ final RowData headerRow = arrayData.getRow(i,
2);
+ if (headerRow.isNullAt(0)) {
+ throw new IllegalArgumentException(
+ "Null header keys are not
permitted.");
+ }
+ final String name =
headerRow.getString(0).toString();
Review Comment:
We should mention here that we assume UTF-8 bytes and accept problems around:
https://cwiki.apache.org/confluence/display/FLINK/FLIP-568%3A+Strict+BYTES-to-STRING+CAST+with+UTF-8+Validation+Utilities
We don't intend to switch to StringData.fromUtf8Bytes as this would
potentially block processing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]