Skip to content

Commit 5aa4b8f

Browse files
craig[bot]yuzefovich
andcommitted
150454: tree: clean up DOidWrapper usage r=yuzefovich a=yuzefovich This PR cleans up usage of `DOidWrapper` utility. Throughout the years we've accumulated some dead code as well as in many cases we had blind copy-paste of unnecessary code, and this PR gets rid of it. Namely, `DOidWrapper` utility is now used to support `DName` and `DRefCursor` (on top of `DString`) and `DCIText` (on top of `DCollatedString`), and any other usages are forbidden. This PR removes all those other usages. Please see each commit for more details. Epic: None 152765: sql: replace a few context.Background() with what we have in scope r=yuzefovich a=yuzefovich **sql: remove no longer used StubTableStats function** **sql: replace a few context.Background() with what we have in scope** I was looking into a timeout where we seemingly didn't respect the context cancellation and noticed a couple of places where we use `context.Backround()` that were easy to fix. Touches: #152417. Epic: None 153168: colcontainer: harden closing of files in diskQueue r=yuzefovich a=yuzefovich The AI review of 31c3419 pointed out that `io.Closer` interface is such that calling `Close` multiple times can result in an undefined behavior. Previously, we had multiple places where if we got an error on the first `Close` call of read or write file of the disk queue, we could try to close the same file again - this was the case since we nil-ed out the file pointer after the error short-circuiting logic. This commit hardens the disk queue around this error to guarantee that we always close the file exactly once. This also allows us to remove some of explicit nilling out logic which now became redundant. It's not immediately clear to me what actual "undefined behavior" would be in case of double-`Close` (or if it's even possible for implementations that we use to return an error), so I didn't include a release note. Still, it seems prudent to follow the interface's contract. Epic: None Release note: None 153176: sql/parser: fix minor issue with recent LTREE additions r=yuzefovich a=yuzefovich We recently added parser support for FIRST_CONTAINS and FIRST_CONTAINED_BY operators (`?`@>`` and `?<`@`` respectively). The AI review pointed out a minor bug in how we handle these operators in the scanner - we incorrectly advanced the position unconditionally before matching the following characters. Instead, we need to use `peekN` to look a few characters ahead to see whether we have a match, and this commit does that. Note that the impact of the bug is very minor - we simply would put the `^` character in the error in the wrong position. Note that two newly-added tests have slightly different behavior with regards to the `^` character which seems to be due to peculiarities of the tokenizing / parsing that I didn't look closely into. Additionally, this commit adds a newline character in an unrelated parser test file. Epic: None Release note: None 153327: importer: simplify MakeTestingSimpleTableDescriptor r=yuzefovich a=yuzefovich We no longer need any FK handling in this function, which allows us to remove some dead code. Also update error messages to not reference no longer open issues. Epic: None Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]>
6 parents 8fecc51 + 811f49f + 6bd0cd6 + 8aaf90c + 5116dd2 + db4b651 commit 5aa4b8f

Some content is hidden

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

50 files changed

+286
-826
lines changed

pkg/backup/compaction_job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ func maybeStartCompactionJob(
161161
if err != nil {
162162
return err
163163
}
164-
idDatum, ok := tree.AsDInt(datums[0])
164+
idDatum, ok := datums[0].(*tree.DInt)
165165
if !ok {
166166
return errors.Newf("expected job ID: unexpected result type %T", datums[0])
167167
}
168-
jobID = jobspb.JobID(idDatum)
168+
jobID = jobspb.JobID(*idDatum)
169169

170170
scheduledJob := jobs.ScheduledJobTxn(txn)
171171
backupSchedule, args, err := getScheduledBackupExecutionArgsFromSchedule(

pkg/backup/schedule_exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@ func getBackupFnTelemetry(
544544
return jobspb.BackupDetails{}, errors.New("expected job ID as first column of result")
545545
}
546546

547-
jobID, ok := tree.AsDInt(jobIDDatum)
547+
jobID, ok := jobIDDatum.(*tree.DInt)
548548
if !ok {
549549
return jobspb.BackupDetails{}, errors.New("expected job ID as first column of result")
550550
}
551551

552-
job, err := registry.LoadJobWithTxn(ctx, jobspb.JobID(jobID), txn)
552+
job, err := registry.LoadJobWithTxn(ctx, jobspb.JobID(*jobID), txn)
553553
if err != nil {
554554
return jobspb.BackupDetails{}, errors.Wrap(err, "failed to load dry-run backup job")
555555
}

pkg/ccl/changefeedccl/avro/avro.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,11 @@ func typeToSchema(typ *types.T) (*SchemaField, error) {
450450
setNullable(
451451
SchemaTypeString,
452452
func(d tree.Datum, _ interface{}) (interface{}, error) {
453-
return string(*d.(*tree.DString)), nil
453+
s, ok := tree.AsDString(d)
454+
if !ok {
455+
return nil, errors.Newf("expected string type, got %T", d)
456+
}
457+
return string(s), nil
454458
},
455459
func(x interface{}) (tree.Datum, error) {
456460
return tree.NewDString(x.(string)), nil
@@ -460,7 +464,11 @@ func typeToSchema(typ *types.T) (*SchemaField, error) {
460464
setNullable(
461465
SchemaTypeString,
462466
func(d tree.Datum, _ interface{}) (interface{}, error) {
463-
return d.(*tree.DCollatedString).Contents, nil
467+
cs, ok := tree.AsDCollatedString(d)
468+
if !ok {
469+
return nil, errors.Newf("expected collated string type, got %T", d)
470+
}
471+
return cs.Contents, nil
464472
},
465473
func(x interface{}) (tree.Datum, error) {
466474
return tree.NewDCollatedString(x.(string), typ.Locale(), &tree.CollationEnvironment{})

pkg/ccl/changefeedccl/avro/avro_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func parseTableDesc(createTableStmt string) (catalog.TableDescriptor, error) {
7272
tableID := descpb.ID(bootstrap.TestingUserDescID(1))
7373
semaCtx := makeTestSemaCtx()
7474
mutDesc, err := importer.MakeTestingSimpleTableDescriptor(
75-
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, importer.NoFKs, timeutil.Now().UnixNano())
75+
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, timeutil.Now().UnixNano(),
76+
)
7677
if err != nil {
7778
return nil, err
7879
}

pkg/ccl/changefeedccl/encoder_json_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ func parseTableDesc(createTableStmt string) (catalog.TableDescriptor, error) {
342342
tableID := descpb.ID(bootstrap.TestingUserDescID(1))
343343
semaCtx := makeTestSemaCtx()
344344
mutDesc, err := importer.MakeTestingSimpleTableDescriptor(
345-
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, importer.NoFKs, timeutil.Now().UnixNano())
345+
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, timeutil.Now().UnixNano(),
346+
)
346347
if err != nil {
347348
return nil, err
348349
}

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/ccl/changefeedccl/event_processing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ func readOneJSONValue(row cdcevent.Row, colName string) (*tree.DJSON, error) {
825825
if d == tree.DNull {
826826
return nil
827827
}
828-
if valJSON, ok = tree.AsDJSON(d); !ok {
828+
if valJSON, ok = d.(*tree.DJSON); !ok {
829829
return errors.Newf("expected a JSON object, got %s", d.ResolvedType())
830830
}
831831
return nil

pkg/ccl/changefeedccl/kcjsonschema/kafka_connect_json_schema_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ func parseTableDesc(createTableStmt string) (catalog.TableDescriptor, error) {
183183
tableID := descpb.ID(bootstrap.TestingUserDescID(1))
184184
semaCtx := makeTestSemaCtx()
185185
mutDesc, err := importer.MakeTestingSimpleTableDescriptor(
186-
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, importer.NoFKs, timeutil.Now().UnixNano())
186+
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, timeutil.Now().UnixNano(),
187+
)
187188
if err != nil {
188189
return nil, err
189190
}

pkg/ccl/partitionccl/zone_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ func (pt partitioningTest) parse() (parsed parsedPartitioningTest, _ error) {
358358
st := cluster.MakeTestingClusterSettings()
359359
parentID, tableID := descpb.ID(bootstrap.TestingUserDescID(0)), descpb.ID(bootstrap.TestingUserDescID(1))
360360
mutDesc, err := importer.MakeTestingSimpleTableDescriptor(
361-
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, importer.NoFKs, timeutil.Now().UnixNano())
361+
ctx, &semaCtx, st, createTable, parentID, keys.PublicSchemaID, tableID, timeutil.Now().UnixNano(),
362+
)
362363
if err != nil {
363364
return parsed, err
364365
}

pkg/cmd/smith/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ func parseSchemaDefinition(schemaPath string) (opts []sqlsmith.SmitherOption, _
236236
case *tree.CreateTable:
237237
tableID := descpb.ID(int(parentID) + i + 1)
238238
desc, err := importer.MakeTestingSimpleTableDescriptor(
239-
context.Background(), &semaCtx, st, t, parentID, keys.PublicSchemaID, tableID, importer.NoFKs, wall)
239+
context.Background(), &semaCtx, st, t, parentID, keys.PublicSchemaID, tableID, wall,
240+
)
240241
if err != nil {
241242
return nil, errors.Wrapf(err, "failed to create table descriptor for statement %s", t)
242243
}

0 commit comments

Comments
 (0)