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

CREATE TABLE LIKE Feature for Delta #1584

Closed
wants to merge 11 commits into from

Conversation

Dhruv-Shah9
Copy link
Contributor

Description

This PR aims to enable CREATE TABLE LIKE for Delta. CREATE TABLE LIKE is a SQL DDL that creates an empty new table using the definition and metadata of an existing table or view. CREATE TABLE LIKE is not supported for creating Delta tables. Currently, when a user tries to use CREATE TABLE LIKE with Delta, it throws an exception saying this command is not supported for Delta tables.

What changes were proposed in this pull request?

This PR aims to enable CREATE TABLE LIKE for Delta. CREATE TABLE LIKE is a SQL DDL that creates an empty new table using the definition and metadata of an existing table or view. CREATE TABLE LIKE is not supported for creating Delta tables. Currently, when a user tries to use CREATE TABLE LIKE with Delta, it throws an exception saying this command is not supported for Delta tables.

Specifically, the following table properties are being copied over:

Metadata Field/Type Non-Delta Tables Delta Tables
Description(Comment) Yes Yes
Schema Yes Yes
Partition Columns Yes Yes
Configuration Yes Yes
Delta Protocol No(Current Default Protocol for that spark session) Yes

How was this patch tested?

This patch is tested by adding unit tests for CREATE TABLE LIKE in the DeltaCreateTableLikeSuite.scala file. Other existing tests were modified to reflect the change that Delta Tables are now supported for the Create Table Like Command.

  - 7dac8ac0387c1295718ebce29b76f197f6e5b169 create table like feature for delta by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: 7dac8ac0387c1295718ebce29b76f197f6e5b169
@@ -53,14 +52,14 @@ case class CreateDeltaTableCommand(
query: Option[LogicalPlan],
operation: TableCreationModes.CreationMode = TableCreationModes.Create,
tableByPath: Boolean = false,
override val output: Seq[Attribute] = Nil)
override val output: Seq[Attribute] = Nil,
newProtocol: Option[Protocol] = None)
Copy link
Contributor

Choose a reason for hiding this comment

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

update the param docs!

/**
* This updates the protocol for the table to a set newProtocol
*/
def updateProtocol(newProtocolOption: Option[Protocol]): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont like this method signature. if someone is calling updateProtocol, then they must have a new protocol object. why would they pass on option? For example, updateMetadata just take metadata, not an option.

* This updates the protocol for the table to a set newProtocol
*/
def updateProtocol(newProtocolOption: Option[Protocol]): Unit = {
if (newProtocolOption != None) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am surprised that there were no existing protocol updating method in opttxn, and this DDL is the first one requiring it.

@xupefei could you double check this protocol upgrade path, since I dont if there is any complexity with regards to table features.

  - 0109e40334dbfaf9cae47aabe1b71d09c2d1f596 Fixed nits, updated param docs by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: 0109e40334dbfaf9cae47aabe1b71d09c2d1f596
  - 392d30a4b5caaef1c921b07ee1d4bbbbfb9cc7a3 fixed nits by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: 392d30a4b5caaef1c921b07ee1d4bbbbfb9cc7a3
  - 01783a8f3741182753f9be2489648d720df4a64e Fixed nits by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: 01783a8f3741182753f9be2489648d720df4a64e
  - abab591a6797e5f655a8401412e069e6913649d5 fixed nits by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: abab591a6797e5f655a8401412e069e6913649d5
  - b5bc6fe00ebdfe7980bb6459c4f489873f4bf543 Fixed nits by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: b5bc6fe00ebdfe7980bb6459c4f489873f4bf543
  - c76de8bfb3fb9b1d0a3c170db75350ef44976529 fixed nits by Dhruv-Shah9 <[email protected]>

GitOrigin-RevId: c76de8bfb3fb9b1d0a3c170db75350ef44976529
@nkarpov nkarpov closed this Feb 24, 2023
scottsand-db pushed a commit that referenced this pull request Feb 24, 2023
### Description
This PR aims to enable CREATE TABLE LIKE for Delta. CREATE TABLE LIKE is a SQL DDL that creates an empty new table using the definition and metadata of an existing table or view. CREATE TABLE LIKE is not supported for creating Delta tables. Currently, when a user tries to use CREATE TABLE LIKE with Delta, it throws an exception saying this command is not supported for Delta tables.

### What changes were proposed in this pull request?

This PR aims to enable CREATE TABLE LIKE for Delta. [CREATE TABLE LIKE](https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-create-table-like.html) is a SQL DDL that creates an empty new table using the definition and metadata of an existing table or view. [CREATE TABLE LIKE](https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-create-table-like.html) is not supported for creating Delta tables. Currently, when a user tries to use CREATE TABLE LIKE with Delta, it throws an exception saying this command is not supported for Delta tables.

Specifically, the following table properties are being copied over:
| Metadata Field/Type  | Non-Delta Tables                                    | Delta Tables |
|----------------------|-----------------------------------------------------|--------------|
| Description(Comment) | Yes                                                 | Yes          |
| Schema               | Yes                                                 | Yes          |   |
| Partition Columns    | Yes                                                 | Yes          |
| Configuration        | Yes                                                 | Yes          |
| Delta Protocol       | No(Current Default Protocol for that spark session) | Yes          |

### How was this patch tested?

This patch is tested by adding unit tests for CREATE TABLE LIKE in the DeltaCreateTableLikeSuite.scala file. Other existing tests were modified to reflect the change that Delta Tables are now supported for the Create Table Like Command.

## Description

This PR aims to enable CREATE TABLE LIKE for Delta. CREATE TABLE LIKE is a SQL DDL that creates an empty new table using the definition and metadata of an existing table or view. CREATE TABLE LIKE is not supported for creating Delta tables. Currently, when a user tries to use CREATE TABLE LIKE with Delta, it throws an exception saying this command is not supported for Delta tables.

Closes #1584

GitOrigin-RevId: de25640020ae12ed2d15bfbcb4e46c0305f9e4a2
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.

2 participants