Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for external tables with qualified names #12645

Merged
merged 9 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions datafusion/core/src/catalog_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ pub fn resolve_table_references(
let _ = s.as_ref().visit(visitor);
}
DFStatement::CreateExternalTable(table) => {
visitor
.relations
.insert(ObjectName(vec![Ident::from(table.name.as_str())]));
let idents: Vec<Ident> = table.name.split('.').map(Ident::from).collect();
OussamaSaoudi marked this conversation as resolved.
Show resolved Hide resolved
visitor.relations.insert(ObjectName(idents));
}
DFStatement::CopyTo(CopyToStatement { source, .. }) => match source {
CopyToSource::Relation(table_name) => {
Expand Down
8 changes: 5 additions & 3 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::parser::{
LexOrdering, Statement as DFStatement,
};
use crate::planner::{
object_name_to_qualifier, ContextProvider, PlannerContext, SqlToRel,
object_name_to_qualifier, object_name_to_table_reference, ContextProvider,
PlannerContext, SqlToRel,
};
use crate::utils::normalize_ident;

Expand Down Expand Up @@ -1239,8 +1240,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let ordered_exprs =
self.build_order_by(order_exprs, &df_schema, &mut planner_context)?;

// External tables do not support schemas at the moment, so the name is just a table name
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

let name = TableReference::bare(name);
let idents: Vec<Ident> = name.split('.').map(Ident::from).collect();
let name = object_name_to_table_reference(ObjectName(idents), false)
.unwrap_or(TableReference::bare(name));
OussamaSaoudi marked this conversation as resolved.
Show resolved Hide resolved
let constraints =
Constraints::new_from_table_constraints(&all_constraints, &df_schema)?;
Ok(LogicalPlan::Ddl(DdlStatement::CreateExternalTable(
Expand Down