Skip to content
Permalink
Browse files
feat(spanner/spansql): support JSON data type (#4959)
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 e84e40830752fc8bc0ccdd869fa7b8fd0c80f306
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
@@ -19,6 +19,7 @@ by ascending esotericism:

- expression functions
- NUMERIC
- JSON
- more aggregation functions
- SELECT HAVING
- more literal types
@@ -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 }
*/
@@ -322,6 +322,8 @@ func (tb TypeBase) SQL() string {
return "DATE"
case Timestamp:
return "TIMESTAMP"
case JSON:
return "JSON"
}
panic("unknown TypeBase")
}
@@ -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<STRING(MAX)>,
Cl TIMESTAMP OPTIONS (allow_commit_timestamp = null),
Cm INT64 AS (CHAR_LENGTH(Ce)) STORED,
Cn JSON,
) PRIMARY KEY(Ca, Cb DESC)`,
reparseDDL,
},
@@ -387,6 +387,7 @@ const (
Bytes
Date
Timestamp
JSON
)

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

0 comments on commit e84e408

Please sign in to comment.