@@ -42,6 +42,8 @@ abstract class HashTest {
42
42
private static final String EMPTY_FIELD_VALUE = "" ;
43
43
private static final String NON_EMPTY_FIELD_VALUE = "jerry@all_your_bases.com" ;
44
44
private static final String DEFAULT_HASH_FUNCTION = HashConfig .HashFunction .SHA256 .toString ();
45
+ private static final String UNAFFECTED_FIELD = "name" ;
46
+ private static final String UNAFFECTED_FIELD_VALUE = "jerry" ;
45
47
46
48
@ Test
47
49
void noFieldName_NullValue_NoSkip () {
@@ -132,8 +134,12 @@ void fieldName_MissingValue_NoSkip() {
132
134
void fieldName_NullValue_Skip () {
133
135
final Schema schema = SchemaBuilder .struct ()
134
136
.field (FIELD , SchemaBuilder .OPTIONAL_STRING_SCHEMA )
137
+ .field (UNAFFECTED_FIELD , SchemaBuilder .STRING_SCHEMA )
135
138
.schema ();
136
- final SinkRecord originalRecord = record (schema , new Struct (schema ).put (FIELD , null ));
139
+ final Struct originalStruct = new Struct (schema )
140
+ .put (FIELD , null )
141
+ .put (UNAFFECTED_FIELD , UNAFFECTED_FIELD_VALUE );
142
+ final SinkRecord originalRecord = record (schema , originalStruct );
137
143
final Hash <SinkRecord > transform = transformation (FIELD , true , DEFAULT_HASH_FUNCTION );
138
144
final SinkRecord result = transform .apply (originalRecord );
139
145
// No changes.
@@ -193,11 +199,17 @@ void fieldName_UnsupportedTypeInField() {
193
199
void fieldName_NormalStringValue (final String hashFunction ) {
194
200
final Schema schema = SchemaBuilder .struct ()
195
201
.field (FIELD , SchemaBuilder .STRING_SCHEMA )
202
+ .field (UNAFFECTED_FIELD , SchemaBuilder .STRING_SCHEMA )
196
203
.schema ();
197
- final SinkRecord originalRecord = record (schema , new Struct (schema ).put (FIELD , NON_EMPTY_FIELD_VALUE ));
204
+ final Struct originalStruct = new Struct (schema )
205
+ .put (FIELD , NON_EMPTY_FIELD_VALUE )
206
+ .put (UNAFFECTED_FIELD , UNAFFECTED_FIELD_VALUE );
207
+ final SinkRecord originalRecord = record (schema , originalStruct );
198
208
final Hash <SinkRecord > transform = transformation (FIELD , true , hashFunction );
199
209
final SinkRecord result = transform .apply (originalRecord );
200
- final String newValue = hash (hashFunction , NON_EMPTY_FIELD_VALUE );
210
+ final Struct newValue = new Struct (schema )
211
+ .put (FIELD , hash (hashFunction , NON_EMPTY_FIELD_VALUE ))
212
+ .put (UNAFFECTED_FIELD , UNAFFECTED_FIELD_VALUE );
201
213
assertEquals (setNewValue (originalRecord , newValue ), result );
202
214
}
203
215
@@ -206,11 +218,17 @@ void fieldName_NormalStringValue(final String hashFunction) {
206
218
void fieldName_EmptyStringValue (final String hashFunction ) {
207
219
final Schema schema = SchemaBuilder .struct ()
208
220
.field (FIELD , SchemaBuilder .STRING_SCHEMA )
221
+ .field (UNAFFECTED_FIELD , SchemaBuilder .STRING_SCHEMA )
209
222
.schema ();
210
- final SinkRecord originalRecord = record (schema , new Struct (schema ).put (FIELD , EMPTY_FIELD_VALUE ));
223
+ final Struct originalStruct = new Struct (schema )
224
+ .put (FIELD , EMPTY_FIELD_VALUE )
225
+ .put (UNAFFECTED_FIELD , UNAFFECTED_FIELD_VALUE );
226
+ final SinkRecord originalRecord = record (schema , originalStruct );
211
227
final Hash <SinkRecord > transform = transformation (FIELD , true , hashFunction );
212
228
final SinkRecord result = transform .apply (originalRecord );
213
- final String newValue = hash (hashFunction , EMPTY_FIELD_VALUE );
229
+ final Struct newValue = new Struct (schema )
230
+ .put (FIELD , hash (hashFunction , EMPTY_FIELD_VALUE ))
231
+ .put (UNAFFECTED_FIELD , UNAFFECTED_FIELD_VALUE );
214
232
assertEquals (setNewValue (originalRecord , newValue ), result );
215
233
}
216
234
@@ -246,7 +264,7 @@ protected SinkRecord record(final Schema keySchema,
246
264
456L , TimestampType .CREATE_TIME );
247
265
}
248
266
249
- private SinkRecord setNewValue (final SinkRecord record , final String newValue ) {
267
+ private SinkRecord setNewValue (final SinkRecord record , final Object newValue ) {
250
268
return record .newRecord (record .topic (),
251
269
record .kafkaPartition (),
252
270
record .keySchema (),
0 commit comments