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

[SPARK-17873][SQL] ALTER TABLE RENAME TO should allow users to specify database in destination table name(but have to be same as source table) #15434

Closed
wants to merge 2 commits into from

Conversation

cloud-fan
Copy link
Contributor

@cloud-fan cloud-fan commented Oct 11, 2016

What changes were proposed in this pull request?

Unlike Hive, in Spark SQL, ALTER TABLE RENAME TO cannot move a table from one database to another(e.g. ALTER TABLE db1.tbl RENAME TO db2.tbl2), and will report error if the database in source table and destination table is different. So in #14955 , we forbid users to specify database of destination table in ALTER TABLE RENAME TO, to be consistent with other database systems and also make it easier to rename tables in non-current database, e.g. users can write ALTER TABLE db1.tbl RENAME TO tbl2, instead of ALTER TABLE db1.tbl RENAME TO db1.tbl2.

However, this is a breaking change. Users may already have queries that specify database of destination table in ALTER TABLE RENAME TO.

This PR reverts most of #14955 , and simplify the usage of ALTER TABLE RENAME TO by making database of source table the default database of destination table, instead of current database, so that users can still write ALTER TABLE db1.tbl RENAME TO tbl2, which is consistent with other databases like MySQL, Postgres, etc.

How was this patch tested?

The added back tests and some new tests.

@cloud-fan
Copy link
Contributor Author

cc @yhuai @gatorsmile

@yhuai
Copy link
Contributor

yhuai commented Oct 11, 2016

Can you update the description to explain if ALTER TABLE db1.tbl RENAME TO db2.tbl2 is allowed (I guess it is not allowed)?

@SparkQA
Copy link

SparkQA commented Oct 11, 2016

Test build #66744 has finished for PR 15434 at commit 393dc65.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 12, 2016

Test build #66778 has finished for PR 15434 at commit 65c1885.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

val db = formatDatabaseName(oldName.database.getOrElse(currentDb))
newName.database.map(formatDatabaseName).foreach { newDb =>
Copy link
Member

Choose a reason for hiding this comment

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

If newName.database is empty, we should use the current database, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see PR description, we should use the database of source table, so that users can just write db.tbl1 RENAME TO tbl2. This is different from Hive, as we don't support move table from one database to another.

Copy link
Member

Choose a reason for hiding this comment

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

uh, I see. If this is by design, I do not have more questions. LGTM

@gatorsmile
Copy link
Member

gatorsmile commented Oct 12, 2016

Just FYI. Hive allows the following changes:

ALTER TABLE db1.tbl RENAME TO db2.tbl

@gatorsmile
Copy link
Member

LGTM

@gatorsmile
Copy link
Member

retest this please

@gatorsmile
Copy link
Member

cc @yhuai

@SparkQA
Copy link

SparkQA commented Oct 15, 2016

Test build #66990 has finished for PR 15434 at commit 65c1885.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor Author

retest this please

@SparkQA
Copy link

SparkQA commented Oct 19, 2016

Test build #67154 has finished for PR 15434 at commit 65c1885.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan cloud-fan changed the title [SPARK-17873][SQL] ALTER TABLE RENAME TO should allow users to specify database in destination table name [SPARK-17873][SQL] ALTER TABLE RENAME TO should allow users to specify database in destination table name(but have to be same as source table) Oct 19, 2016
@yhuai
Copy link
Contributor

yhuai commented Oct 19, 2016

LGTM. Merging to master.

@yhuai
Copy link
Contributor

yhuai commented Oct 19, 2016

Merged to master.

@asfgit asfgit closed this in 4329c5c Oct 19, 2016
robert3005 pushed a commit to palantir/spark that referenced this pull request Nov 1, 2016
…y database in destination table name(but have to be same as source table)

## What changes were proposed in this pull request?

Unlike Hive, in Spark SQL, ALTER TABLE RENAME TO cannot move a table from one database to another(e.g. `ALTER TABLE db1.tbl RENAME TO db2.tbl2`), and will report error if the database in source table and destination table is different. So in apache#14955 , we forbid users to specify database of destination table in ALTER TABLE RENAME TO, to be consistent with other database systems and also make it easier to rename tables in non-current database, e.g. users can write `ALTER TABLE db1.tbl RENAME TO tbl2`, instead of `ALTER TABLE db1.tbl RENAME TO db1.tbl2`.

However, this is a breaking change. Users may already have queries that specify database of destination table in ALTER TABLE RENAME TO.

This PR reverts most of apache#14955 , and simplify the usage of ALTER TABLE RENAME TO by making database of source table the default database of destination table, instead of current database, so that users can still write `ALTER TABLE db1.tbl RENAME TO tbl2`, which is consistent with other databases like MySQL, Postgres, etc.

## How was this patch tested?

The added back tests and some new tests.

Author: Wenchen Fan <[email protected]>

Closes apache#15434 from cloud-fan/revert.
uzadude pushed a commit to uzadude/spark that referenced this pull request Jan 27, 2017
…y database in destination table name(but have to be same as source table)

## What changes were proposed in this pull request?

Unlike Hive, in Spark SQL, ALTER TABLE RENAME TO cannot move a table from one database to another(e.g. `ALTER TABLE db1.tbl RENAME TO db2.tbl2`), and will report error if the database in source table and destination table is different. So in apache#14955 , we forbid users to specify database of destination table in ALTER TABLE RENAME TO, to be consistent with other database systems and also make it easier to rename tables in non-current database, e.g. users can write `ALTER TABLE db1.tbl RENAME TO tbl2`, instead of `ALTER TABLE db1.tbl RENAME TO db1.tbl2`.

However, this is a breaking change. Users may already have queries that specify database of destination table in ALTER TABLE RENAME TO.

This PR reverts most of apache#14955 , and simplify the usage of ALTER TABLE RENAME TO by making database of source table the default database of destination table, instead of current database, so that users can still write `ALTER TABLE db1.tbl RENAME TO tbl2`, which is consistent with other databases like MySQL, Postgres, etc.

## How was this patch tested?

The added back tests and some new tests.

Author: Wenchen Fan <[email protected]>

Closes apache#15434 from cloud-fan/revert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants