{"record":{"id":"f8b8d3ecfe4dea22","repo":"apache/iceberg","slug":"view-does-not-exist-s-s","errorCode":null,"errorMessage":"View does not exist: %s.%s","messagePattern":"View does not exist: (.+?)\\.(.+?)","errorType":"exception","errorClass":"NoSuchViewException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java","lineNumber":104,"sourceCode":"  @Override\n  public void doRefresh() {\n    String metadataLocation = null;\n    Table table;\n\n    try {\n      table = metaClients.run(client -> client.getTable(database, viewName));\n\n      // Check if we are trying to load an Iceberg Table as a View\n      HiveOperationsBase.validateIcebergTableNotLoadedAsIcebergView(table, fullName);\n      // Check if it is a valid Iceberg View\n      HiveOperationsBase.validateTableIsIcebergView(table, fullName);\n\n      metadataLocation =\n          table.getParameters().get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP);\n\n    } catch (NoSuchObjectException e) {\n      if (currentMetadataLocation() != null) {\n        throw new NoSuchViewException(\"View does not exist: %s.%s\", database, viewName);\n      }\n    } catch (TException e) {\n      String errMsg =\n          String.format(\"Failed to get view info from metastore %s.%s\", database, viewName);\n      throw new RuntimeException(errMsg, e);\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new RuntimeException(\"Interrupted during refresh\", e);\n    }\n\n    refreshFromMetadataLocation(metadataLocation);\n  }\n\n  @SuppressWarnings(\"checkstyle:CyclomaticComplexity\")\n  @Override\n  public void doCommit(ViewMetadata base, ViewMetadata metadata) {\n    boolean newView = base == null;\n    String newMetadataLocation = writeNewMetadataIfRequired(metadata);","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java#L86-L122","documentation":"HiveViewOperations.doRefresh wraps the HMS getView call; if Hive reports NoSuchObjectException but this operation already has a current metadata location, the view previously existed and was dropped, so it throws NoSuchViewException with the database and view name. If there was no prior location, refresh simply treats it as a non-existent view (used during create).","triggerScenarios":"Calling refreshView or any refresh-triggering view operation when the view was deleted from Hive between load and refresh (currentMetadataLocation() != null but HMS getView throws NoSuchObjectException).","commonSituations":"Another job or user dropped the view concurrently; pointing at a database where the view was dropped; staging/refresh environments where views are recreated; stale catalog handles after DDL.","solutions":["Re-create the view or re-load it from the catalog to obtain a fresh handle.","Check the view's existence with the catalog/HMS before refreshing in long-lived jobs.","Coordinate DDL so views are not dropped while readers hold references; use retries that re-resolve the identifier on NoSuchViewException.","Verify you are connected to the correct metastore/database (view may exist elsewhere)."],"exampleFix":"// before\nView view = catalog.loadView(identifier);\nview.refresh(); // NoSuchViewException if dropped\n// after\nif (catalog.viewExists(identifier)) {\n  catalog.loadView(identifier).refresh();\n} else {\n  // recreate or re-resolve\n}","handlingStrategy":"try-catch","validationCode":"if (!catalog.viewExists(identifier)) {\n  throw new IllegalStateException(identifier + \" does not exist; refresh skipped\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  view.refresh();\n} catch (NoSuchViewException e) {\n  // view was dropped concurrently; reload or recreate\n  view = catalog.loadView(identifier); // or handle absence\n}","preventionTips":["Re-resolve view identifiers periodically in long-lived jobs.","Coordinate view DDL across teams/jobs to avoid dropping views in use.","Check catalog.viewExists before operating on potentially stale handles.","Handle NoSuchViewException explicitly in pipelines that tolerate view recreation."],"tags":["hive-metastore","view","not-found","concurrency"],"backgroundTag":"entity-not-found","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"}