bigquery-emulator
bigquery-emulator copied to clipboard
Syntax error: Unexpected keyword END when field name on nested table is named "end"
What happened?
I am getting the following error when trying to create the following table on the database using bigquery.InferSchema:
type Schema struct {
Foo string
Period struct {
Bar string
Date time.Time `bigquery:"end"`
}
}
emulator error:
2025-04-23T12:40:02.975Z ERROR server/handler.go:2548 internalError {"error": "internalError: failed to create table CREATE TABLE `project.abcd` (`Foo` STRING,`Period` STRUCT<Bar STRING,end TIMESTAMP>): failed to parse statements: failed to parse statement: INVALID_ARGUMENT: Syntax error: Unexpected keyword END [type.googleapis.com/zetasql.ErrorLocation='\\x08\\x01\\x10h']"}
What did you expect to happen?
Table to be created.
How can we reproduce it (as minimally and precisely as possible)?
c, err := bigquery.NewClient(ctx, project, option.WithEndpoint("http://0.0.0.0:9050"), option.WithoutAuthentication())
if err != nil {
return nil, err
}
schema, err := bigquery.InferSchema(Schema{})
if err != nil {
return nil, err
}
fmt.Println(ds.Table("abcd").Create(ctx, &bigquery.TableMetadata{
Name: "abcd",
Schema: schema,
}))
Anything else we need to know?
#397 also happened with me on code very similar to this one, but I don't have it here any longer to reproduce it there. Just adding this for context as it might help.
A fix for using reserved keywords as struct keys has been implemented and released in the Recidiviz fork of the emulator https://github.com/Recidiviz/bigquery-emulator/releases/tag/v0.6.6-recidiviz.0