Skip to content

Commit

Permalink
Merge pull request #48 from citusdata/bump-2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hanefi authored Sep 10, 2021
2 parents 9b77e07 + 4bb5cea commit 865c827
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
copy_data.out

# Generated migration scripts
topn--?.?.?.sql
topn--*.sql
!update/topn--*.sql

# Sample data
customer_reviews_????.csv
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ matrix:
- env: PGVERSION=11
- env: PGVERSION=12
- env: PGVERSION=13
- env: PGVERSION=14
before_install:
- bash test_data_provider
- git clone -b v0.7.13 --depth 1 https://github.com/citusdata/tools.git
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### topn v2.4.0 (September 09, 2021) ###

* Adds PostgreSQL 14 support

### topn v2.3.1 (November 27, 2020) ###

* Adds PostgreSQL 13 support
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MODULES = topn
EXTENSION = topn
EXTVERSIONS = 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1
EXTVERSIONS = 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.4.0
DATA = $(wildcard $(EXTENSION)--*--*.sql)
DATA_built = $(foreach v,$(EXTVERSIONS),$(EXTENSION)--$(v).sql)
PG_CONFIG ?= pg_config
Expand Down Expand Up @@ -32,6 +32,8 @@ $(EXTENSION)--2.3.0.sql: $(EXTENSION)--2.2.2.sql $(EXTENSION)--2.2.2--2.3.0.sql
cat $^ > $@
$(EXTENSION)--2.3.1.sql: $(EXTENSION)--2.3.0.sql $(EXTENSION)--2.3.0--2.3.1.sql
cat $^ > $@
$(EXTENSION)--2.4.0.sql: $(EXTENSION)--2.3.1.sql $(EXTENSION)--2.3.1--2.4.0.sql
cat $^ > $@

EXTRA_CLEAN += topn--*.sql -r $(RPM_BUILD_ROOT)

Expand Down
12 changes: 9 additions & 3 deletions expected/customer_reviews_query.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 13;
SELECT substring(:'server_version', '\d+')::int = 14;
?column?
----------
t
(1 row)

SELECT substring(:'server_version', '\d+')::int = 13;
?column?
----------
f
(1 row)

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

SELECT substring(:'server_version', '\d+')::int = 13;
?column?
----------
t
(1 row)

-- Create table to insert summaries.
create table popular_products
(
Expand Down Expand Up @@ -47,9 +53,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
105 changes: 105 additions & 0 deletions expected/customer_reviews_query_1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int = 14;
?column?
----------
f
(1 row)

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: 2 additions & 1 deletion sql/customer_reviews_query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 13;
SELECT substring(:'server_version', '\d+')::int = 14;
SELECT substring(:'server_version', '\d+')::int = 13;

-- Create table to insert summaries.
create table popular_products
Expand Down
8 changes: 7 additions & 1 deletion topn.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,20 @@ CreateTopnAggState(void)
{
int32 hashTableSize = 0;
HASHCTL hashInfo;
int flags = HASH_ELEM | HASH_CONTEXT;

hashTableSize = (NumberOfCounters / 0.75) + 1;
memset(&hashInfo, 0, sizeof(hashInfo));
hashInfo.keysize = MAX_KEYSIZE;
hashInfo.entrysize = sizeof(FrequentTopnItem);
hashInfo.hcxt = CurrentMemoryContext;

#if PG_VERSION_NUM >= 140000
flags |= HASH_STRINGS;
#endif

return (TopnAggState *) hash_create("Item Frequency Map", hashTableSize, &hashInfo,
HASH_ELEM | HASH_CONTEXT);
flags);
}


Expand Down
2 changes: 1 addition & 1 deletion topn.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# topn extension
comment = 'type for top-n JSONB'
default_version = '2.3.1'
default_version = '2.4.0'
module_pathname = '$libdir/topn'
3 changes: 3 additions & 0 deletions update/topn--2.3.1--2.4.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* topn--2.3.1--2.4.0 */

/* bump version to 2.4.0 */

0 comments on commit 865c827

Please sign in to comment.