{"record":{"id":"9136f1e5779de88b","repo":"apache/iceberg","slug":"msg-dynamic-parse-error-message","errorCode":null,"errorMessage":"msg (dynamic parse error message)","messagePattern":"msg \\(dynamic parse error message\\)","errorType":"exception","errorClass":"IcebergParseException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSparkSqlExtensionsParser.scala","lineNumber":316,"sourceCode":"case object IcebergParseErrorListener extends BaseErrorListener {\n  override def syntaxError(\n      recognizer: Recognizer[_, _],\n      offendingSymbol: scala.Any,\n      line: Int,\n      charPositionInLine: Int,\n      msg: String,\n      e: RecognitionException): Unit = {\n    val (start, stop) = offendingSymbol match {\n      case token: CommonToken =>\n        val start = Origin(Some(line), Some(token.getCharPositionInLine))\n        val length = token.getStopIndex - token.getStartIndex + 1\n        val stop = Origin(Some(line), Some(token.getCharPositionInLine + length))\n        (start, stop)\n      case _ =>\n        val start = Origin(Some(line), Some(charPositionInLine))\n        (start, start)\n    }\n    throw new IcebergParseException(None, msg, start, stop)\n  }\n}\n\n/**\n * Copied from Apache Spark\n * A [[ParseException]] is an [[AnalysisException]] that is thrown during the parse process. It\n * contains fields and an extended error message that make reporting and diagnosing errors easier.\n */\nclass IcebergParseException(\n    val command: Option[String],\n    message: String,\n    val start: Origin,\n    val stop: Origin)\n    extends AnalysisException(message, start.line, start.startPosition) {\n\n  def this(message: String, ctx: ParserRuleContext) = {\n    this(\n      Option(IcebergParserUtils.command(ctx)),","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSparkSqlExtensionsParser.scala#L298-L334","documentation":"This is the ANTLR error-listener hook of the Iceberg SQL extensions parser: whenever the lexer/parser fails on Iceberg extension syntax, it throws an IcebergParseException whose message is the dynamic ANTLR parse error and whose Origin marks the failing line and column. It indicates the SQL text does not match the Iceberg extension grammar.","triggerScenarios":"Any syntactically invalid use of Iceberg SQL extensions: malformed CALL arguments, wrong ALTER TABLE ... SET TBLPROPERTIES/WRITE DISTRIBUTED/ORDERED BY syntax, unknown branch syntax, or a missing/extra token in an extension statement.","commonSituations":"Typos in Iceberg-specific clauses; using plain-Spark syntax where the Iceberg grammar requires its own form; forgetting extensions registration so a valid Iceberg statement is parsed by the wrong grammar; version mismatch between grammar features and the Iceberg release.","solutions":["Fix the SQL per the message's line/column and the Iceberg extension grammar (e.g. `ALTER TABLE t WRITE ORDERED BY col`, `CALL catalog.system.procedure(...)`).","Verify both parser extensions and the matching iceberg-spark-extensions version are registered for your exact Spark version.","Split complex statements and test each clause to isolate the token the parser rejects.","If the statement is valid for a newer Iceberg grammar, upgrade the extensions artifact."],"exampleFix":"-- before\nALTER TABLE t WRITE ORDERED BY\n-- after\nALTER TABLE t WRITE ORDERED BY col ASC NULLS FIRST","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(stmt)\n} catch {\n  case e: IcebergParseException if e.getMessage.contains(\"mismatched input\") || e.getMessage.contains(\"no viable alternative\") =>\n    throw new IllegalArgumentException(s\"Check Iceberg SQL syntax near: ${e.getMessage}\", e)\n}","preventionTips":["Verify Iceberg parser extensions are registered in spark.sql.extensions","Fix statements per the line/column in the parse message","Compare each clause with documented Iceberg extension syntax","Keep extension artifact versions in lockstep with Spark and Iceberg releases"],"tags":["spark","sql-parser","antlr","sql-syntax"],"backgroundTag":"invalid-sql-syntax","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}