Skip to content

Commit

Permalink
Run PG13 tests on CI (#44)
Browse files Browse the repository at this point in the history
TopN approximation algorithm returns different and consistent results
on PG13 due to some changes in the execution of the plan. I added an
alternative test output to resolve this.
  • Loading branch information
hanefi authored Nov 26, 2020
1 parent a8751df commit eb04747
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
- env: PGVERSION=10
- env: PGVERSION=11
- env: PGVERSION=12
- env: PGVERSION=13
before_install:
- bash test_data_provider
- git clone -b v0.7.13 --depth 1 https://github.com/citusdata/tools.git
Expand Down
11 changes: 9 additions & 2 deletions expected/customer_reviews_query.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 13;
?column?
----------
t
(1 row)

-- Create table to insert summaries.
create table popular_products
(
Expand Down Expand Up @@ -40,9 +47,9 @@ order by 2 DESC, 1;
0671014730 | 572
0743527550 | 572
0375700757 | 555
0871136791 | 555
0871136791 | 553
0679460691 | 551
0375402926 | 550
0375402926 | 548
0613221583 | 536
0812550293 | 536
1575110458 | 536
Expand Down
99 changes: 99 additions & 0 deletions expected/customer_reviews_query_0.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 13;
?column?
----------
f
(1 row)

-- Create table to insert summaries.
create table popular_products
(
review_summary jsonb,
year double precision,
month double precision
);
set topn.number_of_counters to 1000;
-- Create different summaries by grouping the reviews according to their year and month.
insert into
popular_products(review_summary, year, month )
select
topn_add_agg(product_id),
extract(year from review_date) as year,
extract(month from review_date) as month
from
customer_reviews
group by
year,
month;
-- Create another table for the merged results.
create table
overall_result(merged_summary jsonb);
-- Let's merge the summaries for the overall result and check top-20 items.
insert into
overall_result(merged_summary)
select
topn_union_agg(review_summary)
from
popular_products;
select
(topn(merged_summary, 20)).*
from
overall_result
order by 2 DESC, 1;
item | frequency
------------+-----------
0671003755 | 576
0613033205 | 575
0671014730 | 572
0743527550 | 572
0375700757 | 555
0871136791 | 555
0679460691 | 551
0375402926 | 550
0613221583 | 536
0812550293 | 536
1575110458 | 536
1590073983 | 536
1590073991 | 536
0375402675 | 524
0375403477 | 524
0375703241 | 524
0399143904 | 524
0425170349 | 524
0613222407 | 524
0765342294 | 510
(20 rows)

-- Test window functions
CREATE TABLE daily_populars
(
date DATE,
agg_data JSONB
);
INSERT INTO daily_populars
SELECT
date_trunc('day', review_date),
topn_add_agg(product_id)
FROM
customer_reviews
GROUP BY
1;
SELECT
date,
topn_union_agg(agg_data) OVER seven_days
FROM
daily_populars
WINDOW
seven_days AS (ORDER BY date ASC ROWS 6 PRECEDING)
ORDER BY
1
LIMIT 5;
date | topn_union_agg
------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12-30-1970 | {"1551802538": 1, "1551803542": 1}
06-19-1995 | {"0898624932": 1, "1551802538": 1, "1551803542": 1}
06-23-1995 | {"0521469112": 1, "0898624932": 1, "1551802538": 1, "1551803542": 1}
07-14-1995 | {"0521469112": 1, "0679722955": 1, "0898624932": 1, "1551802538": 1, "1551803542": 1}
07-18-1995 | {"0195069056": 1, "0471114251": 1, "0517887290": 1, "0521469112": 1, "0679722955": 1, "0898624932": 1, "0962344788": 1, "1551802538": 1, "1551803542": 1, "1574531093": 1}
(5 rows)

3 changes: 3 additions & 0 deletions sql/customer_reviews_query.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 13;

-- Create table to insert summaries.
create table popular_products
(
Expand Down

0 comments on commit eb04747

Please sign in to comment.