Skip to content

Commit

Permalink
feat(spanner/spansql): support JSON data type (#4959)
Browse files Browse the repository at this point in the history
Co-authored-by: Rahul Yadav <irahul@google.com>
Co-authored-by: Hengfeng Li <hengfeng@google.com>
  • Loading branch information
3 people committed Oct 8, 2021
1 parent e51aff9 commit e84e408
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
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

0 comments on commit e84e408

Please sign in to comment.