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

fix: Alter table renames view successfully #2678

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions crates/datafusion_ext/src/planner/relation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ fn infer_func_for_file(path: &str) -> Result<OwnedTableReference> {
schema: "public".into(),
table: "read_parquet".into(),
},
"xlsx" => OwnedTableReference::Partial {
schema: "public".into(),
table: "read_excel".into(),
},
greyscaled marked this conversation as resolved.
Show resolved Hide resolved
"csv" => OwnedTableReference::Partial {
schema: "public".into(),
table: "read_csv".into(),
Expand All @@ -266,6 +262,10 @@ fn infer_func_for_file(path: &str) -> Result<OwnedTableReference> {
schema: "public".into(),
table: "read_bson".into(),
},
"xlsx" => OwnedTableReference::Partial {
schema: "public".into(),
table: "read_excel".into(),
},
ext => {
if let Ok(compression_type) = ext.parse::<FileCompressionType>() {
let ext = compression_type.get_ext();
Expand Down
20 changes: 9 additions & 11 deletions crates/metastore/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,19 +935,17 @@ impl State {
Some(id) => id,
};

let mut table = match self.entries.remove(&oid)?.unwrap() {
CatalogEntry::Table(ent) => ent,
other => unreachable!("unexpected entry type: {:?}", other),
};
let mut ent = self.entries.remove(&oid)?.unwrap();

// The entry must be a "table" or a "view".
assert!(
matches!(ent, CatalogEntry::Table(_) | CatalogEntry::View(_)),
"unexpected entry type: {ent:?}"
);

table.meta.name = new_name;
ent.get_meta_mut().name = new_name;

self.try_insert_table_namespace(
CatalogEntry::Table(table.clone()),
schema_id,
table.meta.id,
CreatePolicy::Create,
)?;
self.try_insert_table_namespace(ent, schema_id, oid, CreatePolicy::Create)?;
}
AlterTableOperation::SetAccessMode { access_mode } => {
let oid = match objs.tables.get(&alter_table.name) {
Expand Down
20 changes: 20 additions & 0 deletions testdata/sqllogictests/alter.slt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ alter table t1 rename to t2;
statement ok
drop table if exists t1, t2;

# Tests alter views (with the same syntax as tables)

statement ok
create view v1 as values (1), (2);

statement ok
alter table v1 rename to v2;

statement error Missing database object
alter table v1 rename to v2;

statement ok
create view v1 as values (3), (4);

statement error Duplicate name
alter table v1 rename to v2;

statement ok
drop view if exists v1, v2;

# Tests alter database

statement ok
Expand Down
Loading