Skip to content

Commit

Permalink
Derive Eq, Hash, Ord for ResolvedTableReference to be capable of map …
Browse files Browse the repository at this point in the history
…key (apache#13303)

Resolves apache#13300.
  • Loading branch information
kezhuw authored and askalt committed Nov 19, 2024
1 parent 2199b58 commit d53f727
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion datafusion/common/src/table_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::utils::{parse_identifiers_normalized, quote_identifier};
use std::sync::Arc;

/// A fully resolved path to a table of the form "catalog.schema.table"
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ResolvedTableReference {
/// The catalog (aka database) containing the table
pub catalog: Arc<str>,
Expand Down
9 changes: 5 additions & 4 deletions datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,9 @@ impl SessionState {
};

for reference in references {
let resolved = &self.resolve_table_ref(reference);
if let Entry::Vacant(v) = provider.tables.entry(resolved.to_string()) {
let resolved = self.resolve_table_ref(reference);
if let Entry::Vacant(v) = provider.tables.entry(resolved) {
let resolved = v.key();
if let Ok(schema) = self.schema_for_ref(resolved.clone()) {
if let Some(table) = schema.table(&resolved.table).await? {
v.insert(provider_as_source(table));
Expand Down Expand Up @@ -1515,7 +1516,7 @@ impl From<SessionState> for SessionStateBuilder {
/// having a direct dependency on the [`SessionState`] struct (and core crate)
struct SessionContextProvider<'a> {
state: &'a SessionState,
tables: HashMap<String, Arc<dyn TableSource>>,
tables: HashMap<ResolvedTableReference, Arc<dyn TableSource>>,
}

impl<'a> ContextProvider for SessionContextProvider<'a> {
Expand All @@ -1527,7 +1528,7 @@ impl<'a> ContextProvider for SessionContextProvider<'a> {
&self,
name: TableReference,
) -> datafusion_common::Result<Arc<dyn TableSource>> {
let name = self.state.resolve_table_ref(name).to_string();
let name = self.state.resolve_table_ref(name);
self.tables
.get(&name)
.cloned()
Expand Down

0 comments on commit d53f727

Please sign in to comment.