Skip to content

Commit

Permalink
sql: Enable the decoding of single-column family arrays
Browse files Browse the repository at this point in the history
I'm actually surprised this hasn't been tested before.  The decoding method
was just outright missing.

Fixes #36477

Release note: None
  • Loading branch information
BramGruneir committed Apr 8, 2019
1 parent 38783c7 commit 44cd40b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
49 changes: 49 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/array
Original file line number Diff line number Diff line change
Expand Up @@ -1224,3 +1224,52 @@ query B
SELECT ARRAY[''] = ARRAY[] FROM (VALUES (1)) WHERE ARRAY[B''] != ARRAY[]
----
false

subtest 36477

statement ok
CREATE TABLE array_single_family (a INT PRIMARY KEY, b INT[], FAMILY fam0(a), FAMILY fam1(b))

statement ok
INSERT INTO array_single_family VALUES(0,ARRAY[])

statement ok
INSERT INTO array_single_family VALUES(1,ARRAY[1])

statement ok
INSERT INTO array_single_family VALUES(2,ARRAY[1,2])

statement ok
INSERT INTO array_single_family VALUES(3,ARRAY[1,2,NULL])

statement ok
INSERT INTO array_single_family VALUES(4,ARRAY[NULL,2,3])

statement ok
INSERT INTO array_single_family VALUES(5,ARRAY[1,NULL,3])

statement ok
INSERT INTO array_single_family VALUES(6,ARRAY[NULL::INT])

statement ok
INSERT INTO array_single_family VALUES(7,ARRAY[NULL::INT,NULL::INT])

statement ok
INSERT INTO array_single_family VALUES(8,ARRAY[NULL::INT,NULL::INT,NULL::INT])

query IT colnames
SELECT a, b FROM array_single_family ORDER BY a
----
a b
0 {}
1 {1}
2 {1,2}
3 {1,2,NULL}
4 {NULL,2,3}
5 {1,NULL,3}
6 {NULL}
7 {NULL,NULL}
8 {NULL,NULL,NULL}

statement ok
DROP TABLE array_single_family
16 changes: 16 additions & 0 deletions pkg/sql/sqlbase/column_type_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,14 @@ func UnmarshalColumnValue(a *DatumAlloc, typ ColumnType, value roachpb.Value) (t
return nil, err
}
return a.NewDOid(tree.MakeDOid(tree.DInt(v))), nil
case ColumnType_ARRAY:
v, err := value.GetBytes()
if err != nil {
return nil, err
}
elementType := columnSemanticTypeToDatumType(&ColumnType{}, *typ.ArrayContents)
datum, _, err := decodeArrayNoMarshalColumnValue(a, elementType, v)
return datum, err
default:
return nil, errors.Errorf("unsupported column type: %s", typ.SemanticType)
}
Expand Down Expand Up @@ -922,6 +930,14 @@ func decodeArray(a *DatumAlloc, elementType types.T, b []byte) (tree.Datum, []by
if err != nil {
return nil, b, err
}
return decodeArrayNoMarshalColumnValue(a, elementType, b)
}

// decodeArrayNoMarshalColumnValue skips the step where the MarshalColumnValue
// is stripped from the bytes. This is required for single-column family arrays.
func decodeArrayNoMarshalColumnValue(
a *DatumAlloc, elementType types.T, b []byte,
) (tree.Datum, []byte, error) {
header, b, err := decodeArrayHeader(b)
if err != nil {
return nil, b, err
Expand Down

0 comments on commit 44cd40b

Please sign in to comment.