Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spanner/spansql): support JSON data type #4959

Merged
merged 2 commits into from Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions spanner/spannertest/README.md
Expand Up @@ -19,6 +19,7 @@ by ascending esotericism:

- expression functions
- NUMERIC
- JSON
- more aggregation functions
- SELECT HAVING
- more literal types
Expand Down
3 changes: 2 additions & 1 deletion spanner/spansql/parser.go
Expand Up @@ -1890,6 +1890,7 @@ var baseTypes = map[string]TypeBase{
"BYTES": Bytes,
"DATE": Date,
"TIMESTAMP": Timestamp,
"JSON": JSON,
}

func (p *parser) parseType() (Type, *parseError) {
Expand All @@ -1900,7 +1901,7 @@ func (p *parser) parseType() (Type, *parseError) {
ARRAY< scalar_type >

scalar_type:
{ BOOL | INT64 | FLOAT64 | NUMERIC | STRING( length ) | BYTES( length ) | DATE | TIMESTAMP }
{ BOOL | INT64 | FLOAT64 | NUMERIC | STRING( length ) | BYTES( length ) | DATE | TIMESTAMP | JSON }
length:
{ int64_value | MAX }
*/
Expand Down
2 changes: 2 additions & 0 deletions spanner/spansql/sql.go
Expand Up @@ -322,6 +322,8 @@ func (tb TypeBase) SQL() string {
return "DATE"
case Timestamp:
return "TIMESTAMP"
case JSON:
return "JSON"
}
panic("unknown TypeBase")
}
Expand Down
2 changes: 2 additions & 0 deletions spanner/spansql/sql_test.go
Expand Up @@ -84,6 +84,7 @@ func TestSQL(t *testing.T) {
{Name: "Ck", Type: Type{Array: true, Base: String, Len: MaxLen}, Position: line(12)},
{Name: "Cl", Type: Type{Base: Timestamp}, Options: ColumnOptions{AllowCommitTimestamp: boolAddr(false)}, Position: line(13)},
{Name: "Cm", Type: Type{Base: Int64}, Generated: Func{Name: "CHAR_LENGTH", Args: []Expr{ID("Ce")}}, Position: line(14)},
{Name: "Cn", Type: Type{Base: JSON}, Position: line(15)},
},
PrimaryKey: []KeyPart{
{Column: "Ca"},
Expand All @@ -105,6 +106,7 @@ func TestSQL(t *testing.T) {
Ck ARRAY<STRING(MAX)>,
Cl TIMESTAMP OPTIONS (allow_commit_timestamp = null),
Cm INT64 AS (CHAR_LENGTH(Ce)) STORED,
Cn JSON,
) PRIMARY KEY(Ca, Cb DESC)`,
reparseDDL,
},
Expand Down
1 change: 1 addition & 0 deletions spanner/spansql/types.go
Expand Up @@ -387,6 +387,7 @@ const (
Bytes
Date
Timestamp
JSON
)

// KeyPart represents a column specification as part of a primary key or index definition.
Expand Down