Skip to content

Commit

Permalink
expression: modify the mean result of time type (#21514)
Browse files Browse the repository at this point in the history
  • Loading branch information
ou-bing authored Dec 21, 2020
1 parent 1265a11 commit e8fb3ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions expression/aggregation/base_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (a *baseFuncDesc) typeInfer4Avg(ctx sessionctx.Context) {
case mysql.TypeDouble, mysql.TypeFloat:
a.RetTp = types.NewFieldType(mysql.TypeDouble)
a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxRealWidth, a.Args[0].GetType().Decimal
case mysql.TypeDate, mysql.TypeDuration, mysql.TypeDatetime, mysql.TypeTimestamp:
a.RetTp = types.NewFieldType(mysql.TypeDouble)
a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxRealWidth, 4
default:
a.RetTp = types.NewFieldType(mysql.TypeDouble)
a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxRealWidth, types.UnspecifiedLength
Expand Down
12 changes: 12 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8350,6 +8350,18 @@ func (s *testIntegrationSerialSuite) TestIssue20876(c *C) {
tk.MustQuery("select * from t where a='#';").Check(testkit.Rows("# C 10"))
}

// The actual results do not agree with the test results, It should be modified after the test suite is updated
func (s *testIntegrationSuite) TestIssue17726(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t0")
tk.MustExec("create table t0 (c1 DATE, c2 TIME, c3 DATETIME, c4 TIMESTAMP)")
tk.MustExec("insert into t0 values ('1000-01-01', '-838:59:59', '1000-01-01 00:00:00', '1970-01-01 08:00:01')")
tk.MustExec("insert into t0 values ('9999-12-31', '838:59:59', '9999-12-31 23:59:59', '2038-01-19 11:14:07')")
result := tk.MustQuery("select avg(c1), avg(c2), avg(c3), avg(c4) from t0")
result.Check(testkit.Rows("54995666 0 54995666117979.5 20040110095704"))
}

func (s *testIntegrationSuite) TestIssue12205(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down

0 comments on commit e8fb3ea

Please sign in to comment.