Skip to content
Snippets Groups Projects
Commit eeb98a9a authored by Arseniy Volynets's avatar Arseniy Volynets
Browse files

chore: remove duplicate tests from test_groupby.lua

parent b1b021bf
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -1843,83 +1843,6 @@ groupby_queries.test_total_with_groupby = function()
})
end
groupby_queries.test_having1 = function()
local api = cluster:server("api-1").net_box
-- with having
local r, err = api:call("sbroad.execute", {
[[
SELECT "a", sum("b") as "sum" from "arithmetic_space"
group by "a"
having sum("b") > 5
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "a", type = "integer" },
{ name = "sum", type = "decimal" }
})
t.assert_items_equals(r.rows, {
{2, 6}
})
-- without having
r, err = api:call("sbroad.execute", {
[[
SELECT "a", sum("b") as "sum" from "arithmetic_space"
group by "a"
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "a", type = "integer" },
{ name = "sum", type = "decimal" }
})
t.assert_items_equals(r.rows, {
{2, 6},
{1, 3}
})
end
groupby_queries.test_having2 = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
SELECT "a", sum("b") as "sum" from "arithmetic_space"
group by "a"
having "a" = 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "a", type = "integer" },
{ name = "sum", type = "decimal" }
})
t.assert_items_equals(r.rows, {
{1, 3}
})
end
groupby_queries.test_having3 = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
SELECT "boolean_col", sum(distinct "f") as "sum" from "arithmetic_space"
group by "boolean_col"
having "boolean_col" = true
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "boolean_col", type = "boolean" },
{ name = "sum", type = "decimal" }
})
t.assert_items_equals(r.rows, {
{true, 2}
})
end
groupby_queries.test_having_with_sq = function()
local api = cluster:server("api-1").net_box
local query_str = [[
......@@ -1957,252 +1880,6 @@ groupby_queries.test_having_with_sq = function()
})
end
groupby_queries.test_having_no_groupby = function()
local api = cluster:server("api-1").net_box
-- having condition is true
local r, err = api:call("sbroad.execute", {
[[
SELECT sum("a"), sum(distinct "a"), count("a"), count(distinct "a") from "arithmetic_space"
having count(distinct "a") > 1
]], {}
})
t.assert_equals(err, nil)
-- todo: if executed on single tarantool instance, types are: (integer, integer, integer, integer)
t.assert_equals(r.metadata, {
{ name = "COL_1", type = "decimal" },
{ name = "COL_2", type = "decimal" },
{ name = "COL_3", type = "decimal" },
{ name = "COL_4", type = "integer" },
})
t.assert_items_equals(r.rows, {
{6, 3, 4, 2}
})
-- having condition is false
r, err = api:call("sbroad.execute", {
[[
SELECT sum("a"), sum(distinct "a"), count("a"), count(distinct "a") from "arithmetic_space"
having count(distinct "a") > 100
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "COL_1", type = "decimal" },
{ name = "COL_2", type = "decimal" },
{ name = "COL_3", type = "decimal" },
{ name = "COL_4", type = "integer" },
})
t.assert_items_equals(r.rows, {})
end
groupby_queries.test_having_selection = function()
local api = cluster:server("api-1").net_box
-- with having
local r, err = api:call("sbroad.execute", {
[[
SELECT "string_col", count(distinct "string_col"), count("string_col")
from "arithmetic_space"
where "id" > 2 or "string_col" = 'a'
group by "string_col"
having sum(distinct "a") > 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "string_col", type = "string" },
{ name = "COL_1", type = "integer" },
{ name = "COL_2", type = "decimal" }
})
t.assert_items_equals(r.rows, {
{ 'c', 1, 2 }
})
-- without having
r, err = api:call("sbroad.execute", {
[[
SELECT "string_col", count(distinct "string_col"), count("string_col")
from "arithmetic_space"
where "id" > 2 or "string_col" = 'a'
group by "string_col"
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "string_col", type = "string" },
{ name = "COL_1", type = "integer" },
{ name = "COL_2", type = "decimal" }
})
t.assert_items_equals(r.rows, {
{ 'a', 1, 2 },
{ 'c', 1, 2 }
})
end
groupby_queries.test_having_join = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
SELECT sum(distinct "a"), "b", s
from "arithmetic_space" as t1 inner join
(
select cast(sum("a") / 6 as integer) as s
from "arithmetic_space2"
having count(distinct "a") > 1
) as t2
on t1."c" = t2.s
group by s, t1."b"
having sum(distinct "a") in (2, 3) and count(distinct t2.s) = 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "COL_1", type = "decimal" },
{ name = "b", type = "integer" },
{ name = "S", type = "integer" }
})
t.assert_items_equals(r.rows, {
{ 2, 3, 1 }
})
end
groupby_queries.test_having_full_query = function()
local api = cluster:server("api-1").net_box
-- data after join + where
local r, err = api:call("sbroad.execute", {
[[
SELECT t1."a", t2.b, t2.s, t1."d"
from "arithmetic_space" as t1 inner join
(select "b" as b, "string_col" as s from "arithmetic_space2") as t2
on t1."a" = t2.b
where t1."d" + t1."a" > 2
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "T1.a", type = "integer" },
{ name = "T2.B", type = "integer" },
{ name = "T2.S", type = "string" },
{ name = "T1.d", type = "integer" },
})
t.assert_items_equals(r.rows, {
{1, 1, "a", 2},
{1, 1, "b", 2},
{1, 1, "b", 2},
{2, 2, "a", 2},
{2, 2, "a", 1},
})
r, err = api:call("sbroad.execute", {
[[
SELECT t1."a", count(distinct s)
from "arithmetic_space" as t1 inner join
(select "b" as b, "string_col" as s from "arithmetic_space2") as t2
on t1."a" = t2.b
where t1."d" + t1."a" > 2
group by "a"
having count(distinct s) > 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "a", type = "integer" },
{ name = "COL_1", type = "integer" },
})
t.assert_items_equals(r.rows, {
{ 1, 2 }
})
end
groupby_queries.test_having_inside_union = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
select sum(distinct "e") from "arithmetic_space"
having count(distinct "d") > 1
union all
select "b" from "arithmetic_space"
group by "b"
having count(distinct "d") > 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "COL_1", type = "decimal" },
})
t.assert_items_equals(r.rows, {
{2},
{3}
})
end
groupby_queries.test_having_inside_union1 = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
select "e" from "arithmetic_space"
union all
select "b" from "arithmetic_space"
group by "b"
having count(distinct "d") > 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "e", type = "integer" },
})
t.assert_items_equals(r.rows, {
{2},
{2},
{2},
{2},
{3}
})
end
groupby_queries.test_having_inside_except = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
select count("e") - 1 from "arithmetic_space"
having count("e") = 4
except
select "b" from "arithmetic_space"
group by "b"
having count(distinct "d") > 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "COL_1", type = "decimal" },
})
t.assert_items_equals(r.rows, {})
end
groupby_queries.test_having_inside_except1 = function()
local api = cluster:server("api-1").net_box
local r, err = api:call("sbroad.execute", {
[[
select "d" from "arithmetic_space"
group by "d"
except
select sum(distinct "c") from "arithmetic_space"
having count(distinct "c") = 1
]], {}
})
t.assert_equals(err, nil)
t.assert_equals(r.metadata, {
{ name = "d", type = "integer" },
})
t.assert_items_equals(r.rows, {
{2},
})
end
groupby_queries.test_having1 = function()
local api = cluster:server("api-1").net_box
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment