apache/iceberg · error

ALTER TABLE has no changes: missing both distribution and…

Error message

ALTER TABLE has no changes: missing both distribution and ordering clauses

What it means

The AST builder for ALTER TABLE ... WRITE (DISTRIBUTED|ORDERED BY ...) requires at least one of a distribution clause or an ordering clause. If the write spec is empty (no changes requested), an AnalysisException is thrown since the statement would be a no-op.

Solutions

  1. Add the intended clause, e.g. ALTER TABLE t WRITE ORDERED BY col; or ALTER TABLE t WRITE DISTRIBUTED BY PARTITION;
  2. To reset to defaults, use ALTER TABLE t WRITE UNORDERED; or WRITE DISTRIBUTED BY PARTITION with no ordering
  3. Drop the statement entirely if no change is intended

Example fix

// before
ALTER TABLE catalog.db.t WRITE;
// after
ALTER TABLE catalog.db.t WRITE ORDERED BY id;
Defensive patterns

Strategy: validation

Validate before calling

val spec = sqlText.stripPrefix("ALTER TABLE t WRITE ").trim
require(spec.nonEmpty, "ALTER TABLE WRITE requires DISTRIBUTED/ORDERED/UNORDERED/LOCALLY ORDERED clause")

Try / catch

try { spark.sql(ddl) } catch { case e: AnalysisException if e.getMessage.contains("no changes") => log.warn("no-op write spec") }

Prevention

When it happens

Trigger: Running 'ALTER TABLE t WRITE ...' where the write spec contains neither a distribution spec (DISTRIBUTED BY/HASH/etc.) nor an ordering spec (ORDERED BY/LOCALLY ORDERED BY/UNORDERED), e.g. 'ALTER TABLE t WRITE' with nothing after it that the grammar accepts.

Common situations: Incomplete SQL statements from generated scripts; users expecting the statement to reset distribution/ordering to defaults without specifying clauses.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/ba0fd5aa66ee9eaf. Report an issue: GitHub.

Appendix: source

Thrown at spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSqlExtensionsAstBuilder.scala:243

  override def visitDropIdentifierFields(ctx: DropIdentifierFieldsContext): DropIdentifierFields =
    withOrigin(ctx) {
      DropIdentifierFields(
        typedVisit[Seq[String]](ctx.multipartIdentifier),
        toSeq(ctx.fieldList.fields).map(_.getText))
    }

  /**
   * Create a [[SetWriteDistributionAndOrdering]] for changing the write distribution and ordering.
   */
  override def visitSetWriteDistributionAndOrdering(
      ctx: SetWriteDistributionAndOrderingContext): SetWriteDistributionAndOrdering = {

    val tableName = typedVisit[Seq[String]](ctx.multipartIdentifier)

    val (distributionSpec, orderingSpec) = toDistributionAndOrderingSpec(ctx.writeSpec)

    if (distributionSpec == null && orderingSpec == null) {
      throw new AnalysisException(
        "ALTER TABLE has no changes: missing both distribution and ordering clauses")
    }

    val distributionMode = if (distributionSpec != null) {
      Some(DistributionMode.HASH)
    } else if (orderingSpec.UNORDERED != null) {
      Some(DistributionMode.NONE)
    } else if (orderingSpec.LOCALLY() != null) {
      None
    } else {
      Some(DistributionMode.RANGE)
    }

    val ordering = if (orderingSpec != null && orderingSpec.order != null) {
      toSeq(orderingSpec.order.fields).map(typedVisit[(Term, SortDirection, NullOrder)])
    } else {
      Seq.empty
    }

View on GitHub (pinned to 86d9c8fc54)