Skip to content

Commit 07cf6b2

Browse files
committed
util/parquet,sql: clean up DOidWrapper handling a bit
This commit removes redundant branch for `DOidWrapper` in `encodeArrayElement` (we already do the unwrapping at the top of the function, so this was dead code) as well as replaces the custom unwrap function in `parquet` package with the exported one. It also replaces some other unwrappers with that exported function. Release note: None
1 parent c40d1e9 commit 07cf6b2

File tree

7 files changed

+7
-29
lines changed

7 files changed

+7
-29
lines changed

pkg/sql/colconv/datum_to_vec.eg.go

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/colexec/execgen/cmd/execgen/rowtovec_gen.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ type familyWidthPair struct {
6969

7070
var rowToVecPreludeTmpls = map[familyWidthPair]string{
7171
{types.StringFamily, anyWidth}: `// Handle other STRING-related OID types, like oid.T_name.
72-
wrapper, ok := %[1]s.(*tree.DOidWrapper)
73-
if ok {
74-
%[1]s = wrapper.Wrapped
75-
}`,
72+
%[1]s = tree.UnwrapDOidWrapper(%[1]s)`,
7673
}
7774

7875
// rowToVecConversionTmpls maps the type families to the corresponding

pkg/sql/colexec/rowtovec.eg.go

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/opt/norm/scalar_funcs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ func (c *CustomFuncs) ConvertConstArrayToTuple(arr *memo.ConstExpr) opt.ScalarEx
245245
// collated string constant with the given locale.
246246
func (c *CustomFuncs) CastToCollatedString(str opt.ScalarExpr, locale string) opt.ScalarExpr {
247247
datum := str.(*memo.ConstExpr).Value
248-
if wrap, ok := datum.(*tree.DOidWrapper); ok {
249-
datum = wrap.Wrapped
250-
}
248+
datum = tree.UnwrapDOidWrapper(datum)
251249

252250
// buildCollated is a recursive helper function to handle casting arrays.
253251
var buildCollated func(datum tree.Datum) tree.Datum

pkg/sql/rowenc/valueside/array.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ func encodeArrayElement(b []byte, d tree.Datum) ([]byte, error) {
336336
return encoding.EncodeUntaggedIntValue(b, int64(t.Oid)), nil
337337
case *tree.DCollatedString:
338338
return encoding.EncodeUntaggedBytesValue(b, []byte(t.Contents)), nil
339-
case *tree.DOidWrapper:
340-
return encodeArrayElement(b, t.Wrapped)
341339
case *tree.DEnum:
342340
return encoding.EncodeUntaggedBytesValue(b, t.PhysicalRep), nil
343341
case *tree.DJSON:

pkg/sql/stats/automatic_stats_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ func TestAnalyzeSystemTables(t *testing.T) {
903903
return descpb.ID(tableID)
904904
}
905905
for _, row := range rows {
906-
tableName := string(*row[0].(*tree.DOidWrapper).Wrapped.(*tree.DString))
906+
tableName := string(*tree.UnwrapDOidWrapper(row[0]).(*tree.DString))
907907
if DisallowedOnSystemTable(getTableID(tableName)) {
908908
continue
909909
}

pkg/util/parquet/testutils.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,6 @@ func decodeValuesIntoDatumsHelper(
362362
}
363363
}
364364

365-
func unwrapDatum(d tree.Datum) tree.Datum {
366-
switch t := d.(type) {
367-
case *tree.DOidWrapper:
368-
return unwrapDatum(t.Wrapped)
369-
default:
370-
return d
371-
}
372-
}
373-
374365
// ValidateDatum validates that the "contents" of the expected datum matches the
375366
// contents of the actual datum. For example, when validating two arrays, we
376367
// only compare the datums in the arrays. We do not compare CRDB-specific
@@ -384,8 +375,8 @@ func ValidateDatum(t *testing.T, expected tree.Datum, actual tree.Datum) {
384375
// The randgen library may generate datums wrapped in a *tree.DOidWrapper, so
385376
// we should unwrap them. We unwrap at this stage as opposed to when
386377
// generating datums to test that the writer can handle wrapped datums.
387-
expected = unwrapDatum(expected)
388-
actual = unwrapDatum(actual)
378+
expected = tree.UnwrapDOidWrapper(expected)
379+
actual = tree.UnwrapDOidWrapper(actual)
389380

390381
switch expected.ResolvedType().Family() {
391382
case types.JsonFamily:

0 commit comments

Comments
 (0)