Skip to content

Commit

Permalink
Revert "sql: age returns normalized intervals"
Browse files Browse the repository at this point in the history
This reverts commit 0608caf.
  • Loading branch information
solongordon committed Nov 16, 2020
1 parent ffd029f commit 9624e1e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
7 changes: 1 addition & 6 deletions pkg/sql/logictest/testdata/logic_test/datetime
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,13 @@ SELECT '5874897-12-31'::date - '4714-11-24 BC'::date
query T
SELECT age('2001-04-10 22:06:45', '1957-06-13')
----
44 years 5 mons 17 days 22:06:45
384190:06:45

query B
SELECT age('1957-06-13') - age(now(), '1957-06-13') = interval '0s'
----
true

query T
select age('2017-12-10'::timestamptz, '2017-12-01'::timestamptz)
----
9 days

query B
SELECT now() - timestamp '2015-06-13' > interval '100h'
----
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/timestamp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ SELECT
FROM example
ORDER BY a
----
2010-11-07 22:59:00 -0600 CST 2010-11-07 23:59:00 -0600 CST 2010-12-06 23:59:00 -0600 CST 2010-11-05 23:59:00 -0500 CDT 2010-11-05 23:59:00 -0500 CDT 2010-10-06 23:59:00 -0500 CDT 00:00:00 -1 days -01:00:00 2010-11-06 23:59:00-05:00
2010-11-08 23:59:00 -0600 CST 2010-11-08 23:59:00 -0600 CST 2010-12-07 23:59:00 -0600 CST 2010-11-07 00:59:00 -0500 CDT 2010-11-06 23:59:00 -0500 CDT 2010-10-07 23:59:00 -0500 CDT 1 day 01:00:00 00:00:00 2010-11-07 23:59:00-06:00
2010-11-07 22:59:00 -0600 CST 2010-11-07 23:59:00 -0600 CST 2010-12-06 23:59:00 -0600 CST 2010-11-05 23:59:00 -0500 CDT 2010-11-05 23:59:00 -0500 CDT 2010-10-06 23:59:00 -0500 CDT 00:00:00 -25:00:00 2010-11-06 23:59:00-05:00
2010-11-08 23:59:00 -0600 CST 2010-11-08 23:59:00 -0600 CST 2010-12-07 23:59:00 -0600 CST 2010-11-07 00:59:00 -0500 CDT 2010-11-06 23:59:00 -0500 CDT 2010-10-07 23:59:00 -0500 CDT 25:00:00 00:00:00 2010-11-07 23:59:00-06:00

statement ok
DROP TABLE example
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/norm/testdata/rules/fold_constants
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ values
├── cardinality: [1 - 1]
├── key: ()
├── fd: ()-->(1)
└── ('-1 days',)
└── ('-24:00:00',)

# Fold constant.
norm expect=FoldBinary
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/sem/tree/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
ReturnType: types.Interval,
Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
nanos := left.(*DTimestamp).Sub(right.(*DTimestamp).Time).Nanoseconds()
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
},
},
&BinOp{
Expand All @@ -887,7 +887,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
ReturnType: types.Interval,
Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
nanos := left.(*DTimestampTZ).Sub(right.(*DTimestampTZ).Time).Nanoseconds()
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
},
},
&BinOp{
Expand All @@ -898,7 +898,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
// These two quantities aren't directly comparable. Convert the
// TimestampTZ to a timestamp first.
nanos := left.(*DTimestamp).Sub(right.(*DTimestampTZ).stripTimeZone(ctx).Time).Nanoseconds()
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
},
},
&BinOp{
Expand All @@ -909,7 +909,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
// These two quantities aren't directly comparable. Convert the
// TimestampTZ to a timestamp first.
nanos := left.(*DTimestampTZ).stripTimeZone(ctx).Sub(right.(*DTimestamp).Time).Nanoseconds()
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
},
},
&BinOp{
Expand Down
9 changes: 0 additions & 9 deletions pkg/util/duration/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ func MakeDuration(nanos, days, months int64) Duration {
}
}

// MakeNormalizedDuration returns a normalized Duration.
func MakeNormalizedDuration(nanos, days, months int64) Duration {
return Duration{
Months: months,
Days: days,
nanos: rounded(nanos),
}.normalize()
}

// DecodeDuration returns a Duration without rounding nanos.
func DecodeDuration(months, days, nanos int64) Duration {
return Duration{
Expand Down

0 comments on commit 9624e1e

Please sign in to comment.