Skip to content
Permalink
Browse files
HAWQ-987. Add feature test for agg derived win.
  • Loading branch information
ztao1987 committed Aug 9, 2016
1 parent d73117e commit e0a072b0c7cf95f8d3d151c96ada53181485a7c0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
@@ -1,3 +1,7 @@
-- start_ignore
SET SEARCH_PATH=TestAggregate_TestAggregateDerivedWin;
SET
-- end_ignore
-- Objective: test aggregate derived window functions in HAWQ.
-- Aggregate derived window functions are nothing but user defined
-- aggregates when used with "OVER()" clause. Refer to GPSQL-1418.
@@ -19,10 +23,13 @@
--
-- Here the sequence V is represented by table ema_test ordered by k.
drop type if exists ema_type cascade;
NOTICE: type "ema_type" does not exist, skipping
psql:/tmp/TestAggregate_TestAggregateDerivedWin.sql:26: NOTICE: type "ema_type" does not exist, skipping
DROP TYPE
drop table if exists ema_test cascade;
NOTICE: table "ema_test" does not exist, skipping
psql:/tmp/TestAggregate_TestAggregateDerivedWin.sql:27: NOTICE: table "ema_test" does not exist, skipping
DROP TABLE
create type ema_type as (x float, e float);
CREATE TYPE
create function ema_adv(t ema_type, v float, x float)
returns ema_type
as $$
@@ -39,33 +46,39 @@ create function ema_adv(t ema_type, v float, x float)
return t;
end;
$$ language plpgsql;
CREATE FUNCTION
create function ema_fin(t ema_type)
returns float
as $$
begin
return t.e;
end;
$$ language plpgsql;
CREATE FUNCTION
-- Work around for MPP-14845: define a placebo prefunc. This should
-- never be called.
create function ema_pre(s1 ema_type, s2 ema_type)
returns ema_type
as $$
select '(,)'::ema_type;
$$ language sql;
CREATE FUNCTION
create aggregate ema(float, float) (
sfunc = ema_adv,
stype = ema_type,
finalfunc = ema_fin,
prefunc = ema_pre,
initcond = '(,)'
);
CREATE AGGREGATE
create table ema_test
( k int, v float )
distributed by (k);
CREATE TABLE
insert into ema_test
select i, 4*(22/7::float) + 10.0*(1+cos(radians(i*5)))
from generate_series(0,19) i(i);
INSERT 0 20
select
k, v,
ema(v, 0.9) over (order by k rows between unbounded preceding and current row)
@@ -146,25 +159,29 @@ create function mylag_transfn(st int[], val int, lag int)
return array_append(local_st[2:lag+1], val);
end;
$$ language plpgsql;
CREATE FUNCTION
create function mylag_finalfn(st int[])
returns int
as $$
begin
return st[1];
end;
$$ language plpgsql;
CREATE FUNCTION
create function mylag_prefn(st1 int[], st2 int[])
returns int[]
as $$
select '{}'::int[];
$$ language sql;
CREATE FUNCTION
create aggregate mylag(int, int) (
sfunc = mylag_transfn,
stype = int[],
finalfunc = mylag_finalfn,
prefunc = mylag_prefn,
initcond = '{null,null}'
);
CREATE AGGREGATE
-- This will be executed only on master, not on segments.
select i, mylag(i, 2) over (order by i) from generate_series(1,10)i;
i | mylag
@@ -182,7 +199,9 @@ select i, mylag(i, 2) over (order by i) from generate_series(1,10)i;
(10 rows)

create table t1 (a int, b int) distributed by (a);
CREATE TABLE
insert into t1 select i%3, 22*i/7 from generate_series(0,10)i;
INSERT 0 11
select a,b,mylag(b,1) over (order by b) from t1;
a | b | mylag
---+----+-------
@@ -207,6 +226,7 @@ CREATE AGGREGATE mysum (int) (
SFUNC = int4_sum,
prefunc = int8pl
);
CREATE AGGREGATE
SELECT a,b,mysum(b) over (order by b) FROM t1;
a | b | mysum
---+----+-------
@@ -242,17 +262,17 @@ SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (); -- mvd 1,2->3
SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (PARTITION BY a); -- mvd 1,2->3
a | b | mysum
---+----+-------
1 | 3 | 68
1 | 12 | 68
1 | 22 | 68
1 | 31 | 68
0 | 28 | 55
0 | 9 | 55
0 | 18 | 55
0 | 0 | 55
2 | 25 | 46
2 | 15 | 46
2 | 6 | 46
1 | 3 | 68
1 | 12 | 68
1 | 22 | 68
1 | 31 | 68
(11 rows)

SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (ORDER BY b); -- mvd 1,2->3
@@ -288,35 +308,35 @@ SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (PARTITION BY a ORDER BY b); --
(11 rows)

SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as
(PARTITION BY a ORDER BY b ROWS BETWEEN 1 preceding and current row); -- mvd 1,2->3
(PARTITION BY a ORDER BY b ROWS BETWEEN 1 preceding and current row) order by a,b; -- mvd 1,2->3
a | b | mysum
---+----+-------
1 | 3 | 3
1 | 12 | 15
1 | 22 | 34
1 | 31 | 53
0 | 0 | 0
0 | 9 | 9
0 | 18 | 27
0 | 28 | 46
1 | 3 | 3
1 | 12 | 15
1 | 22 | 34
1 | 31 | 53
2 | 6 | 6
2 | 15 | 21
2 | 25 | 40
(11 rows)

select a,b,mylag(b, 1) over (partition by a order by b) from t1; -- mvd 1,2->3
select a,b,mylag(b, 1) over (partition by a order by b) from t1 order by a,b; -- mvd 1,2->3
a | b | mylag
---+----+-------
0 | 0 |
0 | 9 | 0
0 | 18 | 9
0 | 28 | 18
2 | 6 |
2 | 15 | 6
2 | 25 | 15
1 | 3 |
1 | 12 | 3
1 | 22 | 12
1 | 31 | 22
2 | 6 |
2 | 15 | 6
2 | 25 | 15
(11 rows)

@@ -155,7 +155,7 @@ SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (PARTITION BY a); -- mvd 1,2->3
SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (ORDER BY b); -- mvd 1,2->3
SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as (PARTITION BY a ORDER BY b); -- mvd 1,2->3
SELECT a,b,mysum(b) over (w) FROM t1 WINDOW w as
(PARTITION BY a ORDER BY b ROWS BETWEEN 1 preceding and current row); -- mvd 1,2->3
(PARTITION BY a ORDER BY b ROWS BETWEEN 1 preceding and current row) order by a,b; -- mvd 1,2->3

select a,b,mylag(b, 1) over (partition by a order by b) from t1; -- mvd 1,2->3
select a,b,mylag(b, 1) over (partition by a order by b) from t1 order by a,b; -- mvd 1,2->3

@@ -72,4 +72,8 @@ TEST_F(TestAggregate, TestAggregateWithNull) {
"1||aa|\n0||WET|\n0|51||\n");
}


TEST_F(TestAggregate, TestAggregateDerivedWin) {
hawq::test::SQLUtility util;
util.execSQLFile("query/sql/agg-derived-win.sql",
"query/ans/agg-derived-win.ans");
}
@@ -170,7 +170,6 @@ ignore: percentile
ignore: resource_queue_function
ignore: gp_optimizer
ignore: co_nestloop_idxscan
test: agg_derived_win
ignore: orca_udfs
#
# the following test needs some special filespace/tablespace.

0 comments on commit e0a072b

Please sign in to comment.