MCPcopy Create free account
hub / github.com/apache/datafusion / test_json_array_from_file

Function test_json_array_from_file

datafusion/datasource-json/src/source.rs:540–568  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

538
539 #[tokio::test]
540 async fn test_json_array_from_file() -> Result<()> {
541 // Test reading JSON array format from a file
542 let json_data = r#"[{"id": 1, "name": "alice"}, {"id": 2, "name": "bob"}]"#;
543
544 let store = Arc::new(InMemory::new());
545 let path = Path::from("test.json");
546 store
547 .put(&path, PutPayload::from_static(json_data.as_bytes()))
548 .await?;
549
550 let opener = JsonOpener::new(
551 1024,
552 test_schema(),
553 FileCompressionType::UNCOMPRESSED,
554 store.clone(),
555 false, // JSON array format
556 );
557
558 let meta = store.head(&path).await?;
559 let file = PartitionedFile::new(path.to_string(), meta.size);
560
561 let stream = opener.open(file)?.await?;
562 let batches: Vec<_> = stream.try_collect().await?;
563
564 assert_eq!(batches.len(), 1);
565 assert_eq!(batches[0].num_rows(), 2);
566
567 Ok(())
568 }
569
570 #[tokio::test]
571 async fn test_json_array_from_stream() -> Result<()> {

Callers

nothing calls this directly

Calls 6

newFunction · 0.85
test_schemaFunction · 0.70
putMethod · 0.45
cloneMethod · 0.45
to_stringMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…