bigquery-emulator icon indicating copy to clipboard operation
bigquery-emulator copied to clipboard

DELETE not working on views

Open yaronneuman opened this issue 2 years ago • 2 comments

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:

  1. change func (n *DropStmtNode) FormatSQL to 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
  1. change func newNode(node ast.Node) Formatter to create DropTableStmtNode or DropViewStmtNode accordingly.

I would go with option #1 @goccy what do you think?

yaronneuman avatar May 14 '23 10:05 yaronneuman

@goccy Could you assign this to me?

ohaibbq avatar Mar 25 '24 21:03 ohaibbq