Skip to content

Commit 59b2bc2

Browse files
otanJuanLeon1
authored andcommitted
release-20.1: Revert "sql: age returns normalized intervals"
This reverts commit 0608caf. Release note (bug fix): In 20.1.8, we attempted to fix age's lack of normalization of H:M:S into the years, months and days field. However, this was also broken for values > 1 month, as well as breaking `a::timestamp(tz) - b::timestamp(tz)` operators. This has now been resolved.
1 parent 49693f9 commit 59b2bc2

File tree

5 files changed

+8
-22
lines changed

5 files changed

+8
-22
lines changed

pkg/sql/logictest/testdata/logic_test/datetime

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,13 @@ SELECT '5874897-12-31'::date - '4714-11-24 BC'::date
159159
query T
160160
SELECT age('2001-04-10 22:06:45', '1957-06-13')
161161
----
162-
44 years 5 mons 17 days 22:06:45
162+
384190:06:45
163163

164164
query B
165165
SELECT age('1957-06-13') - age(now(), '1957-06-13') = interval '0s'
166166
----
167167
true
168168

169-
query T
170-
select age('2017-12-10'::timestamptz, '2017-12-01'::timestamptz)
171-
----
172-
9 days
173-
174169
query B
175170
SELECT now() - timestamp '2015-06-13' > interval '100h'
176171
----

pkg/sql/logictest/testdata/logic_test/timestamp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ SELECT
402402
FROM example
403403
ORDER BY a
404404
----
405-
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
406-
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
405+
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
406+
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
407407

408408
statement ok
409409
DROP TABLE example

pkg/sql/opt/norm/testdata/rules/fold_constants

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ values
366366
├── cardinality: [1 - 1]
367367
├── key: ()
368368
├── fd: ()-->(1)
369-
└── ('-1 days',)
369+
└── ('-24:00:00',)
370370

371371
# Fold constant.
372372
norm expect=FoldBinary

pkg/sql/sem/tree/eval.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
878878
ReturnType: types.Interval,
879879
Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
880880
nanos := left.(*DTimestamp).Sub(right.(*DTimestamp).Time).Nanoseconds()
881-
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
881+
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
882882
},
883883
},
884884
&BinOp{
@@ -887,7 +887,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
887887
ReturnType: types.Interval,
888888
Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
889889
nanos := left.(*DTimestampTZ).Sub(right.(*DTimestampTZ).Time).Nanoseconds()
890-
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
890+
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
891891
},
892892
},
893893
&BinOp{
@@ -898,7 +898,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
898898
// These two quantities aren't directly comparable. Convert the
899899
// TimestampTZ to a timestamp first.
900900
nanos := left.(*DTimestamp).Sub(right.(*DTimestampTZ).stripTimeZone(ctx).Time).Nanoseconds()
901-
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
901+
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
902902
},
903903
},
904904
&BinOp{
@@ -909,7 +909,7 @@ var BinOps = map[BinaryOperator]binOpOverload{
909909
// These two quantities aren't directly comparable. Convert the
910910
// TimestampTZ to a timestamp first.
911911
nanos := left.(*DTimestampTZ).stripTimeZone(ctx).Sub(right.(*DTimestamp).Time).Nanoseconds()
912-
return &DInterval{Duration: duration.MakeNormalizedDuration(nanos, 0, 0)}, nil
912+
return &DInterval{Duration: duration.MakeDuration(nanos, 0, 0)}, nil
913913
},
914914
},
915915
&BinOp{

pkg/util/duration/duration.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ func MakeDuration(nanos, days, months int64) Duration {
102102
}
103103
}
104104

105-
// MakeNormalizedDuration returns a normalized Duration.
106-
func MakeNormalizedDuration(nanos, days, months int64) Duration {
107-
return Duration{
108-
Months: months,
109-
Days: days,
110-
nanos: rounded(nanos),
111-
}.normalize()
112-
}
113-
114105
// DecodeDuration returns a Duration without rounding nanos.
115106
func DecodeDuration(months, days, nanos int64) Duration {
116107
return Duration{

0 commit comments

Comments
 (0)