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

Function test_from_existing

datafusion/core/src/execution/session_state.rs:2434–2499  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2432
2433 #[test]
2434 fn test_from_existing() -> Result<()> {
2435 fn employee_batch() -> RecordBatch {
2436 let name: ArrayRef =
2437 Arc::new(StringArray::from_iter_values(["Andy", "Andrew"]));
2438 let age: ArrayRef = Arc::new(Int32Array::from(vec![11, 22]));
2439 RecordBatch::try_from_iter(vec![("name", name), ("age", age)]).unwrap()
2440 }
2441 let batch = employee_batch();
2442 let table = MemTable::try_new(batch.schema(), vec![vec![batch]])?;
2443
2444 let session_state = SessionStateBuilder::new()
2445 .with_catalog_list(Arc::new(MemoryCatalogProviderList::new()))
2446 .build();
2447 let table_ref = session_state.resolve_table_ref("employee").to_string();
2448 session_state
2449 .schema_for_ref(&table_ref)?
2450 .register_table("employee".to_string(), Arc::new(table))?;
2451
2452 let default_catalog = session_state
2453 .config
2454 .options()
2455 .catalog
2456 .default_catalog
2457 .clone();
2458 let default_schema = session_state
2459 .config
2460 .options()
2461 .catalog
2462 .default_schema
2463 .clone();
2464 let is_exist = session_state
2465 .catalog_list()
2466 .catalog(default_catalog.as_str())
2467 .unwrap()
2468 .schema(default_schema.as_str())
2469 .unwrap()
2470 .table_exist("employee");
2471 assert!(is_exist);
2472 let new_state = SessionStateBuilder::new_from_existing(session_state).build();
2473 assert!(
2474 new_state
2475 .catalog_list()
2476 .catalog(default_catalog.as_str())
2477 .unwrap()
2478 .schema(default_schema.as_str())
2479 .unwrap()
2480 .table_exist("employee")
2481 );
2482
2483 // if `with_create_default_catalog_and_schema` is disabled, the new one shouldn't create default catalog and schema
2484 let disable_create_default =
2485 SessionConfig::default().with_create_default_catalog_and_schema(false);
2486 let without_default_state = SessionStateBuilder::new()
2487 .with_config(disable_create_default)
2488 .build();
2489 assert!(
2490 without_default_state
2491 .catalog_list()

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
with_catalog_listMethod · 0.80
schema_for_refMethod · 0.80
catalog_listMethod · 0.80
employee_batchFunction · 0.70
schemaMethod · 0.45
buildMethod · 0.45
to_stringMethod · 0.45
resolve_table_refMethod · 0.45
register_tableMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…