File: orderby9.test.lua

package info (click to toggle)
tarantool 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,364 kB
  • sloc: ansic: 513,760; cpp: 69,489; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,173; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (74 lines) | stat: -rwxr-xr-x 2,386 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(4)

--!./tcltestrunner.lua
-- 2015-08-26
--
-- The author disclaims copyright to this source code.  In place of
-- a legal notice, here is a blessing:
--
--    May you do good and not evil.
--    May you find forgiveness for yourself and forgive others.
--    May you share freely, never taking more than you give.
--
-------------------------------------------------------------------------
-- This file implements regression tests for sql library.
-- 
-- This file seeks to verify that expressions (and especially functions)
-- that are in both the ORDER BY clause and the result set are only
-- evaluated once.
--
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]

testprefix = "orderby9"
test:do_execsql_test(
    "setup",
    [[
        -- create a table with many entries
        CREATE TABLE t1(x  INT primary key);
        WITH RECURSIVE
           c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
        INSERT INTO t1 SELECT x FROM c;
    ]])

test:do_test(
    1.0,
    function()
        -- If random() is only evaluated once and then reused for each row, then
        -- the output should appear in sorted order.  If random() is evaluated 
        -- separately for the result set and the ORDER BY clause, then the output
        -- order will be random.
        local l1 = test:execsql("SELECT random() AS y FROM t1 ORDER BY 1;")
        -- Big random() numbers are cdata, but cdata numbers can
        -- not be compared nor sorted correctly.
        for k,_ in pairs(l1) do l1[k] = tonumber(l1[k]) end
        local l2 = table.deepcopy(l1)
        table.sort(l1)
        return test.is_deeply_regex(l1, l2)
    end, true)

test:do_test(
    1.1,
    function()
        local l1 = test:execsql("SELECT random() AS y FROM t1 ORDER BY random();")
        for k,_ in pairs(l1) do l1[k] = tonumber(l1[k]) end
        local l2 = table.deepcopy(l1)
        table.sort(l1)
        return test.is_deeply_regex(l1, l2)
    end, true)

test:do_test(
    1.2,
    function()
        local l1 = test:execsql("SELECT random() AS y FROM t1 ORDER BY +random();")
        for k,_ in pairs(l1) do l1[k] = tonumber(l1[k]) end
        local l2 = table.deepcopy(l1)
        table.sort(l1)
        return test.is_deeply_regex(l1, l2)
    end, false)



test:finish_test()