{"record":{"id":"7ea9732a74099f2d","repo":"prestodb/presto","slug":"invalid-view","errorCode":"INVALID_VIEW","errorMessage":"View already exists as data table","messagePattern":"View already exists as data table","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-accumulo/src/main/java/com/facebook/presto/accumulo/AccumuloClient.java","lineNumber":547,"sourceCode":"        }\n\n        if (tableManager.exists(newTable.getMetricsTableName())) {\n            throw new PrestoException(ACCUMULO_TABLE_EXISTS, format(\"Table %s already exists\", newTable.getMetricsTableName()));\n        }\n\n        tableManager.renameAccumuloTable(oldTable.getIndexTableName(), newTable.getIndexTableName());\n        tableManager.renameAccumuloTable(oldTable.getMetricsTableName(), newTable.getMetricsTableName());\n    }\n\n    public void createView(SchemaTableName viewName, String viewData)\n    {\n        if (getSchemaNames().contains(viewName.getSchemaName())) {\n            if (getViewNames(viewName.getSchemaName()).contains(viewName.getTableName())) {\n                throw new PrestoException(ALREADY_EXISTS, \"View already exists\");\n            }\n\n            if (getTableNames(viewName.getSchemaName()).contains(viewName.getTableName())) {\n                throw new PrestoException(INVALID_VIEW, \"View already exists as data table\");\n            }\n        }\n\n        metaManager.createViewMetadata(new AccumuloView(viewName.getSchemaName(), viewName.getTableName(), viewData));\n    }\n\n    public void createOrReplaceView(SchemaTableName viewName, String viewData)\n    {\n        if (getView(viewName) != null) {\n            metaManager.deleteViewMetadata(viewName);\n        }\n\n        metaManager.createViewMetadata(new AccumuloView(viewName.getSchemaName(), viewName.getTableName(), viewData));\n    }\n\n    public void dropView(SchemaTableName viewName)\n    {\n        metaManager.deleteViewMetadata(viewName);","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-accumulo/src/main/java/com/facebook/presto/accumulo/AccumuloClient.java#L529-L565","documentation":"Thrown by createView when the requested view name collides with an existing DATA TABLE (not a view) in the same schema. The connector distinguishes tables from views in its metadata, and creating a view on top of a table name is invalid, so it fails with INVALID_VIEW before any metadata is written.","triggerScenarios":"Calling createView(viewName, viewData) where getTableNames(viewName.getSchemaName()).contains(viewName.getTableName()) is true — the target name is an existing Accumulo-backed data table.","commonSituations":"Naming a view the same as a table that was created earlier in the schema; migration scripts that convert tables to views but leave the old table in place; confusion after sync/rename operations left a table with the intended view name.","solutions":["Choose a different name for the view","Drop or rename the existing data table if it is no longer needed","Move the data table to another schema/name, then create the view","Verify with SHOW TABLES vs SHOW VIEWS which object occupies the name"],"exampleFix":"// before\nCREATE VIEW my_schema.events AS SELECT ...; -- my_schema.events is a data table\n// after\nALTER TABLE my_schema.events RENAME TO my_schema.events_raw;\nCREATE VIEW my_schema.events AS SELECT ...;","handlingStrategy":"validation","validationCode":"-- Pre-check that the name is not occupied by a table\nSELECT count(*) FROM system.jdbc.tables WHERE table_schema = 'my_schema' AND table_name = 'my_view'; -- expect 0","typeGuard":"boolean nameNotATable(SchemaTableName name) {\n    return !getSchemaNames().contains(name.getSchemaName())\n        || !getTableNames(name.getSchemaName()).contains(name.getTableName());\n}","tryCatchPattern":"try {\n    client.createView(viewName, viewData);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"INVALID_VIEW\")) {\n        // a data table holds this name: rename/drop the table or pick a new view name\n    } else {\n        throw e;\n    }\n}","preventionTips":["Maintain separate naming conventions for tables vs views (e.g. vw_ prefix)","Run SHOW TABLES and SHOW VIEWS before creating a view","Remove or rename stale tables left by failed migrations before re-running scripts","Document and enforce that view names never shadow table names in a schema"],"tags":["accumulo","invalid-view","name-collision","ddl"],"backgroundTag":"table-already-exists","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}