Skip to content

Commit dee78cd

Browse files
authored
tests: update test results (#1116)
Signed-off-by: Louis Mandel <[email protected]>
1 parent 05ebec2 commit dee78cd

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
@SuppressWarnings("unchecked")
3+
public static Map<String, String> deserializeOffsetMap(String lastSourceOffset) throws IOException {
4+
Map<String, String> offsetMap;
5+
if (lastSourceOffset == null || lastSourceOffset.isEmpty()) {
6+
offsetMap = new HashMap<>();
7+
} else {
8+
offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class);
9+
}
10+
return offsetMap;
11+
}
12+
13+
The provided Java function `deserializeOffsetMap` is part of the StreamSets Data Collector (DC) codebase in the `stagesupport` package within the `com.../OffsetUtil.java` file. This function is designed to deserialize a JSON string containing offsets into a `Map<String, String>` object. Here's an explanation of its purpose and functionality:
14+
15+
1. **Purpose**: The primary goal of this method is to convert a JSON-formatted offset string (represented as `lastSourceOffset`) into a Java `Map` where keys are strings and values are also strings. This conversion allows for easier manipulation, storage, or further processing in the Data Collector application.
16+
17+
2. **Parameters**:
18+
- `lastSourceOffset`: A required parameter of type `String`, which is expected to contain JSON-formatted offset data.
19+
20+
3. **Return Type**: The method returns a `Map<String, String>`. This means it will return a map where each key and value are strings.
21+
22+
4. **Throws**:
23+
- `IOException`: In case the JSON string cannot be parsed due to an I/O error (e.g., network issues).
24+
25+
5. **Logic**:
26+
27+
- The method first checks if `lastSourceOffset` is null or empty (`if (lastSourceOffset == null || lastSourceOffset.isEmpty())`). If true, it initializes a new `HashMap<String, String>` called `offsetMap`.
28+
- Otherwise, the function uses Jackson's JSON mapper (`JSON_MAPPER`) to deserialize the input string into a `Map<String, String>`. This is done with `JSON_MAPPER.readValue(lastSourceOffset, Map.class)`.
29+
30+
- The deserialization process converts the JSON string into a Java map, where each key-value pair in the JSON will become an entry in the resulting map.
31+
32+
6. **Security Note**: `@SuppressWarnings("unchecked")` is used to suppress potential warnings about unchecked casts. This is because `JSON_MAPPER.readValue()` returns a `Map`, and there's no need for explicit type casting here, as Java's auto-boxing mechanism handles the conversion from JSON keys/values to `String`.
33+
34+
In summary, this function serves as an adapter between JSON offset data (in string format) and a standard Java map structure. It ensures that any provided offsets can be easily accessed or manipulated within the Data Collector application.
35+
36+
EVALUATION:
37+
The similarity (Levenshtein) between this answer and the ground truth is:
38+
0.1991833030852994

tests/test_examples_run.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
update_results: true
1+
update_results: false
22
check: []
33
skip:
44
- examples/demos/react.pdl

0 commit comments

Comments
 (0)