Skip to content

isthmus: visit(NamedWrite) ignores output_mode, so a write declaring MODIFIED_RECORDS converts to a ROWCOUNT TableModify #1213

Description

@nielspardon

visit(NamedWrite) never reads getOutputMode() on the INSERT and DELETE paths -- only handleCreateTableAs checks it, for CTAS -- and returns a LogicalTableModify whose row type is a single ROWCOUNT column:

return LogicalTableModify.create(
targetTable,
requireCatalogReader(relOptSchema, write.getNames()),
input,
operation,
null,
null,
false);

The plan says otherwise. AbstractWriteRel.deriveRecordType() returns the input's record type, and the spec documents OUTPUT_MODE_MODIFIED_RECORDS as returning the records the operator inserted, deleted or updated, further manipulable upstream. So a write declaring MODIFIED_RECORDS converts to a relation that reports one column where the plan declares the input's, and a parent reading it resolves its references against columns that are not there.

isthmus produces those plans itself -- the export direction stamps the mode on every INSERT and DELETE:

.outputMode(AbstractWriteRel.OutputMode.MODIFIED_RECORDS)

#1189 refuses an emit mapping on a write because the mode is dropped, and its message says so, but the drop itself is still silent. Either refuse MODIFIED_RECORDS the way the mapping is now refused, or model it.

Found while reviewing #1189.

Activity

  1. nielspardon commented on Oct 5, 2026

    @nielspardon
    MemberAuthor

    Related, on the CTAS path: handleCreateTableAs does check the output mode, but it accepts only OUTPUT_MODE_NO_OUTPUT, and this repo's Spark module writes every CTAS with OUTPUT_MODE_UNSPECIFIED. So a Spark CREATE TABLE t AS SELECT ... plan is refused by isthmus with Can only handle CTAS NamedWrite with output mode NO_OUTPUT, given UNSPECIFIED, even though its create mode (ERROR_IF_EXISTS / IGNORE_IF_EXISTS / REPLACE_IF_EXISTS) is now supported after #1266. The spec doesn't say what an unspecified output mode means for CTAS, so whichever fix lands here should decide whether isthmus reads it as NO_OUTPUT or whether Spark should emit NO_OUTPUT.

    if (namedWrite.getOutputMode() != AbstractWriteRel.OutputMode.NO_OUTPUT) {
    throw new UnsupportedOperationException(
    String.format(
    "Can only handle CTAS NamedWrite with output mode %s, given %s",
    AbstractWriteRel.OutputMode.NO_OUTPUT, namedWrite.getOutputMode()));
    }

    private def convertCTAS(
    table: CatalogTable,
    mode: SaveMode,
    query: LogicalPlan,
    outputColumnNames: Seq[String]): relation.NamedWrite =
    relation.NamedWrite
    .builder()
    .input(visit(query))
    .operation(WriteOp.CTAS)
    .outputMode(OutputMode.UNSPECIFIED)
    .createMode(createMode(mode))
    .names(table.identifier.unquotedString.split("\\.").toList.asJava)
    .tableSchema(outputSchema(query.output, outputColumnNames))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions