Skip to content

fix(isthmus)!: preserve CTAS creation policies - #1266

Merged
nielspardon merged 2 commits into
substrait-io:mainfrom
bvolpato:bvolpato/fix-ctas-create-mode
Oct 5, 2026
Merged

nielspardon merged 2 commits into
substrait-io:mainfrom
bvolpato:bvolpato/fix-ctas-create-mode

Conversation

@bvolpato

@bvolpato bvolpato commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Plain CREATE TABLE AS SELECT and CREATE TABLE IF NOT EXISTS currently emit REPLACE_IF_EXISTS, allowing a consumer to replace an existing table when the SQL requests an error or a no-op.

Carry ERROR_IF_EXISTS, IGNORE_IF_EXISTS, and REPLACE_IF_EXISTS from the SQL flags through CreateTable, planner copies, and both conversion directions. These CTAS creation modes have been defined since Substrait v0.60.0. Isthmus rejects other creation modes consistently and rejects conflicting SQL flags rather than choosing a precedence that the specification does not define.

Explicit replacement requires CREATE OR REPLACE TABLE. Existing programmatic constructors retain their historical replacement behavior but are deprecated in favor of the constructor with an explicit creation mode.

BREAKING CHANGE: Plain CREATE TABLE AS SELECT now emits ERROR_IF_EXISTS and CREATE TABLE IF NOT EXISTS emits IGNORE_IF_EXISTS instead of REPLACE_IF_EXISTS. Older Isthmus readers that accept only replacement-mode CTAS cannot read these plans. CREATE OR REPLACE TABLE IF NOT EXISTS is now rejected. Callers requiring replacement must request it explicitly.

@bvolpato
bvolpato force-pushed the bvolpato/fix-ctas-create-mode branch from 7af5f67 to 7aa6240 Compare September 4, 2026 16:27
Plain CREATE TABLE AS SELECT and CREATE TABLE IF NOT EXISTS currently emit REPLACE_IF_EXISTS, allowing a consumer to replace an existing table when the SQL requests an error or a no-op.

Carry ERROR_IF_EXISTS, IGNORE_IF_EXISTS, and REPLACE_IF_EXISTS from the SQL flags through CreateTable, planner copies, and both conversion directions. Include the mode in planner digests so different creation policies remain distinct. Explicit replacement requires CREATE OR REPLACE TABLE; existing programmatic constructors retain their historical replacement behavior.

These policies map to the CTAS creation modes defined by Substrait v0.102.0. Conflicting SQL flags are rejected.
@bvolpato
bvolpato force-pushed the bvolpato/fix-ctas-create-mode branch from 7aa6240 to d6b8d7e Compare September 29, 2026 05:15
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 102fdd0f-2348-4182-89d7-a43f8da15ca6
📥 Commits

Reviewing files that changed from the base of the PR and between 4d21734 and 2a99e2b.

📒 Files selected for processing (8)
  • isthmus-cli/src/main/java/io/substrait/isthmus/cli/IsthmusExecutionExceptionHandler.java
  • isthmus-cli/src/test/java/io/substrait/isthmus/cli/IsthmusEntryPointTest.java
  • isthmus/src/main/java/io/substrait/isthmus/SubstraitRelNodeConverter.java
  • isthmus/src/main/java/io/substrait/isthmus/SubstraitRelVisitor.java
  • isthmus/src/main/java/io/substrait/isthmus/calcite/rel/CreateTable.java
  • isthmus/src/main/java/io/substrait/isthmus/calcite/rel/DdlSqlToRelConverter.java
  • isthmus/src/test/java/io/substrait/isthmus/DdlRoundtripTest.java
  • isthmus/src/test/java/io/substrait/isthmus/calcite/rel/DdlRelCopyTest.java
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bvolpato
bvolpato marked this pull request as ready for review September 29, 2026 05:25

@nielspardon nielspardon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please mark this fix(isthmus)!: and end the body with a BREAKING CHANGE: footer: the same SQL now produces different plans (plain CTAS → ERROR_IF_EXISTS), released isthmus can't read those plans, and CREATE OR REPLACE TABLE IF NOT EXISTS now throws. The mapping itself matches the spec. Small nit for the body: CreateMode has been in the spec since v0.60.0, not v0.102.0.

Comment thread isthmus/src/main/java/io/substrait/isthmus/calcite/rel/CreateTable.java Outdated
Comment thread isthmus/src/main/java/io/substrait/isthmus/calcite/rel/CreateTable.java Outdated
Comment thread isthmus/src/main/java/io/substrait/isthmus/calcite/rel/CreateTable.java Outdated
Comment thread isthmus/src/test/java/io/substrait/isthmus/CtasCreateModeTest.java Outdated
Comment thread isthmus/src/test/java/io/substrait/isthmus/CtasCreateModeTest.java Outdated
Comment thread isthmus/src/test/java/io/substrait/isthmus/CtasCreateModeTest.java Outdated
@bvolpato

bvolpato commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review. I also prepared the breaking-change title and final footer, including the old-reader compatibility impact, and clarified that these CTAS modes have been defined since v0.60.0. The code and test follow-ups above pass the full local build. The branch and description updates have not been published yet.

Reject unsupported creation policies at construction, deprecate implicit replacement constructors, and keep explain output JSON-compatible. Report conflicting SQL flags as input errors and validate empty-catalog round trips.
@bvolpato bvolpato changed the title fix(isthmus): preserve CTAS creation policies fix(isthmus)!: preserve CTAS creation policies Oct 3, 2026
@bvolpato

bvolpato commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

I pushed the constructor validation, deprecated the implicit-mode constructors, and fixed JSON explain output and CLI error handling. The consolidated round-trip tests include an empty catalog, and the breaking-change note now spells out the compatibility impact.

@nielspardon nielspardon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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