Skip to content

Commit 66eeb16

Browse files
committed
rowenc: rename DatumToEncDatum methods
This commit does the following renaming: - `DatumToEncDatumEx` -> `DatumToEncDatum` - `DatumToEncDatum` -> `DatumToEncDatumUnsafe`. The goal is to encourage usage of safer version which requires explicit error handling (as opposed to panicking). The main use case (apart from tests) for the unsafe version has been documented. Release note: None
1 parent c0aab48 commit 66eeb16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+143
-141
lines changed

pkg/backup/generative_split_and_scatter_processor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ func routingDatumsForSQLInstance(
253253
sqlInstanceID base.SQLInstanceID,
254254
) (rowenc.EncDatum, rowenc.EncDatum) {
255255
routingBytes := roachpb.Key(fmt.Sprintf("node%d", sqlInstanceID))
256-
startDatum := rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes)))
257-
endDatum := rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes.Next())))
256+
startDatum := rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes)))
257+
endDatum := rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes.Next())))
258258
return startDatum, endDatum
259259
}
260260

@@ -399,7 +399,7 @@ func (gssp *generativeSplitAndScatterProcessor) Next() (
399399

400400
row := rowenc.EncDatumRow{
401401
routingDatum,
402-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(entryBytes))),
402+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(entryBytes))),
403403
}
404404
return row, nil
405405
}

pkg/ccl/changefeedccl/avro/avro.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ func (r *DataRecord) rowFromNative(native interface{}) (rowenc.EncDatumRow, erro
995995
if err != nil {
996996
return nil, err
997997
}
998-
row[r.colIdxByFieldIdx[fieldIdx]], err = rowenc.DatumToEncDatumEx(field.typ, decoded)
998+
row[r.colIdxByFieldIdx[fieldIdx]], err = rowenc.DatumToEncDatum(field.typ, decoded)
999999
if err != nil {
10001000
return nil, err
10011001
}

pkg/ccl/changefeedccl/avro/avro_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func parseValues(tableDesc catalog.TableDescriptor, values string) ([]rowenc.Enc
119119
if err != nil {
120120
return nil, errors.Wrapf(err, "evaluating %s", typedExpr)
121121
}
122-
row = append(row, rowenc.DatumToEncDatum(col.GetType(), datum))
122+
row = append(row, rowenc.DatumToEncDatumUnsafe(col.GetType(), datum))
123123
}
124124
rows = append(rows, row)
125125
}
@@ -951,8 +951,8 @@ func randEncDatumRow(typ *types.T) rowenc.EncDatumRow {
951951
const notNull = false
952952
rnd, _ := randutil.NewTestRand()
953953
return rowenc.EncDatumRow{
954-
rowenc.DatumToEncDatum(typ, randgen.RandDatum(rnd, typ, allowNull)),
955-
rowenc.DatumToEncDatum(types.Int, randgen.RandDatum(rnd, types.Int, notNull)),
954+
rowenc.DatumToEncDatumUnsafe(typ, randgen.RandDatum(rnd, typ, allowNull)),
955+
rowenc.DatumToEncDatumUnsafe(types.Int, randgen.RandDatum(rnd, types.Int, notNull)),
956956
}
957957
}
958958

@@ -1059,7 +1059,7 @@ func BenchmarkEncodeDecimal(b *testing.B) {
10591059
d := &tree.DDecimal{}
10601060
coeff := int64(rand.Uint64()) % 10000
10611061
d.Decimal.SetFinite(coeff, 2)
1062-
encRow[0] = rowenc.DatumToEncDatum(typ, d)
1062+
encRow[0] = rowenc.DatumToEncDatumUnsafe(typ, d)
10631063
benchmarkEncodeType(b, typ, encRow)
10641064
}
10651065

pkg/ccl/changefeedccl/cdcevent/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func TestingMakeEventRowFromDatums(datums tree.Datums) Row {
810810
for i, d := range datums {
811811
desc.cols = append(desc.cols, ResultColumn{ord: i})
812812
desc.valueCols = append(desc.valueCols, i)
813-
encRow = append(encRow, rowenc.DatumToEncDatum(d.ResolvedType(), d))
813+
encRow = append(encRow, rowenc.DatumToEncDatumUnsafe(d.ResolvedType(), d))
814814
}
815815
return Row{
816816
EventDescriptor: &desc,

pkg/ccl/changefeedccl/encoder_protobuf_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func Test_ProtoEncoderAllTypes(t *testing.T) {
158158

159159
targets := mkTargets(tableDesc)
160160
row := cdcevent.TestingMakeEventRow(tableDesc, 0, rowenc.EncDatumRow{
161-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(1)),
162-
rowenc.DatumToEncDatum(tc.typ, tc.datum),
161+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(1)),
162+
rowenc.DatumToEncDatumUnsafe(tc.typ, tc.datum),
163163
}, false)
164164

165165
opts := changefeedbase.EncodingOptions{Envelope: changefeedbase.OptEnvelopeBare}
@@ -442,7 +442,7 @@ func Test_ProtoEncoder_Escaping(t *testing.T) {
442442

443443
targets := mkTargets(tableDesc)
444444
row := cdcevent.TestingMakeEventRow(tableDesc, 0, rowenc.EncDatumRow{
445-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(123)),
445+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(123)),
446446
}, false)
447447

448448
opts := changefeedbase.EncodingOptions{Envelope: changefeedbase.OptEnvelopeBare}
@@ -470,8 +470,8 @@ func TestProtoEncoder_BareEnvelope_WithMetadata(t *testing.T) {
470470
require.NoError(t, err)
471471

472472
encRow := rowenc.EncDatumRow{
473-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(1)),
474-
rowenc.DatumToEncDatum(types.String, tree.NewDString("Alice")),
473+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(1)),
474+
rowenc.DatumToEncDatumUnsafe(types.String, tree.NewDString("Alice")),
475475
}
476476
row := cdcevent.TestingMakeEventRow(tableDesc, 0, encRow, false)
477477

pkg/ccl/changefeedccl/kcjsonschema/kafka_connect_json_schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func parseValues(tableDesc catalog.TableDescriptor, values string) ([]rowenc.Enc
239239
if err != nil {
240240
return nil, errors.Wrapf(err, "evaluating %s", typedExpr)
241241
}
242-
row = append(row, rowenc.DatumToEncDatum(col.GetType(), datum))
242+
row = append(row, rowenc.DatumToEncDatumUnsafe(col.GetType(), datum))
243243
}
244244
rows = append(rows, row)
245245
}

pkg/crosscluster/logical/logical_replication_writer_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (lrw *logicalReplicationWriterProcessor) Next() (
376376
return nil, lrw.DrainHelper()
377377
}
378378
row := rowenc.EncDatumRow{
379-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
379+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
380380
}
381381
return row, nil
382382
} else {

pkg/crosscluster/logical/offline_initial_scan_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (o *offlineInitialScanProcessor) Next() (rowenc.EncDatumRow, *execinfrapb.P
269269
return nil, o.DrainHelper()
270270
}
271271
row := rowenc.EncDatumRow{
272-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
272+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
273273
}
274274
return row, nil
275275
}

pkg/crosscluster/physical/stream_ingestion_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (sip *streamIngestionProcessor) Next() (rowenc.EncDatumRow, *execinfrapb.Pr
532532
return nil, sip.DrainHelper()
533533
}
534534
row := rowenc.EncDatumRow{
535-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
535+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
536536
}
537537
return row, nil
538538
}

pkg/sql/cloud_check_processor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ func (p *proc) Next() (rowenc.EncDatumRow, *execinfrapb.ProducerMetadata) {
257257
return nil, p.DrainHelper()
258258
}
259259
return rowenc.EncDatumRow{
260-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(tree.DInt(p.FlowCtx.EvalCtx.NodeID.SQLInstanceID()))),
261-
rowenc.DatumToEncDatum(types.String, tree.NewDString(p.FlowCtx.EvalCtx.Locality.String())),
262-
rowenc.DatumToEncDatum(types.Bool, tree.MakeDBool(tree.DBool(res.ok))),
263-
rowenc.DatumToEncDatum(types.String, tree.NewDString(res.error)),
264-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(tree.DInt(res.readBytes))),
265-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(tree.DInt(res.readTime))),
266-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(tree.DInt(res.wroteBytes))),
267-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(tree.DInt(res.wroteTime))),
268-
rowenc.DatumToEncDatum(types.Bool, tree.MakeDBool(tree.DBool(res.canDelete))),
260+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(tree.DInt(p.FlowCtx.EvalCtx.NodeID.SQLInstanceID()))),
261+
rowenc.DatumToEncDatumUnsafe(types.String, tree.NewDString(p.FlowCtx.EvalCtx.Locality.String())),
262+
rowenc.DatumToEncDatumUnsafe(types.Bool, tree.MakeDBool(tree.DBool(res.ok))),
263+
rowenc.DatumToEncDatumUnsafe(types.String, tree.NewDString(res.error)),
264+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(tree.DInt(res.readBytes))),
265+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(tree.DInt(res.readTime))),
266+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(tree.DInt(res.wroteBytes))),
267+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(tree.DInt(res.wroteTime))),
268+
rowenc.DatumToEncDatumUnsafe(types.Bool, tree.MakeDBool(tree.DBool(res.canDelete))),
269269
}, nil
270270
}
271271
}

0 commit comments

Comments
 (0)