alamb commented on code in PR #11991:
URL: https://github.com/apache/datafusion/pull/11991#discussion_r1717546426
##########
datafusion/core/src/execution/session_state.rs:
##########
@@ -1841,4 +1859,68 @@ mod tests {
assert!(sql_to_expr(&state).is_err())
}
+
+ #[test]
+ fn test_from_existing() -> Result<()> {
+ fn employee_batch() -> RecordBatch {
+ let name: ArrayRef =
+ Arc::new(StringArray::from_iter_values(["Andy", "Andrew"]));
+ let age: ArrayRef = Arc::new(Int32Array::from(vec![11, 22]));
+ RecordBatch::try_from_iter(vec![("name", name), ("age",
age)]).unwrap()
+ }
+ let batch = employee_batch();
+ let table = MemTable::try_new(batch.schema(), vec![vec![batch]])?;
+
+ let session_state = SessionStateBuilder::new()
+ .with_catalog_list(Arc::new(MemoryCatalogProviderList::new()))
+ .build();
+ let table_ref =
session_state.resolve_table_ref("employee").to_string();
+ session_state
+ .schema_for_ref(&table_ref)?
+ .register_table("employee".to_string(), Arc::new(table))?;
+
+ let default_catalog = session_state
+ .config
+ .options()
+ .catalog
+ .default_catalog
+ .clone();
+ let default_schema = session_state
+ .config
+ .options()
+ .catalog
+ .default_schema
+ .clone();
+ let is_exist = session_state
+ .catalog_list()
+ .catalog(default_catalog.as_str())
+ .unwrap()
+ .schema(default_schema.as_str())
+ .unwrap()
+ .table_exist("employee");
+ assert!(is_exist);
+ let new_state =
SessionStateBuilder::new_from_existing(session_state).build();
+ assert!(new_state
+ .catalog_list()
+ .catalog(default_catalog.as_str())
+ .unwrap()
+ .schema(default_schema.as_str())
+ .unwrap()
+ .table_exist("employee"));
+
+ // if `with_create_default_catalog_and_schema` is disabled, the new
one shouldn't create default catalog and schema
Review Comment:
I ran this test locally without the code changes in this PR and the test
fails (as expected) thus verifying test coverage for the new code 👍
```
assertion failed:
new_state.catalog_list().catalog(default_catalog.as_str()).unwrap().schema(default_schema.as_str()).unwrap().table_exist("employee")
thread 'execution::session_state::tests::test_from_existing' panicked at
datafusion/core/src/execution/session_state.rs:1887:9:
assertion failed:
new_state.catalog_list().catalog(default_catalog.as_str()).unwrap().schema(default_schema.as_str()).unwrap().table_exist("employee")
stack backtrace:
0: rust_begin_unwind
at
/rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:652:5
1: core::panicking::panic_fmt
at
/rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:72:14
2: core::panicking::panic
at
/rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:146:5
3: datafusion::execution::session_state::tests::test_from_existing
at ./src/execution/session_state.rs:1887:9
4:
datafusion::execution::session_state::tests::test_from_existing::{{closure}}
at ./src/execution/session_state.rs:1848:32
5: core::ops::function::FnOnce::call_once
at
/rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/ops/function.rs:250:5
6: core::ops::function::FnOnce::call_once
at
/rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose
backtrace.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]