From add47a5adaef48aad5a87e708382e7727e5bb182 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 24 Apr 2018 13:54:12 +0100 Subject: [PATCH] Ensure correct ordering with same-compare values --- db/select_test.go | 16 ++++++++-------- sql/string.go | 3 ++- util/comp/comp.go | 7 ++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/db/select_test.go b/db/select_test.go index c514b5d6..dad0a099 100644 --- a/db/select_test.go +++ b/db/select_test.go @@ -145,7 +145,7 @@ func TestSelect(t *testing.T) { CREATE person:a SET name="Tobias"; CREATE person:b SET name="Silvana"; CREATE person:c SET name="Jonathan", father=person:a, mother=person:b; - SELECT name, father, mother FROM person ORDER BY meta.id; + SELECT meta, name, father, mother FROM person ORDER BY meta.id; ` res, err := Execute(setupKV(), txt, nil) @@ -171,7 +171,7 @@ func TestSelect(t *testing.T) { CREATE person:a SET name="Tobias"; CREATE person:b SET name="Silvana"; CREATE person:c SET name="Jonathan", father=person:a, mother=person:b; - SELECT name, father.* AS father, mother.* AS mother FROM person ORDER BY meta.id; + SELECT meta, name, father.* AS father, mother.* AS mother FROM person ORDER BY meta.id; ` res, err := Execute(setupKV(), txt, nil) @@ -211,7 +211,7 @@ func TestSelect(t *testing.T) { CREATE person:a SET name="Tobias"; CREATE person:b SET name="Silvana"; CREATE person:c SET name="Jonathan", father=person:a, mother=person:b; - SELECT name, father.id AS father, mother.id AS mother FROM person ORDER BY meta.id; + SELECT meta, name, father.id AS father, mother.id AS mother FROM person ORDER BY meta.id; ` res, err := Execute(setupKV(), txt, nil) @@ -237,7 +237,7 @@ func TestSelect(t *testing.T) { CREATE person:a SET name="Tobias"; CREATE person:b SET name="Silvana"; CREATE person:c SET name="Jonathan", father=person:a, mother=person:b; - SELECT name, father.name AS father, mother.name AS mother FROM person ORDER BY meta.id; + SELECT meta, name, father.name AS father, mother.name AS mother FROM person ORDER BY meta.id; ` res, err := Execute(setupKV(), txt, nil) @@ -263,7 +263,7 @@ func TestSelect(t *testing.T) { CREATE person:a SET name="Tobias"; CREATE person:b SET name="Silvana"; CREATE person:c SET name="Jonathan", father=person:a, mother=person:b; - SELECT name, father.id.name AS father, mother.id.name AS mother FROM person ORDER BY meta.id; + SELECT meta, name, father.id.name AS father, mother.id.name AS mother FROM person ORDER BY meta.id; ` res, err := Execute(setupKV(), txt, nil) @@ -1278,7 +1278,7 @@ func TestSelect(t *testing.T) { }) - Convey("Group and retrieve more than 1000 records to test incremental processing", t, func() { + Convey("Group and retrieve more than 10000 records to test incremental processing", t, func() { setupDB() @@ -1437,7 +1437,7 @@ func TestSelect(t *testing.T) { }) - Convey("Order records with collation and numeric sorting using unicode definition", t, func() { + Convey("Order records with collation and numeric and insensitive sorting using unicode definition", t, func() { setupDB() @@ -1452,7 +1452,7 @@ func TestSelect(t *testing.T) { UPDATE person:4 SET test = "1000"; UPDATE person:6 SET test = "2"; UPDATE person:8 SET test = null; - SELECT test FROM person ORDER BY test COLLATE 'en-GB-u-kn-true' ASC; + SELECT test FROM person ORDER BY test COLLATE 'en-GB-u-kn-true-kc-false' ASC; ` res, err := Execute(setupKV(), txt, nil) diff --git a/sql/string.go b/sql/string.go index 50f8bda7..eadf2c15 100644 --- a/sql/string.go +++ b/sql/string.go @@ -521,9 +521,10 @@ func (this Orders) String() string { } func (this Order) String() string { - return print("%v %v", + return print("%v %v%v", this.Expr, maybe(this.Dir, "ASC", "DESC"), + maybe(!this.Tag.IsRoot(), print(" COLLATE %s", this.Tag.String())), ) } diff --git a/util/comp/comp.go b/util/comp/comp.go index 4a8f7eb6..1d58f512 100644 --- a/util/comp/comp.go +++ b/util/comp/comp.go @@ -124,7 +124,12 @@ func Comp(a, b interface{}, expr *sql.Order) int { if expr.Tag.IsRoot() { return strings.Compare(x, y) } else { - c := collate.New(expr.Tag, collate.OptionsFromTag(expr.Tag), collate.Loose) + c := collate.New( + expr.Tag, + collate.Loose, + collate.Force, + collate.OptionsFromTag(expr.Tag), + ) return c.CompareString(x, y) } }