{"record":{"id":"4a0b99395b48edd3","repo":"apache/iceberg","slug":"msg-syntax-error-at-input-position-4a0b99","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/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSparkSqlExtensionsParser.scala","lineNumber":294,"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":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/IcebergSparkSqlExtensionsParser.scala#L276-L312","documentation":"This is the Iceberg extension parser's syntax-error path: when the ANTLR lexer/parser fails, it builds start/stop Origin positions from the failing token and throws IcebergParseException with the generated message describing the syntax error and where it occurred. It means the SQL did not match the Iceberg-extended Spark grammar.","triggerScenarios":"Submitting SQL containing Iceberg extension syntax that does not parse: malformed ALTER TABLE write spec, CALL arguments, identifier issues, or any token the extended grammar cannot accept.","commonSituations":"Typos, missing keywords (e.g. forgot ORDERED BY), mixing Spark 3 syntax with Spark 4 extensions, unbalanced parentheses, or Iceberg extension jars missing so base Spark grammar rejects Iceberg keywords.","solutions":["Check the reported line/column in the message and correct the syntax","Confirm iceberg-spark-extensions jar is on the classpath and registered via spark.sql.extensions","Compare the statement against Iceberg docs examples for your version"],"exampleFix":"// before\nspark.sql(\"ALTER TABLE t WRITE HASH BY id\") // syntax error\n// after\nspark.sql(\"ALTER TABLE t WRITE DISTRIBUTED BY HASH ORDERED BY id\")","handlingStrategy":"validation","validationCode":"def isKnownIcebergDdl(stmt: String): Boolean = stmt.trim.toUpperCase(Locale.ROOT).matches(\"(ALTER TABLE|CALL|ALTER VIEW).*\")","typeGuard":null,"tryCatchPattern":"try { spark.sql(stmt) } catch { case e: IcebergParseException => println(s\"Syntax error near line ${e.line}, col ${e.startPosition}: ${e.getMessage}\") }","preventionTips":["Lint SQL before submission with an Iceberg-aware grammar","Keep the Iceberg grammar in your editor's SQL dialect settings","Check jar versions: iceberg-spark-runtime must match Spark major version"],"tags":["spark","parser","syntax-error"],"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-23T08:17:48.524Z"}