-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orderby: fix evaluation of ORDER BY expr when used with projection (#471
) When the ORDER BY expression uses fields that are not present in the preceding projection operator, it was evaluating the expression to NULL, which was breaking the ordering. It now evaluates the expr against the result of the projection first, then if it is NULL evaluates it against the original document. Example: ```bash table.Scan("test") | docs.Project(b) | docs.TempTreeSort(a) ```
- Loading branch information
Showing
3 changed files
with
72 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,84 @@ | ||
-- setup: | ||
CREATE TABLE test(a double); | ||
INSERT INTO test (a) VALUES (1), (2), (3); | ||
CREATE TABLE test(a double, b double); | ||
INSERT INTO test (a, b) VALUES (50, 3), (100, 4), (10, 2), (null, 1); | ||
|
||
-- suite: no index | ||
|
||
-- suite: with index | ||
CREATE INDEX ON test(a); | ||
|
||
-- test: asc | ||
SELECT b FROM test ORDER BY a; | ||
/* result: | ||
{ | ||
b: 1.0, | ||
} | ||
{ | ||
b: 2.0 | ||
} | ||
{ | ||
b: 3.0 | ||
} | ||
{ | ||
b: 4.0 | ||
} | ||
*/ | ||
|
||
|
||
-- test: asc / wildcard | ||
SELECT * FROM test ORDER BY a; | ||
/* result: | ||
{ | ||
a: 1.0 | ||
b: 1.0, | ||
} | ||
{ | ||
a: 2.0 | ||
a: 10.0, | ||
b: 2.0 | ||
} | ||
{ | ||
a: 3.0 | ||
a: 50.0, | ||
b: 3.0 | ||
} | ||
{ | ||
a: 100.0, | ||
b: 4.0 | ||
} | ||
*/ | ||
|
||
|
||
-- test: desc | ||
SELECT * FROM test ORDER BY a DESC; | ||
SELECT b FROM test ORDER BY a DESC; | ||
/* result: | ||
{ | ||
a: 3.0 | ||
b: 4.0, | ||
} | ||
{ | ||
b: 3.0 | ||
} | ||
{ | ||
a: 2.0 | ||
b: 2.0 | ||
} | ||
{ | ||
a: 1.0 | ||
b: 1.0 | ||
} | ||
*/ | ||
|
||
-- test: desc / wildcard | ||
SELECT * FROM test ORDER BY a DESC; | ||
/* result: | ||
{ | ||
a: 100.0, | ||
b: 4.0, | ||
} | ||
{ | ||
a: 50.0, | ||
b: 3.0 | ||
} | ||
{ | ||
a: 10.0, | ||
b: 2.0 | ||
} | ||
{ | ||
b: 1.0 | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters