Skip to content

Commit 87f21b0

Browse files
committed
tree: remove DOidWrapper support for DArrays
Long time ago we implemented `int2vector` and `oidvector` types using DOidWrapper around the arrays. Some time later, but also long time ago in 3f4d1a0 we removed those usages by pushing the "custom" Oid directly into DArray datum, which made the code for supporting DOidWrapper for arrays redundant. This commit removes that dead code as well as `AsDArray` function in favor of explicit type cast. Release note: None
1 parent 8b1e1a9 commit 87f21b0

File tree

6 files changed

+15
-30
lines changed

6 files changed

+15
-30
lines changed

pkg/ccl/changefeedccl/encoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ func TestJsonRountrip(t *testing.T) {
12841284
// In this case, we can just compare strings.
12851285
if isFloatOrDecimal(test.datum.ResolvedType()) {
12861286
require.Equal(t, d.String(), j.String())
1287-
} else if dArr, ok := tree.AsDArray(test.datum); ok && isFloatOrDecimal(dArr.ParamTyp) {
1287+
} else if dArr, ok := test.datum.(*tree.DArray); ok && isFloatOrDecimal(dArr.ParamTyp) {
12881288
require.Equal(t, d.String(), j.String())
12891289
} else {
12901290
cmp, err := d.Compare(j)

pkg/server/admin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,7 +3529,7 @@ func (rs resultScanner) ScanIndex(row tree.Datums, index int, dst interface{}) e
35293529
*d = &val
35303530

35313531
case *[]int64:
3532-
s, ok := tree.AsDArray(src)
3532+
s, ok := src.(*tree.DArray)
35333533
if !ok {
35343534
return errors.Errorf("source type assertion failed")
35353535
}
@@ -3542,7 +3542,7 @@ func (rs resultScanner) ScanIndex(row tree.Datums, index int, dst interface{}) e
35423542
}
35433543

35443544
case *[]descpb.ID:
3545-
s, ok := tree.AsDArray(src)
3545+
s, ok := src.(*tree.DArray)
35463546
if !ok {
35473547
return errors.Errorf("source type assertion failed")
35483548
}

pkg/sql/sem/builtins/builtins.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,7 +5734,7 @@ DO NOT USE -- USE 'CREATE VIRTUAL CLUSTER' INSTEAD`,
57345734
}
57355735
descIDMightExist := func(id descpb.ID) bool { return true }
57365736
if args[1] != tree.DNull {
5737-
descIDs, ok := tree.AsDArray(args[1])
5737+
descIDs, ok := args[1].(*tree.DArray)
57385738
if !ok {
57395739
return nil, errors.Newf("expected array value, got %T", args[1])
57405740
}
@@ -5753,7 +5753,7 @@ DO NOT USE -- USE 'CREATE VIRTUAL CLUSTER' INSTEAD`,
57535753
}
57545754
nonTerminalJobIDMightExist := func(id jobspb.JobID) bool { return true }
57555755
if args[2] != tree.DNull {
5756-
jobIDs, ok := tree.AsDArray(args[2])
5756+
jobIDs, ok := args[2].(*tree.DArray)
57575757
if !ok {
57585758
return nil, errors.Newf("expected array value, got %T", args[2])
57595759
}
@@ -5775,7 +5775,7 @@ DO NOT USE -- USE 'CREATE VIRTUAL CLUSTER' INSTEAD`,
57755775
return true
57765776
}
57775777
if args[3] != tree.DNull {
5778-
roles, ok := tree.AsDArray(args[3])
5778+
roles, ok := args[3].(*tree.DArray)
57795779
if !ok {
57805780
return nil, errors.Newf("expected array value, got %T", args[3])
57815781
}
@@ -11410,7 +11410,7 @@ func arrayLength(arr *tree.DArray, dim int64) tree.Datum {
1141011410
if dim == 1 {
1141111411
return tree.NewDInt(tree.DInt(arr.Len()))
1141211412
}
11413-
a, ok := tree.AsDArray(arr.Array[0])
11413+
a, ok := arr.Array[0].(*tree.DArray)
1141411414
if !ok {
1141511415
return tree.DNull
1141611416
}
@@ -11426,7 +11426,7 @@ func arrayLower(arr *tree.DArray, dim int64) tree.Datum {
1142611426
if dim == 1 {
1142711427
return intOne
1142811428
}
11429-
a, ok := tree.AsDArray(arr.Array[0])
11429+
a, ok := arr.Array[0].(*tree.DArray)
1143011430
if !ok {
1143111431
return tree.DNull
1143211432
}

pkg/sql/sem/eval/comparison.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func ComparisonExprWithSubOperator(
2626
return tree.DNull, nil
2727
} else if tuple, ok := tree.AsDTuple(right); ok {
2828
datums = tuple.D
29-
} else if array, ok := tree.AsDArray(right); ok {
29+
} else if array, ok := right.(*tree.DArray); ok {
3030
datums = array.Array
3131
} else {
3232
return nil, errors.AssertionFailedf("unhandled right expression %s", right)

pkg/sql/sem/tree/datum.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5121,24 +5121,10 @@ func NewDArrayFromDatums(paramTyp *types.T, datums Datums) *DArray {
51215121
return d
51225122
}
51235123

5124-
// AsDArray attempts to retrieve a *DArray from an Expr, returning a *DArray and
5125-
// a flag signifying whether the assertion was successful. The function should
5126-
// be used instead of direct type assertions wherever a *DArray wrapped by a
5127-
// *DOidWrapper is possible.
5128-
func AsDArray(e Expr) (*DArray, bool) {
5129-
switch t := e.(type) {
5130-
case *DArray:
5131-
return t, true
5132-
case *DOidWrapper:
5133-
return AsDArray(t.Wrapped)
5134-
}
5135-
return nil, false
5136-
}
5137-
51385124
// MustBeDArray attempts to retrieve a *DArray from an Expr, panicking if the
51395125
// assertion fails.
51405126
func MustBeDArray(e Expr) *DArray {
5141-
i, ok := AsDArray(e)
5127+
i, ok := e.(*DArray)
51425128
if !ok {
51435129
panic(errors.AssertionFailedf("expected *DArray, found %T", e))
51445130
}
@@ -6024,14 +6010,13 @@ func wrapWithOid(d Datum, oid oid.Oid) Datum {
60246010
case *DInt:
60256011
case *DString:
60266012
case *DCollatedString:
6027-
case *DArray:
60286013
case dNull, *DOidWrapper:
60296014
panic(errors.AssertionFailedf("cannot wrap %T with an Oid", v))
60306015
default:
6031-
// Currently only *DInt, *DString, *DCollatedString, *DArray are hooked up to work with
6032-
// *DOidWrapper. To support another base Datum type, replace all type
6033-
// assertions to that type with calls to functions like AsDInt and
6034-
// MustBeDInt.
6016+
// Currently only *DInt, *DString, and *DCollatedString are hooked up to
6017+
// work with *DOidWrapper. To support another base Datum type, replace
6018+
// all type assertions to that type with calls to functions like AsDInt
6019+
// and MustBeDInt.
60356020
panic(errors.AssertionFailedf("unsupported Datum type passed to wrapWithOid: %T", d))
60366021
}
60376022
return &DOidWrapper{

pkg/util/parquet/write_functions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func writeArray(d tree.Datum, w file.ColumnChunkWriter, a *batchAlloc, wFn write
181181
if d == tree.DNull {
182182
return wFn(tree.DNull, w, a, nilArrayDefLevel, newEntryRepLevel)
183183
}
184-
di, ok := tree.AsDArray(d)
184+
di, ok := d.(*tree.DArray)
185185
if !ok {
186186
return pgerror.Newf(pgcode.DatatypeMismatch, "expected DArray, found %T", d)
187187
}

0 commit comments

Comments
 (0)