Skip to content

Commit

Permalink
fix(spanner): add JSON_PARSE_ARRAY to funcNames slice (#9557)
Browse files Browse the repository at this point in the history
Co-authored-by: rahul2393 <irahul@google.com>
  • Loading branch information
kai5263499 and rahul2393 authored Mar 13, 2024
1 parent 023b8dd commit f799597
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spanner/spansql/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ var funcNames = []string{
"PENDING_COMMIT_TIMESTAMP",

// JSON functions.
"JSON_QUERY",
"JSON_VALUE",
"JSON_QUERY_ARRAY",
"JSON_VALUE_ARRAY",

// Bit functions.
"BIT_COUNT",
Expand Down
45 changes: 45 additions & 0 deletions spanner/spansql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,21 @@ func TestParseDDL(t *testing.T) {
},
},
},
{`ALTER TABLE products ADD COLUMN item STRING(MAX) AS (JSON_QUERY(itemDetails, '$.itemDetails')) STORED`, &DDL{Filename: "filename", List: []DDLStmt{
&AlterTable{
Name: "products",
Alteration: AddColumn{Def: ColumnDef{
Name: "item",
Type: Type{Base: String, Len: MaxLen},
Position: line(1),
Generated: Func{
Name: "JSON_QUERY",
Args: []Expr{ID("itemDetails"), StringLiteral("$.itemDetails")},
},
}},
Position: line(1),
},
}}},
{`ALTER TABLE products ADD COLUMN item STRING(MAX) AS (JSON_VALUE(itemDetails, '$.itemDetails')) STORED`, &DDL{Filename: "filename", List: []DDLStmt{
&AlterTable{
Name: "products",
Expand All @@ -1446,6 +1461,36 @@ func TestParseDDL(t *testing.T) {
Position: line(1),
},
}}},
{`ALTER TABLE products ADD COLUMN item ARRAY<STRING(MAX)> AS (JSON_QUERY_ARRAY(itemDetails, '$.itemDetails')) STORED`, &DDL{Filename: "filename", List: []DDLStmt{
&AlterTable{
Name: "products",
Alteration: AddColumn{Def: ColumnDef{
Name: "item",
Type: Type{Base: String, Array: true, Len: MaxLen},
Position: line(1),
Generated: Func{
Name: "JSON_QUERY_ARRAY",
Args: []Expr{ID("itemDetails"), StringLiteral("$.itemDetails")},
},
}},
Position: line(1),
},
}}},
{`ALTER TABLE products ADD COLUMN item ARRAY<STRING(MAX)> AS (JSON_VALUE_ARRAY(itemDetails, '$.itemDetails')) STORED`, &DDL{Filename: "filename", List: []DDLStmt{
&AlterTable{
Name: "products",
Alteration: AddColumn{Def: ColumnDef{
Name: "item",
Type: Type{Base: String, Array: true, Len: MaxLen},
Position: line(1),
Generated: Func{
Name: "JSON_VALUE_ARRAY",
Args: []Expr{ID("itemDetails"), StringLiteral("$.itemDetails")},
},
}},
Position: line(1),
},
}}},
{
`ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)`,
&DDL{
Expand Down

0 comments on commit f799597

Please sign in to comment.