{"record":{"id":"4c6bd7384abcfc32","repo":"apache/iceberg","slug":"msg-syntax-error-at-input-position","errorCode":null,"errorMessage":"msg (syntax error at input position)","messagePattern":"msg \\(syntax error at input position\\)","errorType":"exception","errorClass":"IcebergParseException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSparkSqlExtensionsParser.scala","lineNumber":299,"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":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSparkSqlExtensionsParser.scala#L281-L317","documentation":"The extensions parser's ANTLR error listener converts lexer/parser syntax errors into an IcebergParseException, embedding the original message with the offending line and character position from the token stream. It indicates the SQL text does not conform to Spark grammar plus the Iceberg extension grammar.","triggerScenarios":"Submitting SQL that fails ANTLR parsing — unknown tokens, unbalanced parentheses, unsupported Iceberg extension clauses, or using an extension clause with a Spark version whose grammar lacks it.","commonSituations":"Running Iceberg-specific SQL (CALL, MERGE extensions, ALTER ... WRITE ORDERED BY) against a build missing the extensions parser; typos in SQL; pasting Spark-3.4 syntax into Spark 3.5 clusters without the right jar.","solutions":["Fix the SQL at the reported line/character position","Ensure the Iceberg Spark extensions parser is registered (spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions) and the correct iceberg-spark jar is on the classpath","Match the iceberg-spark-runtime artifact version to the exact Spark minor version in use"],"exampleFix":"// before\nCALL catalog.system.rewrite_datafiles(table => 'db.t', options); // invalid named-arg syntax\n// after\nCALL catalog.system.rewrite_datafiles(table => 'db.t', options => map('target-file-size-bytes','134217728'));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(sqlText)\n} catch {\n  case e: IcebergParseException if e.line.isDefined =>\n    val l = sqlText.split(\"\\n\").apply(e.line.get - 1)\n    log.error(s\"Syntax error near: $l\"); throw e\n}","preventionTips":["Register IcebergSparkSessionExtensions so the extension grammar is active","Match iceberg-spark artifact to the exact Spark minor version","Lint SQL with a parser aware of Iceberg extension syntax before execution"],"tags":["spark","parser","syntax","antlr"],"backgroundTag":"invalid-argument-format","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}