Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions rust/datafusion/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ impl ExecutionContext {
.insert(name.to_string(), provider.into());
}

/// Deregisters the named table.
///
/// Returns true if the table was successfully de-reregistered.
pub fn deregister_table(&mut self, name: &str) -> bool {
self.state
.lock()
.unwrap()
.datasources
.remove(&name.to_string())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you should be able to use remove(name) here?

.is_some()
}

/// Retrieves a DataFrame representing a table previously registered by calling the
/// register_table function.
///
Expand Down Expand Up @@ -723,6 +735,21 @@ mod tests {
Ok(())
}

#[tokio::test]
async fn register_deregister() -> Result<()> {
let tmp_dir = TempDir::new()?;
let partition_count = 4;
let mut ctx = create_ctx(&tmp_dir, partition_count)?;

let provider = test::create_table_dual();
ctx.register_table("dual", provider);

assert_eq!(ctx.deregister_table("dual"), true);
assert_eq!(ctx.deregister_table("dual"), false);
Comment on lines +747 to +748
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving this to a separate test? This way, if something fails, it is more obvious what caused the failure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that. I hadn't done it originally because there is a fair amount of boilerplate to setting up a data source, but I agree that it makes sense to test is separately.


Ok(())
}

#[tokio::test]
async fn parallel_query_with_filter() -> Result<()> {
let tmp_dir = TempDir::new()?;
Expand Down Expand Up @@ -1668,6 +1695,8 @@ mod tests {
assert_eq!(a.value(i) + b.value(i), sum.value(i));
}

ctx.deregister_table("t");

Ok(())
}

Expand Down