From eb04747659e71f20663e34c7c9fb640ea2ce9e3a Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Thu, 26 Nov 2020 13:57:30 +0300 Subject: [PATCH] Run PG13 tests on CI (#44) 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. --- .travis.yml | 1 + expected/customer_reviews_query.out | 11 ++- expected/customer_reviews_query_0.out | 99 +++++++++++++++++++++++++++ sql/customer_reviews_query.sql | 3 + 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 expected/customer_reviews_query_0.out diff --git a/.travis.yml b/.travis.yml index c7898f3..16ed6f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/expected/customer_reviews_query.out b/expected/customer_reviews_query.out index 1c27108..3500a34 100644 --- a/expected/customer_reviews_query.out +++ b/expected/customer_reviews_query.out @@ -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 ( @@ -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 diff --git a/expected/customer_reviews_query_0.out b/expected/customer_reviews_query_0.out new file mode 100644 index 0000000..206b21f --- /dev/null +++ b/expected/customer_reviews_query_0.out @@ -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) + diff --git a/sql/customer_reviews_query.sql b/sql/customer_reviews_query.sql index 3fe8780..5c11749 100644 --- a/sql/customer_reviews_query.sql +++ b/sql/customer_reviews_query.sql @@ -1,3 +1,6 @@ +SHOW server_version \gset +SELECT substring(:'server_version', '\d+')::int >= 13; + -- Create table to insert summaries. create table popular_products (