{"record":{"id":"79dcfe21d885c866","repo":"apache/iceberg","slug":"cannot-set-write-order-of-non-iceberg-table-tabl","errorCode":null,"errorMessage":"Cannot set write order of non-Iceberg table: $table","messagePattern":"Cannot set write order of non-Iceberg table: \\$table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/SetWriteDistributionAndOrderingExec.scala","lineNumber":69,"sourceCode":"        sortOrder.foreach {\n          case (term, SortDirection.ASC, nullOrder) =>\n            orderBuilder.asc(term, nullOrder)\n          case (term, SortDirection.DESC, nullOrder) =>\n            orderBuilder.desc(term, nullOrder)\n        }\n        orderBuilder.commit()\n\n        distributionMode.foreach { mode =>\n          txn\n            .updateProperties()\n            .set(WRITE_DISTRIBUTION_MODE, mode.modeName())\n            .commit()\n        }\n\n        txn.commitTransaction()\n\n      case table =>\n        throw new UnsupportedOperationException(\n          s\"Cannot set write order of non-Iceberg table: $table\")\n    }\n\n    Nil\n  }\n\n  override def simpleString(maxFields: Int): String = {\n    val tableIdent = s\"${catalog.name}.${ident.quoted}\"\n    val order = sortOrder\n      .map { case (term, direction, nullOrder) =>\n        s\"$term $direction $nullOrder\"\n      }\n      .mkString(\", \")\n    s\"SetWriteDistributionAndOrdering $tableIdent $distributionMode $order\"\n  }\n}\n","sourceCodeStart":51,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/SetWriteDistributionAndOrderingExec.scala#L51-L86","documentation":"Iceberg's SetWriteDistributionAndOrderingExec only supports applying write distribution/ordering to tables backed by an Iceberg catalog. If the resolved table is any other DataSource V2 table (or cannot be cast to Iceberg's Table/transaction interface), the executor throws this UnsupportedOperationException. It exists because write order is an Iceberg table-property concept with no meaning for other table implementations.","triggerScenarios":"Running ALTER TABLE ... SET TBLPROPERTIES or the WRITE ORDERED BY / WRITE DISTRIBUTED BY SQL commands against a table resolved from a non-Iceberg catalog (e.g. a generic Spark V2 catalog like the built-in JDBC or another format's catalog).","commonSituations":"Pointing spark.sql.catalog.<name> at a non-Iceberg catalog implementation and then attempting to set Iceberg write order; running Iceberg extensions SQL against a view or temporary table; catalog name typo causing fallback to the session catalog.","solutions":["Verify the catalog backing the table is an Iceberg catalog (spark_catalog or a catalog with org.apache.iceberg.spark.SparkCatalog)","Set spark.sql.catalog.<name>=org.apache.iceberg.spark.SparkCatalog and spark.sql.catalog.<name>.<format>=iceberg or a catalog-impl","Migrate the table to Iceberg before setting write order (e.g. via Spark procedure migrate/snapshot or rewrite)"],"exampleFix":"// before\nspark.sql(\"ALTER TABLE jdbctable WRITE ORDERED BY id\") // throws\n// after\nspark.sql(\"ALTER TABLE iceberg_table WRITE ORDERED BY id\") // table in an Iceberg catalog","handlingStrategy":"validation","validationCode":"val catalogImpl = spark.conf.get(s\"spark.sql.catalog.$catalogName\", \"\")\nif (!catalogImpl.contains(\"org.apache.iceberg\")) {\n  throw new IllegalStateException(s\"Catalog $catalogName is not an Iceberg catalog\")\n}","typeGuard":"def isIcebergTable(t: Table): Boolean = t.isInstanceOf[org.apache.iceberg.spark.source.SparkTable] && t.asInstanceOf[SparkTable].table() != null","tryCatchPattern":"try {\n  spark.sql(s\"ALTER TABLE $name WRITE ORDERED BY id\")\n} catch {\n  case e: UnsupportedOperationException if e.getMessage.contains(\"Cannot set write order of non-Iceberg table\") =>\n    logError(s\"$name is not an Iceberg table; skipping write order\", e)\n}","preventionTips":["Confirm every catalog you configure maps to an Iceberg SparkCatalog before using Iceberg DDL","Check table format with DESCRIBE TABLE/SHOW TBLPROPERTIES before write-order commands","Keep Iceberg SQL usage confined to catalogs registered as Iceberg"],"tags":["spark","iceberg","unsupported-operation","write-order"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}