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-45807][SQL] Add createOrReplaceView(..) / replaceView(..) to ViewCatalog #43677

Closed
wants to merge 1 commit into from

Conversation

nastra
Copy link
Contributor

@nastra nastra commented Nov 6, 2023

What changes were proposed in this pull request?

ViewCatalog API improvements described in SPIP that didn't make it into the codebase as part of #37556

Why are the changes needed?

Required for DataSourceV2 view support.

Does this PR introduce any user-facing change?

No

How was this patch tested?

N/A

Was this patch authored or co-authored using generative AI tooling?

N/A

@github-actions github-actions bot added the SQL label Nov 6, 2023
@nastra nastra changed the title SPARK-45807: Add createOrReplaceView(..) / replaceView(..) to ViewCatalog [SPARK-45807][SQL]: Add createOrReplaceView(..) / replaceView(..) to ViewCatalog Nov 6, 2023
@nastra nastra closed this Nov 6, 2023
@nastra nastra reopened this Nov 6, 2023
@nastra
Copy link
Contributor Author

nastra commented Nov 6, 2023

/cc @holdenk @jzhuge

Copy link
Member

@jzhuge jzhuge left a comment

Choose a reason for hiding this comment

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

Thanks for catching this!

@nastra
Copy link
Contributor Author

nastra commented Nov 21, 2023

@aokolnychyi could you also take a look at this please?

@aokolnychyi
Copy link
Contributor

Will review today.

String[] columnAliases,
String[] columnComments,
Map<String, String> properties) throws NoSuchNamespaceException {
if (!viewExists(ident)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: I think it is easier to read conditions that don't have negation. I'd flip the branches.

Copy link
Contributor

@aokolnychyi aokolnychyi left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@nastra
Copy link
Contributor Author

nastra commented Nov 22, 2023

thanks for reviewing @aokolnychyi, I've applied your suggestion

@HyukjinKwon HyukjinKwon changed the title [SPARK-45807][SQL]: Add createOrReplaceView(..) / replaceView(..) to ViewCatalog [SPARK-45807][SQL] Add createOrReplaceView(..) / replaceView(..) to ViewCatalog Nov 22, 2023
@jzhuge
Copy link
Member

jzhuge commented Dec 3, 2023

@holdenk Could you merge this PR if you think it is ready?

@holdenk
Copy link
Contributor

holdenk commented Dec 3, 2023

Sure let me merge on Monday assuming no objections from folks (taking a weekend vacation with mostly books instead of computers).

@asfgit asfgit closed this in 89673da Dec 5, 2023
String[] queryColumnNames,
String[] columnAliases,
String[] columnComments,
Map<String, String> properties) throws NoSuchViewException, NoSuchNamespaceException {
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we have a class ViewInfo to wrap these fields? It looks verbose to make so many parameters in 3 methods.

Copy link
Member

Choose a reason for hiding this comment

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

Agree, it is verbose.

* @param properties the view properties
* @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
*/
default void createOrReplaceView(
Copy link
Contributor

Choose a reason for hiding this comment

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

3 APIs might be too much. How about we follow the create/replace table logical plan? We have a CreateTable with a bool field ignoreIfExists, and a ReplaceTable with a bool field orCreate.

So we can have just two methods here

def createView(... , ignoreIfExists: Boolean)

def replaceView(..., orCreate: Boolean)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the feedback @cloud-fan. I'll follow up with your suggestions and will ping you for a review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cloud-fan I have made the suggested improvements in #44330 but I'm not sure about having ignoreIfExists on the API when creating a view.
I checked and the TableCatalog also doesn't have such functionality and I wonder if it wouldn't be better to have ignoreIfExists be part of the physical plan that creates the view (similar to how it's done in https://github.com/apache/spark/pull/44197/files#diff-d491b3b4f1ac890067f57f4c30cbdecf3585ea91dabf0dced59b31a4e1643462R83)

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. A simpler API is better. The caller side (Spark) can just ignore the error if ignoreIfExists is true.

dbatomic pushed a commit to dbatomic/spark that referenced this pull request Dec 11, 2023
…iewCatalog

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

ViewCatalog API improvements described in [SPIP](https://docs.google.com/document/d/1XOxFtloiMuW24iqJ-zJnDzHl2KMxipTjJoxleJFz66A/edit?usp=sharing) that didn't make it into the codebase as part of apache#37556

### Why are the changes needed?

Required for DataSourceV2 view support.

### Does this PR introduce _any_ user-facing change?

No
### How was this patch tested?

N/A

### Was this patch authored or co-authored using generative AI tooling?

N/A

Closes apache#43677 from nastra/SPARK-45807.

Authored-by: Eduard Tudenhoefner <etudenhoefner@gmail.com>
Signed-off-by: Holden Karau <holden@pigscanfly.ca>
cloud-fan pushed a commit that referenced this pull request Dec 15, 2023
### What changes were proposed in this pull request?

Follow-up API improvements based on comments from #43677

### Why are the changes needed?

Required for DataSourceV2 view support.

### Does this PR introduce _any_ user-facing change?

No
### How was this patch tested?

N/A

### Was this patch authored or co-authored using generative AI tooling?

N/A

Closes #44330 from nastra/SPARK-45807-api-improvements.

Authored-by: Eduard Tudenhoefner <etudenhoefner@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
cloud-fan pushed a commit that referenced this pull request Feb 2, 2024
### What changes were proposed in this pull request?

Follow-up API improvements based on from #43677

### Why are the changes needed?

Required for DataSourceV2 view support.

### Does this PR introduce _any_ user-facing change?

No
### How was this patch tested?

N/A

### Was this patch authored or co-authored using generative AI tooling?

N/A

Closes #44970 from nastra/SPARK-45807-return-type.

Authored-by: Eduard Tudenhoefner <etudenhoefner@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants