diff --git a/spanner/spannertest/README.md b/spanner/spannertest/README.md index a1c3a821abf..d7504fd2af3 100644 --- a/spanner/spannertest/README.md +++ b/spanner/spannertest/README.md @@ -19,6 +19,7 @@ by ascending esotericism: - expression functions - NUMERIC +- JSON - more aggregation functions - SELECT HAVING - more literal types diff --git a/spanner/spansql/parser.go b/spanner/spansql/parser.go index 6b3293069dd..f69ee620cc3 100644 --- a/spanner/spansql/parser.go +++ b/spanner/spansql/parser.go @@ -1890,6 +1890,7 @@ var baseTypes = map[string]TypeBase{ "BYTES": Bytes, "DATE": Date, "TIMESTAMP": Timestamp, + "JSON": JSON, } func (p *parser) parseType() (Type, *parseError) { @@ -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 } */ diff --git a/spanner/spansql/sql.go b/spanner/spansql/sql.go index 859c08afae3..5032b57ad99 100644 --- a/spanner/spansql/sql.go +++ b/spanner/spansql/sql.go @@ -322,6 +322,8 @@ func (tb TypeBase) SQL() string { return "DATE" case Timestamp: return "TIMESTAMP" + case JSON: + return "JSON" } panic("unknown TypeBase") } diff --git a/spanner/spansql/sql_test.go b/spanner/spansql/sql_test.go index 28897490bd7..9f3b13d45b4 100644 --- a/spanner/spansql/sql_test.go +++ b/spanner/spansql/sql_test.go @@ -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"}, @@ -105,6 +106,7 @@ func TestSQL(t *testing.T) { Ck ARRAY, Cl TIMESTAMP OPTIONS (allow_commit_timestamp = null), Cm INT64 AS (CHAR_LENGTH(Ce)) STORED, + Cn JSON, ) PRIMARY KEY(Ca, Cb DESC)`, reparseDDL, }, diff --git a/spanner/spansql/types.go b/spanner/spansql/types.go index da592532b3b..86b98f4d189 100644 --- a/spanner/spansql/types.go +++ b/spanner/spansql/types.go @@ -387,6 +387,7 @@ const ( Bytes Date Timestamp + JSON ) // KeyPart represents a column specification as part of a primary key or index definition.