{"record":{"id":"19e2d59d1b4c7d3d","repo":"prestodb/presto","slug":"bigquery-view-destination-table-creation-failed","errorCode":"BIGQUERY_VIEW_DESTINATION_TABLE_CREATION_FAILED","errorMessage":"Error creating destination table","messagePattern":"Error creating destination table","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-bigquery/src/main/java/com/facebook/presto/plugin/bigquery/ReadSessionCreator.java","lineNumber":124,"sourceCode":"    {\n        TableDefinition tableDefinition = table.getDefinition();\n        TableDefinition.Type tableType = tableDefinition.getType();\n        if (TableDefinition.Type.TABLE == tableType) {\n            return table;\n        }\n        if (TableDefinition.Type.VIEW == tableType) {\n            if (!config.viewsEnabled) {\n                throw new PrestoException(NOT_SUPPORTED,\n                        \"Views are not enabled. You can enable views by setting 'bigquery.views-enabled' to true. Notice additional cost may occur.\");\n            }\n            // get it from the view\n            String querySql = bigQueryClient.createSql(table.getTableId(), requiredColumns);\n            log.debug(\"querySql is %s\", querySql);\n            try {\n                return destinationTableCache.get(querySql, new DestinationTableBuilder(bigQueryClient, config, querySql, table.getTableId()));\n            }\n            catch (ExecutionException e) {\n                throw new PrestoException(BigQueryErrorCode.BIGQUERY_VIEW_DESTINATION_TABLE_CREATION_FAILED, \"Error creating destination table\", e);\n            }\n        }\n        else {\n            // not regular table or a view\n            throw new PrestoException(NOT_SUPPORTED, format(\"Table type '%s' of table '%s.%s' is not supported\",\n                    tableType, table.getTableId().getDataset(), table.getTableId().getTable()));\n        }\n    }\n\n    static class DestinationTableBuilder\n            implements Callable<TableInfo>\n    {\n        final BigQueryClient bigQueryClient;\n        final ReadSessionCreatorConfig config;\n        final String querySql;\n        final TableId table;\n\n        DestinationTableBuilder(BigQueryClient bigQueryClient, ReadSessionCreatorConfig config, String querySql, TableId table)","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-bigquery/src/main/java/com/facebook/presto/plugin/bigquery/ReadSessionCreator.java#L106-L142","documentation":"When views are enabled, getActualTable materializes a view via a DestinationTableBuilder cached by query SQL (destinationTableCache.get); an ExecutionException from that cache load is wrapped as BIGQUERY_VIEW_DESTINATION_TABLE_CREATION_FAILED. It means the background job that runs the view query and creates the destination table in BigQuery failed.","triggerScenarios":"Querying an enabled view whose DestinationTableBuilder call fails — invalid view SQL, insufficient permissions to create tables in the dataset, BigQuery job errors, or quota limits.","commonSituations":"Service account lacking BigQuery jobs.create / dataset write permissions; the view's SQL referencing tables the service account cannot read; quota exceeded; destination dataset misconfigured (bigquery.view-expiration / project settings).","solutions":["Inspect the ExecutionException cause for the BigQuery job error and fix the underlying issue","Grant the service account permission to run queries and create tables in the destination dataset/project","Verify the view itself executes in the BigQuery console","Check quotas and the configured destination dataset for view materialization"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// preflight permissions for view materialization before querying\nPolicy bindings = iam.getPolicy(projectId);\nboolean canCreateTables = serviceAccountHasRoles(bindings,\n    Set.of(\"roles/bigquery.dataEditor\", \"roles/bigquery.jobUser\"));\nif (!canCreateTables) {\n    throw new IllegalStateException(\"Service account cannot create destination tables\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return query.execute();\n} catch (PrestoException e) {\n    if (BIGQUERY_VIEW_DESTINATION_TABLE_CREATION_FAILED.getCode() == e.getErrorCode().getCode()) {\n        Throwable root = e.getCause();\n        while (root.getCause() != null) root = root.getCause();\n        log.error(\"Destination table creation failed: %s\", root.getMessage());\n        // fix permissions/SQL per root cause, then retry\n    }\n    throw e;\n}","preventionTips":["Grant the service account bigquery.jobs.create and dataset write access","Verify the view runs successfully in the BigQuery console first","Set a sane view destination dataset and expiration in catalog config","Unwrap and monitor the ExecutionException cause for quota/job errors"],"tags":["bigquery","views","destination-table","permissions"],"backgroundTag":"view-materialization-failed","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"}