Skip to content

Commit

Permalink
executor: RANGE frame can have no ORDER BY clause (#10496)
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros authored and zz-jason committed May 17, 2019
1 parent 04d4910 commit 8ec79be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ func (b *executorBuilder) buildWindow(v *plannercore.PhysicalWindow) *WindowExec
}
} else {
cmpResult := int64(-1)
if v.OrderBy[0].Desc {
if len(v.OrderBy) > 0 && v.OrderBy[0].Desc {
cmpResult = 1
}
processor = &rangeFrameWindowProcessor{
Expand Down
12 changes: 12 additions & 0 deletions executor/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,16 @@ func (s *testSuite4) TestWindowFunctions(c *C) {

result = tk.MustQuery("SELECT CUME_DIST() OVER (ORDER BY null);")
result.Check(testkit.Rows("1"))

tk.MustExec("create table issue10494(a INT, b CHAR(1), c DATETIME, d BLOB)")
tk.MustExec("insert into issue10494 VALUES (1,'x','2010-01-01','blob'), (2, 'y', '2011-01-01', ''), (3, 'y', '2012-01-01', ''), (4, 't', '2012-01-01', 'blob'), (5, null, '2013-01-01', null)")
tk.MustQuery("SELECT a, b, c, SUM(a) OVER (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM issue10494 order by a;").Check(
testkit.Rows(
"1 x 2010-01-01 00:00:00 15",
"2 y 2011-01-01 00:00:00 15",
"3 y 2012-01-01 00:00:00 15",
"4 t 2012-01-01 00:00:00 15",
"5 <nil> 2013-01-01 00:00:00 15",
),
)
}

0 comments on commit 8ec79be

Please sign in to comment.