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: skip insert when creating table that exists #2901

Merged
merged 7 commits into from
Apr 17, 2024

Conversation

tychoish
Copy link
Collaborator

Closes #2899

@talagluck to add SLTs

@tychoish tychoish closed this Apr 16, 2024
@tychoish tychoish reopened this Apr 16, 2024
@tychoish tychoish enabled auto-merge (squash) April 16, 2024 17:17
@universalmind303
Copy link
Contributor

universalmind303 commented Apr 16, 2024

@tychoish i disabled automerge. We should definitely get #2875 in first as this'll likely have some conflicts

universalmind303 and others added 3 commits April 17, 2024 13:49
This fixes a bug introduced by datafusion 36

previously some operations that failed during optimization such as
invalid casts now fail at runtime.

Since they now fail at runtime, it means that we would still create the
catalog and table and only fail during insert afterwards. This left both
the catalog and the storage in a bad state that didn't accurately
reflect the operation. e.g.

```sql
create table invalid_ctas as (select cast('test' as int) as 'bad_cast');
```

This updated the catalog and created a table for `invalid_ctas`, but
when you'd query it you would get an error.

This PR makes sure that the operation is successful before committing
the changes. It does so by exposing some new methods on the catalog
client. `commit_state` `mutate_and_commit` and `mutate` instead of the
previous `mutate`.

The existing code was refactored to use the `mutate_and_commit` which is
the same as the old `mutate`. The code that requires the commit
semantics (create table) now uses `mutate` to first get an uncommitted
catalog state with those changes, then does all of it's other actions

- create the "native" table
- _Optional_ inserts into the table
- commits the catalog state

If any of the operations before the commit fail, then the catalog
mutations are never committed.

---------

Co-authored-by: Sean Smith <scsmithr@gmail.com>
@tychoish tychoish enabled auto-merge (squash) April 17, 2024 17:51
@tychoish tychoish merged commit 50b3428 into main Apr 17, 2024
26 checks passed
@tychoish tychoish deleted the tycho/create-table-if-not-exists branch April 17, 2024 18:07
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.

BUG: IF NOT EXISTS not working properly with CREATE TABLE
3 participants