Skip to content

Commit 731ff73

Browse files
authoredMar 18, 2025··
Kafka: Suppress warnings around java.util.Date usage / fix var names (#12561)
1 parent 8f6ebb5 commit 731ff73

File tree

2 files changed

+43
-41
lines changed

2 files changed

+43
-41
lines changed
 

‎kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/DebeziumTransform.java

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public R apply(R record) {
7272
}
7373
}
7474

75+
@SuppressWarnings("JavaUtilDate")
7576
private R applyWithSchema(R record) {
7677
Struct value = Requirements.requireStruct(record.value(), "Debezium transform");
7778

‎kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java

+42-41
Original file line numberDiff line numberDiff line change
@@ -53,65 +53,66 @@ public MongoDataConverter(ArrayEncoding arrayEncoding) {
5353
}
5454

5555
public Struct convertRecord(
56-
Entry<String, BsonValue> keyvalueforStruct, Schema schema, Struct struct) {
57-
convertFieldValue(keyvalueforStruct, struct, schema);
56+
Entry<String, BsonValue> keyValueForStruct, Schema schema, Struct struct) {
57+
convertFieldValue(keyValueForStruct, struct, schema);
5858
return struct;
5959
}
6060

61+
@SuppressWarnings("JavaUtilDate")
6162
public void convertFieldValue(
62-
Entry<String, BsonValue> keyvalueforStruct, Struct struct, Schema schema) {
63+
Entry<String, BsonValue> keyValueForStruct, Struct struct, Schema schema) {
6364
Object colValue = null;
6465

65-
String key = keyvalueforStruct.getKey();
66-
BsonType type = keyvalueforStruct.getValue().getBsonType();
66+
String key = keyValueForStruct.getKey();
67+
BsonType type = keyValueForStruct.getValue().getBsonType();
6768

6869
switch (type) {
6970
case NULL:
7071
colValue = null;
7172
break;
7273

7374
case STRING:
74-
colValue = keyvalueforStruct.getValue().asString().getValue().toString();
75+
colValue = keyValueForStruct.getValue().asString().getValue().toString();
7576
break;
7677

7778
case OBJECT_ID:
78-
colValue = keyvalueforStruct.getValue().asObjectId().getValue().toString();
79+
colValue = keyValueForStruct.getValue().asObjectId().getValue().toString();
7980
break;
8081

8182
case DOUBLE:
82-
colValue = keyvalueforStruct.getValue().asDouble().getValue();
83+
colValue = keyValueForStruct.getValue().asDouble().getValue();
8384
break;
8485

8586
case BINARY:
86-
colValue = keyvalueforStruct.getValue().asBinary().getData();
87+
colValue = keyValueForStruct.getValue().asBinary().getData();
8788
break;
8889

8990
case INT32:
90-
colValue = keyvalueforStruct.getValue().asInt32().getValue();
91+
colValue = keyValueForStruct.getValue().asInt32().getValue();
9192
break;
9293

9394
case INT64:
94-
colValue = keyvalueforStruct.getValue().asInt64().getValue();
95+
colValue = keyValueForStruct.getValue().asInt64().getValue();
9596
break;
9697

9798
case BOOLEAN:
98-
colValue = keyvalueforStruct.getValue().asBoolean().getValue();
99+
colValue = keyValueForStruct.getValue().asBoolean().getValue();
99100
break;
100101

101102
case DATE_TIME:
102-
colValue = new Date(keyvalueforStruct.getValue().asDateTime().getValue());
103+
colValue = new Date(keyValueForStruct.getValue().asDateTime().getValue());
103104
break;
104105

105106
case JAVASCRIPT:
106-
colValue = keyvalueforStruct.getValue().asJavaScript().getCode();
107+
colValue = keyValueForStruct.getValue().asJavaScript().getCode();
107108
break;
108109

109110
case JAVASCRIPT_WITH_SCOPE:
110111
Struct jsStruct = new Struct(schema.field(key).schema());
111112
Struct jsScopeStruct = new Struct(schema.field(key).schema().field("scope").schema());
112-
jsStruct.put("code", keyvalueforStruct.getValue().asJavaScriptWithScope().getCode());
113+
jsStruct.put("code", keyValueForStruct.getValue().asJavaScriptWithScope().getCode());
113114
BsonDocument jwsDoc =
114-
keyvalueforStruct.getValue().asJavaScriptWithScope().getScope().asDocument();
115+
keyValueForStruct.getValue().asJavaScriptWithScope().getScope().asDocument();
115116

116117
for (Entry<String, BsonValue> jwsDocKey : jwsDoc.entrySet()) {
117118
convertFieldValue(jwsDocKey, jsScopeStruct, schema.field(key).schema());
@@ -123,17 +124,17 @@ public void convertFieldValue(
123124

124125
case REGULAR_EXPRESSION:
125126
Struct regexStruct = new Struct(schema.field(key).schema());
126-
regexStruct.put("regex", keyvalueforStruct.getValue().asRegularExpression().getPattern());
127-
regexStruct.put("options", keyvalueforStruct.getValue().asRegularExpression().getOptions());
127+
regexStruct.put("regex", keyValueForStruct.getValue().asRegularExpression().getPattern());
128+
regexStruct.put("options", keyValueForStruct.getValue().asRegularExpression().getOptions());
128129
colValue = regexStruct;
129130
break;
130131

131132
case TIMESTAMP:
132-
colValue = new Date(1000L * keyvalueforStruct.getValue().asTimestamp().getTime());
133+
colValue = new Date(1000L * keyValueForStruct.getValue().asTimestamp().getTime());
133134
break;
134135

135136
case DECIMAL128:
136-
colValue = keyvalueforStruct.getValue().asDecimal128().getValue().toString();
137+
colValue = keyValueForStruct.getValue().asDecimal128().getValue().toString();
137138
break;
138139

139140
case DOCUMENT:
@@ -143,7 +144,7 @@ public void convertFieldValue(
143144
}
144145
Schema documentSchema = field.schema();
145146
Struct documentStruct = new Struct(documentSchema);
146-
BsonDocument docs = keyvalueforStruct.getValue().asDocument();
147+
BsonDocument docs = keyValueForStruct.getValue().asDocument();
147148

148149
for (Entry<String, BsonValue> doc : docs.entrySet()) {
149150
convertFieldValue(doc, documentStruct, documentSchema);
@@ -153,7 +154,7 @@ public void convertFieldValue(
153154
break;
154155

155156
case ARRAY:
156-
if (keyvalueforStruct.getValue().asArray().isEmpty()) {
157+
if (keyValueForStruct.getValue().asArray().isEmpty()) {
157158
switch (arrayEncoding) {
158159
case ARRAY:
159160
colValue = Lists.newArrayList();
@@ -166,8 +167,8 @@ public void convertFieldValue(
166167
} else {
167168
switch (arrayEncoding) {
168169
case ARRAY:
169-
BsonType valueType = keyvalueforStruct.getValue().asArray().get(0).getBsonType();
170-
List<BsonValue> arrValues = keyvalueforStruct.getValue().asArray().getValues();
170+
BsonType valueType = keyValueForStruct.getValue().asArray().get(0).getBsonType();
171+
List<BsonValue> arrValues = keyValueForStruct.getValue().asArray().getValues();
171172
List<Object> list = Lists.newArrayList();
172173

173174
arrValues.forEach(
@@ -183,7 +184,7 @@ public void convertFieldValue(
183184
colValue = list;
184185
break;
185186
case DOCUMENT:
186-
final BsonArray array = keyvalueforStruct.getValue().asArray();
187+
final BsonArray array = keyValueForStruct.getValue().asArray();
187188
final Map<String, BsonValue> convertedArray = Maps.newHashMap();
188189
final Schema arraySchema = schema.field(key).schema();
189190
final Struct arrayStruct = new Struct(arraySchema);
@@ -206,11 +207,11 @@ public void convertFieldValue(
206207
default:
207208
return;
208209
}
209-
struct.put(key, keyvalueforStruct.getValue().isNull() ? null : colValue);
210+
struct.put(key, keyValueForStruct.getValue().isNull() ? null : colValue);
210211
}
211212

212213
// TODO FIX Cyclomatic Complexity is 30 (max allowed is 12). [CyclomaticComplexity]
213-
@SuppressWarnings("checkstyle:CyclomaticComplexity")
214+
@SuppressWarnings({"checkstyle:CyclomaticComplexity", "JavaUtilDate"})
214215
private void convertFieldValue(
215216
Schema valueSchema, BsonType valueType, BsonValue arrValue, List<Object> list) {
216217
if (arrValue.getBsonType() == BsonType.STRING && valueType == BsonType.STRING) {
@@ -272,9 +273,9 @@ protected String arrayElementStructName(int index) {
272273
return "_" + index;
273274
}
274275

275-
public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBuilder builder) {
276-
String key = (String) keyValuesforSchema.getKey();
277-
BsonType type = keyValuesforSchema.getValue().getBsonType();
276+
public void addFieldSchema(Entry<String, BsonValue> keyValuesForSchema, SchemaBuilder builder) {
277+
String key = keyValuesForSchema.getKey();
278+
BsonType type = keyValuesForSchema.getValue().getBsonType();
278279

279280
switch (type) {
280281
case NULL:
@@ -311,19 +312,19 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
311312
break;
312313

313314
case JAVASCRIPT_WITH_SCOPE:
314-
SchemaBuilder jswithscope = SchemaBuilder.struct().name(builder.name() + "." + key);
315-
jswithscope.field("code", Schema.OPTIONAL_STRING_SCHEMA);
316-
SchemaBuilder scope = SchemaBuilder.struct().name(jswithscope.name() + ".scope").optional();
315+
SchemaBuilder jsWithScope = SchemaBuilder.struct().name(builder.name() + "." + key);
316+
jsWithScope.field("code", Schema.OPTIONAL_STRING_SCHEMA);
317+
SchemaBuilder scope = SchemaBuilder.struct().name(jsWithScope.name() + ".scope").optional();
317318
BsonDocument jwsDocument =
318-
keyValuesforSchema.getValue().asJavaScriptWithScope().getScope().asDocument();
319+
keyValuesForSchema.getValue().asJavaScriptWithScope().getScope().asDocument();
319320

320321
for (Entry<String, BsonValue> jwsDocumentKey : jwsDocument.entrySet()) {
321322
addFieldSchema(jwsDocumentKey, scope);
322323
}
323324

324325
Schema scopeBuild = scope.build();
325-
jswithscope.field("scope", scopeBuild).build();
326-
builder.field(key, jswithscope);
326+
jsWithScope.field("scope", scopeBuild).build();
327+
builder.field(key, jsWithScope);
327328
break;
328329

329330
case REGULAR_EXPRESSION:
@@ -336,7 +337,7 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
336337
case DOCUMENT:
337338
SchemaBuilder builderDoc =
338339
SchemaBuilder.struct().name(builder.name() + "." + key).optional();
339-
BsonDocument docs = keyValuesforSchema.getValue().asDocument();
340+
BsonDocument docs = keyValuesForSchema.getValue().asDocument();
340341

341342
for (Entry<String, BsonValue> doc : docs.entrySet()) {
342343
addFieldSchema(doc, builderDoc);
@@ -345,7 +346,7 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
345346
break;
346347

347348
case ARRAY:
348-
if (keyValuesforSchema.getValue().asArray().isEmpty()) {
349+
if (keyValuesForSchema.getValue().asArray().isEmpty()) {
349350
switch (arrayEncoding) {
350351
case ARRAY:
351352
builder.field(
@@ -359,17 +360,17 @@ public void addFieldSchema(Entry<String, BsonValue> keyValuesforSchema, SchemaBu
359360
} else {
360361
switch (arrayEncoding) {
361362
case ARRAY:
362-
BsonArray value = keyValuesforSchema.getValue().asArray();
363+
BsonArray value = keyValuesForSchema.getValue().asArray();
363364
BsonType valueType = value.get(0).getBsonType();
364-
testType(builder, key, keyValuesforSchema.getValue(), valueType);
365+
testType(builder, key, keyValuesForSchema.getValue(), valueType);
365366
builder.field(
366367
key,
367368
SchemaBuilder.array(subSchema(builder, key, valueType, value))
368369
.optional()
369370
.build());
370371
break;
371372
case DOCUMENT:
372-
final BsonArray array = keyValuesforSchema.getValue().asArray();
373+
final BsonArray array = keyValuesForSchema.getValue().asArray();
373374
final SchemaBuilder arrayStructBuilder =
374375
SchemaBuilder.struct().name(builder.name() + "." + key).optional();
375376
final Map<String, BsonValue> convertedArray = Maps.newHashMap();

0 commit comments

Comments
 (0)
Please sign in to comment.