bigquery-emulator
bigquery-emulator copied to clipboard
DELETE not working on views
DELETE API should work also on views https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/delete
but
DELETE /bigquery/v2/projects/test/datasets/main/tables/my_view
response:
server/handler.go:2294 internalError {"error": "internalError: failed to delete table my_view: failed to delete table DROP TABLE `test.test.my_view`: failed to exec DROP TABLE `test.test.my_view`: use DROP VIEW to delete view test_test_my_view"}
to fix it we will need to make some changes in both bigquery-emulator and go-zetasqlite in bigquery-emulator:
func (r *Repository) DeleteTables
we can change the last argument to be tables []*metadata.Table instead of tableIDs []string
and then format the query correctly based on the metadata.Table.type
query := fmt.Sprintf("DROP %s `%s`", table.Type(), tablePath)
in zetasqllite we have two options:
- change
func (n *DropStmtNode) FormatSQLto use the node's ObjectType to format the query. like this:
if n.node.IsIfExists() {
return fmt.Sprintf("DROP %s IF EXISTS `%s`", n.node.ObjectType(), tableName), nil
}
return fmt.Sprintf("DROP %s `%s`", tableName), nil
- change
func newNode(node ast.Node) Formatterto create DropTableStmtNode or DropViewStmtNode accordingly.
I would go with option #1 @goccy what do you think?
@goccy Could you assign this to me?