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

Function test_sql_insert_into_fifo

datafusion/core/tests/fifo/mod.rs:329–410  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

327 /// It tests the INSERT INTO functionality.
328 #[tokio::test]
329 async fn test_sql_insert_into_fifo() -> Result<()> {
330 // To make unbounded deterministic
331 let waiting = Arc::new(AtomicBool::new(true));
332 let waiting_thread = waiting.clone();
333 // create local execution context
334 let config = SessionConfig::new().with_batch_size(TEST_BATCH_SIZE);
335 let ctx = SessionContext::new_with_config(config);
336 // Create a new temporary FIFO file
337 let tmp_dir = TempDir::new()?;
338 let source_fifo_path = create_fifo_file(&tmp_dir, "source.csv")?;
339 // Prevent move
340 let (source_fifo_path_thread, source_display_fifo_path) =
341 (source_fifo_path.clone(), source_fifo_path.display());
342 // Tasks
343 let mut tasks: Vec<JoinHandle<()>> = vec![];
344 tasks.push(create_writing_task(
345 source_fifo_path_thread,
346 "a1,a2\n".to_owned(),
347 (0..TEST_DATA_SIZE)
348 .map(|_| "a,1\n".to_string())
349 .collect::<Vec<_>>(),
350 waiting,
351 SEND_BEFORE_WAITING,
352 ));
353 // Create a new temporary FIFO file
354 let sink_fifo_path = create_fifo_file(&tmp_dir, "sink.csv")?;
355 // Prevent move
356 let (sink_fifo_path_thread, sink_display_fifo_path) =
357 (sink_fifo_path.clone(), sink_fifo_path.display());
358
359 // Spawn a new thread to read sink EXTERNAL TABLE.
360 #[expect(clippy::disallowed_methods)] // spawn allowed only in tests
361 tasks.push(spawn_blocking(move || {
362 let file = File::open(sink_fifo_path_thread).unwrap();
363 let schema = Arc::new(Schema::new(vec![
364 Field::new("a1", DataType::Utf8, false),
365 Field::new("a2", DataType::UInt32, false),
366 ]));
367
368 let mut reader = ReaderBuilder::new(schema)
369 .with_batch_size(TEST_BATCH_SIZE)
370 .with_header(true)
371 .build(file)
372 .unwrap();
373
374 while let Some(Ok(_)) = reader.next() {
375 waiting_thread.store(false, Ordering::SeqCst);
376 }
377 }));
378 // register second csv file with the SQL (create an empty file if not found)
379 ctx.sql(&format!(
380 "CREATE UNBOUNDED EXTERNAL TABLE source_table (
381 a1 VARCHAR NOT NULL,
382 a2 INT NOT NULL
383 )
384 STORED AS CSV
385 LOCATION '{source_display_fifo_path}'
386 OPTIONS ('format.has_header' 'true')"

Callers

nothing calls this directly

Calls 14

newFunction · 0.85
create_writing_taskFunction · 0.85
sqlMethod · 0.80
collectMethod · 0.80
create_fifo_fileFunction · 0.70
cloneMethod · 0.45
with_batch_sizeMethod · 0.45
displayMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45
to_stringMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…