Skip to content

Commit

Permalink
deflake tests 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanbenschoten committed Dec 20, 2023
1 parent ca1f198 commit 8a70b72
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 46 deletions.
4 changes: 2 additions & 2 deletions pkg/ccl/streamingccl/streamingest/alter_replication_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func evalTenantReplicationOptions(
r.retention = &retSeconds
}
if options.ResumeTimestamp != nil {
ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.ResumeTimestamp, op, asof.ReplicationCutover)
ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.ResumeTimestamp, op)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func alterReplicationJobHook(
}

ct, err := asof.EvalSystemTimeExpr(ctx, evalCtx, p.SemaCtx(), alterTenantStmt.Cutover.Timestamp,
alterReplicationJobOp, asof.ReplicationCutover)
alterReplicationJobOp)
if err != nil {
return nil, nil, nil, false, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/as_of
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ SELECT * FROM t AS OF SYSTEM TIME follower_read_timestamp('boom')
statement error pq: AS OF SYSTEM TIME: only constant expressions, with_min_timestamp, with_max_staleness, or follower_read_timestamp are allowed
SELECT * FROM t AS OF SYSTEM TIME now()

statement error pq: AS OF SYSTEM TIME: interval value '10s' too large, AS OF interval must be <= -1µs
statement error pq: request timestamp .* too far in future
SELECT * FROM t AS OF SYSTEM TIME '10s'

statement error pq: AS OF SYSTEM TIME: interval value '00:00:00.000001' too large, AS OF interval must be <= -1µs
statement ok
SELECT * FROM t AS OF SYSTEM TIME interval '1 microsecond'

# Verify that the TxnTimestamp used to generate now() and current_timestamp() is
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/pgwire/testdata/pgtest/bind_and_resolve
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ReadyForQuery

# This is crdb_only because Postgres does not support AS OF SYSTEM TIME.
send crdb_only
Query {"String": "BEGIN AS OF SYSTEM TIME '1s'"}
Query {"String": "BEGIN AS OF SYSTEM TIME '0s'"}
Sync
----

Expand Down
38 changes: 2 additions & 36 deletions pkg/sql/sem/asof/as_of.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,41 +202,16 @@ func Eval(
}

stmtTimestamp := evalCtx.GetStmtTimestamp()
ret.Timestamp, err = DatumToHLC(evalCtx, stmtTimestamp, d, AsOf)
ret.Timestamp, err = DatumToHLC(evalCtx, stmtTimestamp, d)
if err != nil {
return eval.AsOfSystemTime{}, errors.Wrap(err, "AS OF SYSTEM TIME")
}
return ret, nil
}

// DatumToHLCUsage specifies which statement DatumToHLC() is used for.
type DatumToHLCUsage int64

const (
// AsOf is when the DatumToHLC() is used for an AS OF SYSTEM TIME statement.
// In this case, if the interval is not synthetic, its value has to be negative
// and last longer than a nanosecond.
AsOf DatumToHLCUsage = iota
// Split is when the DatumToHLC() is used for a SPLIT statement.
// In this case, if the interval is not synthetic, its value has to be positive
// and last longer than a nanosecond.
Split

// ReplicationCutover is when the DatumToHLC() is used for an
// ALTER VIRTUAL CLUSTER ... COMPLETE REPLICATION statement.
ReplicationCutover

// ShowTenantFingerprint is when the DatumToHLC() is used for an SHOW
// EXPERIMENTAL_FINGERPRINTS FROM TENANT ... WITH START TIMESTAMP statement.
//
// ShowTenantFingerprint has the same constraints as AsOf, and so we use the
// same value.
ShowTenantFingerprint = AsOf
)

// DatumToHLC performs the conversion from a Datum to an HLC timestamp.
func DatumToHLC(
evalCtx *eval.Context, stmtTimestamp time.Time, d tree.Datum, usage DatumToHLCUsage,
evalCtx *eval.Context, stmtTimestamp time.Time, d tree.Datum,
) (hlc.Timestamp, error) {
ts := hlc.Timestamp{}
var convErr error
Expand All @@ -257,10 +232,6 @@ func DatumToHLC(
if iv, err := tree.ParseDInterval(evalCtx.GetIntervalStyle(), s); err == nil {
if (iv.Duration == duration.Duration{}) {
convErr = errors.Errorf("interval value %v too small, absolute value must be >= %v", d, time.Microsecond)
} else if (usage == AsOf && iv.Duration.Compare(duration.Duration{}) > 0) {
convErr = errors.Errorf("interval value %v too large, AS OF interval must be <= -%v", d, time.Microsecond)
} else if (usage == Split && iv.Duration.Compare(duration.Duration{}) < 0) {
convErr = errors.Errorf("interval value %v too small, SPLIT AT interval must be >= %v", d, time.Microsecond)
}
ts.WallTime = duration.Add(stmtTimestamp, iv.Duration).UnixNano()
break
Expand All @@ -275,11 +246,6 @@ func DatumToHLC(
case *tree.DDecimal:
ts, convErr = hlc.DecimalToHLC(&d.Decimal)
case *tree.DInterval:
if (usage == AsOf && d.Duration.Compare(duration.Duration{}) > 0) {
convErr = errors.Errorf("interval value %v too large, AS OF interval must be <= -%v", d, time.Microsecond)
} else if (usage == Split && d.Duration.Compare(duration.Duration{}) < 0) {
convErr = errors.Errorf("interval value %v too small, SPLIT interval must be >= %v", d, time.Microsecond)
}
ts.WallTime = duration.Add(stmtTimestamp, d.Duration).UnixNano()
default:
convErr = errors.WithSafeDetails(
Expand Down
3 changes: 1 addition & 2 deletions pkg/sql/sem/asof/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func EvalSystemTimeExpr(
semaCtx *tree.SemaContext,
systemTimeExpr tree.Expr,
op string,
usage DatumToHLCUsage,
) (hlc.Timestamp, error) {
typedExpr, err := TypeCheckSystemTimeExpr(ctx, semaCtx, systemTimeExpr, op)
if err != nil {
Expand All @@ -69,5 +68,5 @@ func EvalSystemTimeExpr(
return hlc.MaxTimestamp, nil
}
stmtTimestamp := evalCtx.GetStmtTimestamp()
return DatumToHLC(evalCtx, stmtTimestamp, d, usage)
return DatumToHLC(evalCtx, stmtTimestamp, d)
}
2 changes: 1 addition & 1 deletion pkg/sql/show_fingerprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func evalShowTenantFingerprintOptions(
) (*resolvedShowTenantFingerprintOptions, error) {
r := &resolvedShowTenantFingerprintOptions{}
if options.StartTimestamp != nil {
ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.StartTimestamp, op, asof.ShowTenantFingerprint)
ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.StartTimestamp, op)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func parseExpirationTime(
return hlc.MaxTimestamp, nil
}
stmtTimestamp := evalCtx.GetStmtTimestamp()
ts, err := asof.DatumToHLC(evalCtx, stmtTimestamp, d, asof.Split)
ts, err := asof.DatumToHLC(evalCtx, stmtTimestamp, d)
if err != nil {
return ts, errors.Wrap(err, "SPLIT AT")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestSplitAt(t *testing.T) {
},
{
in: "ALTER TABLE d.i SPLIT AT VALUES (17) WITH EXPIRATION '-1 day'::interval",
error: "SPLIT AT: interval value '-1 days' too small, SPLIT interval must be >= 1µs",
error: "SPLIT AT: expiration time should be greater than or equal to current time",
},
{
in: "ALTER TABLE d.i SPLIT AT VALUES (17) WITH EXPIRATION '0.1us'",
Expand Down

0 comments on commit 8a70b72

Please sign in to comment.