Skip to content

Commit

Permalink
Retain boolean type from CLPLogRecordExtractor decoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackluo923 committed Nov 19, 2024
1 parent 07962b0 commit 91059cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public GenericRow extract(Map<String, Object> from, GenericRow to) {
return to;
}

/**
* In addition to the basic conversion, we also needs to retain the type info of Boolean input.
*/
@Override
protected Object convertSingleValue(Object value) {
if (value instanceof Boolean) {
return value;
}
return super.convertSingleValue(value);
}

/**
* Encodes a field with CLP
* <p></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class CLPLogRecordExtractorTest {
private static final int _TIMESTAMP_FIELD_VALUE = 10;
private static final String _LEVEL_FIELD_NAME = "level";
private static final String _LEVEL_FIELD_VALUE = "INFO";
private static final String _BOOLEAN_FIELD_NAME = "booleanField";
private static final boolean _BOOLEAN_FIELD_VALUE = true;
private static final String _MESSAGE_1_FIELD_NAME = "message1";
private static final String _MESSAGE_1_FIELD_VALUE = "Started job_123 on node-987: 4 cores, 8 threads and "
+ "51.4% memory used.";
Expand Down Expand Up @@ -105,6 +107,7 @@ public void testBadCLPEncodingConfig() {
row = extract(props, null);
assertEquals(row.getValue(_TIMESTAMP_FIELD_NAME), _TIMESTAMP_FIELD_VALUE);
assertEquals(row.getValue(_LEVEL_FIELD_NAME), _LEVEL_FIELD_VALUE);
assertEquals(row.getValue(_BOOLEAN_FIELD_NAME), _BOOLEAN_FIELD_VALUE);
validateClpEncodedField(row, _MESSAGE_1_FIELD_NAME, _MESSAGE_1_FIELD_VALUE);
validateClpEncodedField(row, _MESSAGE_2_FIELD_NAME, _MESSAGE_2_FIELD_VALUE);
}
Expand Down Expand Up @@ -153,6 +156,7 @@ private GenericRow extract(Map<String, String> props, Set<String> fieldsToRead)
record.put(_MESSAGE_1_FIELD_NAME, _MESSAGE_1_FIELD_VALUE);
record.put(_MESSAGE_2_FIELD_NAME, _MESSAGE_2_FIELD_VALUE);
record.put(_LEVEL_FIELD_NAME, _LEVEL_FIELD_VALUE);
record.put(_BOOLEAN_FIELD_NAME, _BOOLEAN_FIELD_VALUE);

GenericRow row = new GenericRow();
extractor.extract(record, row);
Expand Down

0 comments on commit 91059cd

Please sign in to comment.