Skip to content

Commit fe86e71

Browse files
test: add coverage for parallel json reads
1 parent 39055d1 commit fe86e71

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

default-engine/src/json.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,50 @@ mod tests {
11291129
}
11301130
}
11311131

1132+
#[tokio::test(flavor = "multi_thread")]
1133+
async fn test_read_json_files_parallel_empty_files() {
1134+
let store = Arc::new(InMemory::new());
1135+
let handler = DefaultJsonHandler::new(
1136+
store,
1137+
Arc::new(TokioMultiThreadExecutor::new(
1138+
tokio::runtime::Handle::current(),
1139+
)),
1140+
)
1141+
.with_parallel_chunks(NonZero::new(4));
1142+
let physical_schema = schema_ref! { nullable "val": INTEGER };
1143+
let result: Vec<_> = handler
1144+
.read_json_files(&[], physical_schema, None)
1145+
.unwrap()
1146+
.try_collect()
1147+
.unwrap();
1148+
assert!(result.is_empty(), "empty file list must yield no batches");
1149+
}
1150+
1151+
#[tokio::test(flavor = "multi_thread")]
1152+
async fn test_read_json_files_parallel_missing_file_errors() {
1153+
let store = Arc::new(InMemory::new());
1154+
let missing_path = Path::from("test/missing");
1155+
let url = Url::parse(&format!("memory:/{missing_path}")).unwrap();
1156+
let files = vec![FileMeta {
1157+
location: url,
1158+
last_modified: 0,
1159+
size: 100,
1160+
}];
1161+
let handler = DefaultJsonHandler::new(
1162+
store,
1163+
Arc::new(TokioMultiThreadExecutor::new(
1164+
tokio::runtime::Handle::current(),
1165+
)),
1166+
)
1167+
.with_parallel_chunks(NonZero::new(4));
1168+
let physical_schema = schema_ref! { nullable "val": INTEGER };
1169+
let result: DeltaResult<Vec<_>> = handler
1170+
.read_json_files(&files, physical_schema, None)
1171+
.unwrap()
1172+
.try_collect();
1173+
assert!(result.is_err(), "missing file must produce an error");
1174+
}
1175+
11321176
// Helper function to create test data
11331177
fn create_test_data(values: Vec<&str>) -> DeltaResult<Box<dyn EngineData>> {
11341178
let schema = Arc::new(ArrowSchema::new(vec![Field::new(

default-engine/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ mod tests {
537537
.with_task_executor(executor)
538538
.with_buffer_size(NonZero::new(4).unwrap())
539539
.with_batch_size(NonZero::new(8).unwrap())
540+
.with_parallel_chunks(NonZero::new(4))
540541
.build();
541542
test_arrow_engine(&engine, &url);
542543
}

0 commit comments

Comments
 (0)