{"record":{"id":"ae6ed624ee3aa94a","repo":"apache/iceberg","slug":"invalidviewnameerror-name-ae6ed6","errorCode":null,"errorMessage":"invalidViewNameError(name)","messagePattern":"invalidViewNameError\\(name\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveViews.scala","lineNumber":161,"sourceCode":"      SparkSQLProperties.VIEW_SCHEMA_MODE_COMPENSATION\n    } else {\n      throw new IllegalArgumentException(\n        s\"Invalid value for ${SparkSQLProperties.VIEW_SCHEMA_BINDING_MODE}: $mode, expected \" +\n          s\"${SparkSQLProperties.VIEW_SCHEMA_MODE_BINDING} or \" +\n          s\"${SparkSQLProperties.VIEW_SCHEMA_MODE_COMPENSATION}\")\n    }\n  }\n\n  private def parseViewText(name: String, viewText: String): LogicalPlan = {\n    val origin = Origin(objectType = Some(\"VIEW\"), objectName = Some(name))\n\n    try {\n      CurrentOrigin.withOrigin(origin) {\n        spark.sessionState.sqlParser.parseQuery(viewText)\n      }\n    } catch {\n      case _: ParseException =>\n        throw QueryCompilationErrors.invalidViewNameError(name)\n    }\n  }\n\n  private def rewriteIdentifiers(\n      plan: LogicalPlan,\n      catalogAndNamespace: Seq[String]): LogicalPlan = {\n    // Rewrite unresolved functions and relations\n    qualifyTableIdentifiers(\n      qualifyFunctionIdentifiers(CTESubstitution.apply(plan), catalogAndNamespace),\n      catalogAndNamespace)\n  }\n\n  private def qualifyFunctionIdentifiers(\n      plan: LogicalPlan,\n      catalogAndNamespace: Seq[String]): LogicalPlan = plan transformExpressions {\n    case u @ UnresolvedFunction(Seq(name), _, _, _, _, _, _) =>\n      if (!isBuiltinFunction(name)) {\n        u.copy(nameParts = catalogAndNamespace :+ name)","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveViews.scala#L143-L179","documentation":"When resolving a view, Iceberg re-parses the stored view SQL text with Spark's SQL parser. If parsing fails with a ParseException, the error is reported as an invalid view name rather than leaking the parse exception, because a view whose text cannot be parsed under the current catalog/namespace context is effectively unresolvable. This guards users with a clearer message tied to the view name.","triggerScenarios":"Querying or resolving a stored view whose viewText no longer parses in the current session/catalog context — e.g. the view SQL references identifiers, functions, or syntax invalid under the resolved catalog and namespace, or the view was created by an older/other engine with syntax the current parser rejects.","commonSituations":"Views created under a different Spark version whose SQL is no longer parseable; view text stored with dialect-specific syntax; corrupted or hand-edited view metadata; catalog/namespace change making an unqualified reference in viewText invalid.","solutions":["DROP and recreate the view with SQL that parses in the current Spark/catalog context","Inspect the view's stored text (SHOW CREATE TABLE / metadata) and fix invalid syntax","Align the Spark version or parser used to the one that created the view","Qualify all references inside the view text so it parses regardless of current namespace"],"exampleFix":"-- before: query stale view\nSELECT * FROM catalog.db.old_view; -- ParseException internally\n-- after: recreate it\nDROP VIEW catalog.db.old_view;\nCREATE VIEW catalog.db.old_view AS SELECT id, ts FROM catalog.db.src;","handlingStrategy":"try-catch","validationCode":"// verify the view resolves before querying\nval exists = spark.catalog.tableExists(\"catalog\", \"db\", \"old_view\")\nif (!exists) throw new IllegalStateException(\"view missing; recreate it\")","typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(s\"SELECT * FROM catalog.db.v\")\n} catch {\n  case e: AnalysisException if e.getMessage.contains(\"invalid view name\") =>\n    // viewText no longer parses: recreate the view\n    spark.sql(\"CREATE VIEW catalog.db.v AS <valid SQL>\")\n}","preventionTips":["Fully qualify all table/catalog references inside view definitions","Recreate views after Spark major upgrades and verify with a test query","Avoid hand-editing view metadata"],"tags":["spark","views","sql-parsing"],"backgroundTag":"invalid-identifier-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"}