mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(sfn): support ItemReader InputType JSONL (#3602)
A Distributed Map could only read a JSON dataset: every other InputType failed the state with "not yet implemented". JSONL now reads one item per line, skipping blank lines, so a trailing newline is not an item. ReaderConfig.ItemsPointer stays JSON only, as on AWS, and MaxItems truncates a JSONL dataset the same way it truncates a JSON one.
This commit is contained in:
1 parent
fc5380418e
commit
ef341e1c01
3 files changed
+184
-7
No files matched your search
+148
@@ -950,6 +950,154 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
assertEquals("States.ItemReaderFailed", failure.jsonPath().getString("error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapWithS3JsonlItemReader_readsOneItemPerLine() throws Exception {
|
||||
createBucket("map-inputs-jsonl");
|
||||
putObject("map-inputs-jsonl", "workers.jsonl",
|
||||
"{\"workerId\":\"w1\"}\n{\"workerId\":\"w2\"}\n\n");
|
||||
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "ProcessWorkers",
|
||||
"States": {
|
||||
"ProcessWorkers": {
|
||||
"Type": "Map",
|
||||
"ItemReader": {
|
||||
"Resource": "arn:aws:states:::s3:getObject",
|
||||
"ReaderConfig": {
|
||||
"InputType": "JSONL"
|
||||
},
|
||||
"Parameters": {
|
||||
"Bucket": "map-inputs-jsonl",
|
||||
"Key": "workers.jsonl"
|
||||
}
|
||||
},
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {
|
||||
"Mode": "DISTRIBUTED",
|
||||
"ExecutionType": "STANDARD"
|
||||
},
|
||||
"StartAt": "PassItem",
|
||||
"States": {
|
||||
"PassItem": {
|
||||
"Type": "Pass",
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String smArn = createStateMachine("map-itemreader-s3-jsonl-test", definition);
|
||||
String execArn = startExecution(smArn, "{}");
|
||||
String output = waitForExecution(execArn);
|
||||
|
||||
assertTrue(output.contains("\"workerId\":\"w1\"") || output.contains("\"workerId\": \"w1\""));
|
||||
assertTrue(output.contains("\"workerId\":\"w2\"") || output.contains("\"workerId\": \"w2\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapWithS3JsonlItemReader_maxItemsLimitsDataset() throws Exception {
|
||||
createBucket("map-inputs-jsonl-max-items");
|
||||
putObject("map-inputs-jsonl-max-items", "workers.jsonl",
|
||||
"{\"workerId\":\"w1\"}\n{\"workerId\":\"w2\"}\n{\"workerId\":\"w3\"}\n");
|
||||
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "ProcessWorkers",
|
||||
"States": {
|
||||
"ProcessWorkers": {
|
||||
"Type": "Map",
|
||||
"ItemReader": {
|
||||
"Resource": "arn:aws:states:::s3:getObject",
|
||||
"ReaderConfig": {
|
||||
"InputType": "JSONL",
|
||||
"MaxItems": 2
|
||||
},
|
||||
"Parameters": {
|
||||
"Bucket": "map-inputs-jsonl-max-items",
|
||||
"Key": "workers.jsonl"
|
||||
}
|
||||
},
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {
|
||||
"Mode": "DISTRIBUTED",
|
||||
"ExecutionType": "STANDARD"
|
||||
},
|
||||
"StartAt": "PassItem",
|
||||
"States": {
|
||||
"PassItem": {
|
||||
"Type": "Pass",
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String smArn = createStateMachine("map-itemreader-s3-jsonl-max-items-test", definition);
|
||||
String execArn = startExecution(smArn, "{}");
|
||||
String output = waitForExecution(execArn);
|
||||
|
||||
assertTrue(output.contains("\"workerId\":\"w1\"") || output.contains("\"workerId\": \"w1\""));
|
||||
assertTrue(output.contains("\"workerId\":\"w2\"") || output.contains("\"workerId\": \"w2\""));
|
||||
assertFalse(output.contains("\"workerId\":\"w3\"") || output.contains("\"workerId\": \"w3\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapWithS3JsonlItemReader_malformedLineFailsWithItemReaderError() throws Exception {
|
||||
createBucket("map-inputs-jsonl-invalid");
|
||||
putObject("map-inputs-jsonl-invalid", "workers.jsonl", "{\"workerId\":\"w1\"}\nnot-json\n");
|
||||
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "ProcessWorkers",
|
||||
"States": {
|
||||
"ProcessWorkers": {
|
||||
"Type": "Map",
|
||||
"ItemReader": {
|
||||
"Resource": "arn:aws:states:::s3:getObject",
|
||||
"ReaderConfig": {
|
||||
"InputType": "JSONL"
|
||||
},
|
||||
"Parameters": {
|
||||
"Bucket": "map-inputs-jsonl-invalid",
|
||||
"Key": "workers.jsonl"
|
||||
}
|
||||
},
|
||||
"ItemProcessor": {
|
||||
"ProcessorConfig": {
|
||||
"Mode": "DISTRIBUTED",
|
||||
"ExecutionType": "STANDARD"
|
||||
},
|
||||
"StartAt": "PassItem",
|
||||
"States": {
|
||||
"PassItem": {
|
||||
"Type": "Pass",
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String smArn = createStateMachine("map-itemreader-s3-jsonl-invalid-test", definition);
|
||||
String execArn = startExecution(smArn, "{}");
|
||||
Response failure = waitForExecutionFailure(execArn);
|
||||
|
||||
assertEquals("FAILED", failure.jsonPath().getString("status"));
|
||||
assertEquals("States.ItemReaderFailed", failure.jsonPath().getString("error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void distributedMapWithItemBatcher_groupsItemsIntoBatchesOfMaxItemsPerBatch() throws Exception {
|
||||
String definition = """
|
||||
|
||||
Reference in new issue
Block a user