diff --git a/duckdb-parquet/benchmark.sh b/duckdb-parquet/benchmark.sh new file mode 100755 index 000000000..16bd969aa --- /dev/null +++ b/duckdb-parquet/benchmark.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Install + +sudo apt-get update +sudo apt-get install -y python3-pip +pip install duckdb psutil + +# Load the data +seq 0 99 | xargs -P100 -I{} bash -c 'wget --continue https://datasets.clickhouse.com/hits_compatible/athena_partitioned/hits_{}.parquet' + +./load.py + +# Run the queries + +./run.sh 2>&1 | tee log.txt + +wc -c my-db.duckdb + +cat log.txt | grep -P '^\d|Killed|Segmentation' | sed -r -e 's/^.*(Killed|Segmentation).*$/null\nnull\nnull/' | + awk '{ if (i % 3 == 0) { printf "[" }; printf $1; if (i % 3 != 2) { printf "," } else { print "]," }; ++i; }' diff --git a/duckdb-parquet/create.sql b/duckdb-parquet/create.sql new file mode 100644 index 000000000..6f953ce31 --- /dev/null +++ b/duckdb-parquet/create.sql @@ -0,0 +1,6 @@ +CREATE VIEW hits AS +SELECT * + REPLACE + (epoch_ms(EventTime * 1000) AS EventTime, + DATE '1970-01-01' + INTERVAL (EventDate) DAYS AS EventDate) +FROM read_parquet('hits_*.parquet', binary_as_string=True); \ No newline at end of file diff --git a/duckdb-parquet/load.py b/duckdb-parquet/load.py new file mode 100755 index 000000000..82f047dca --- /dev/null +++ b/duckdb-parquet/load.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import duckdb +import timeit +import psutil + +con = duckdb.connect(database="my-db.duckdb", read_only=False) + +print("Set up a view over the Parquet files") + +start = timeit.default_timer() +con.execute(open("create.sql").read()) +end = timeit.default_timer() +print(end - start) diff --git a/duckdb-parquet/queries.sql b/duckdb-parquet/queries.sql new file mode 100644 index 000000000..b4115ee3a --- /dev/null +++ b/duckdb-parquet/queries.sql @@ -0,0 +1,43 @@ +SELECT COUNT(*) FROM hits; +SELECT COUNT(*) FROM hits WHERE AdvEngineID <> 0; +SELECT SUM(AdvEngineID), COUNT(*), AVG(ResolutionWidth) FROM hits; +SELECT AVG(UserID) FROM hits; +SELECT COUNT(DISTINCT UserID) FROM hits; +SELECT COUNT(DISTINCT SearchPhrase) FROM hits; +SELECT MIN(EventDate), MAX(EventDate) FROM hits; +SELECT AdvEngineID, COUNT(*) FROM hits WHERE AdvEngineID <> 0 GROUP BY AdvEngineID ORDER BY COUNT(*) DESC; +SELECT RegionID, COUNT(DISTINCT UserID) AS u FROM hits GROUP BY RegionID ORDER BY u DESC LIMIT 10; +SELECT RegionID, SUM(AdvEngineID), COUNT(*) AS c, AVG(ResolutionWidth), COUNT(DISTINCT UserID) FROM hits GROUP BY RegionID ORDER BY c DESC LIMIT 10; +SELECT MobilePhoneModel, COUNT(DISTINCT UserID) AS u FROM hits WHERE MobilePhoneModel <> '' GROUP BY MobilePhoneModel ORDER BY u DESC LIMIT 10; +SELECT MobilePhone, MobilePhoneModel, COUNT(DISTINCT UserID) AS u FROM hits WHERE MobilePhoneModel <> '' GROUP BY MobilePhone, MobilePhoneModel ORDER BY u DESC LIMIT 10; +SELECT SearchPhrase, COUNT(*) AS c FROM hits WHERE SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY c DESC LIMIT 10; +SELECT SearchPhrase, COUNT(DISTINCT UserID) AS u FROM hits WHERE SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY u DESC LIMIT 10; +SELECT SearchEngineID, SearchPhrase, COUNT(*) AS c FROM hits WHERE SearchPhrase <> '' GROUP BY SearchEngineID, SearchPhrase ORDER BY c DESC LIMIT 10; +SELECT UserID, COUNT(*) FROM hits GROUP BY UserID ORDER BY COUNT(*) DESC LIMIT 10; +SELECT UserID, SearchPhrase, COUNT(*) FROM hits GROUP BY UserID, SearchPhrase ORDER BY COUNT(*) DESC LIMIT 10; +SELECT UserID, SearchPhrase, COUNT(*) FROM hits GROUP BY UserID, SearchPhrase LIMIT 10; +SELECT UserID, extract(minute FROM EventTime) AS m, SearchPhrase, COUNT(*) FROM hits GROUP BY UserID, m, SearchPhrase ORDER BY COUNT(*) DESC LIMIT 10; +SELECT UserID FROM hits WHERE UserID = 435090932899640449; +SELECT COUNT(*) FROM hits WHERE URL LIKE '%google%'; +SELECT SearchPhrase, MIN(URL), COUNT(*) AS c FROM hits WHERE URL LIKE '%google%' AND SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY c DESC LIMIT 10; +SELECT SearchPhrase, MIN(URL), MIN(Title), COUNT(*) AS c, COUNT(DISTINCT UserID) FROM hits WHERE Title LIKE '%Google%' AND URL NOT LIKE '%.google.%' AND SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY c DESC LIMIT 10; +SELECT * FROM hits WHERE URL LIKE '%google%' ORDER BY EventTime LIMIT 10; +SELECT SearchPhrase FROM hits WHERE SearchPhrase <> '' ORDER BY EventTime LIMIT 10; +SELECT SearchPhrase FROM hits WHERE SearchPhrase <> '' ORDER BY SearchPhrase LIMIT 10; +SELECT SearchPhrase FROM hits WHERE SearchPhrase <> '' ORDER BY EventTime, SearchPhrase LIMIT 10; +SELECT CounterID, AVG(STRLEN(URL)) AS l, COUNT(*) AS c FROM hits WHERE URL <> '' GROUP BY CounterID HAVING COUNT(*) > 100000 ORDER BY l DESC LIMIT 25; +SELECT REGEXP_REPLACE(Referer, '^https?://(?:www\.)?([^/]+)/.*$', '\1') AS k, AVG(STRLEN(Referer)) AS l, COUNT(*) AS c, MIN(Referer) FROM hits WHERE Referer <> '' GROUP BY k HAVING COUNT(*) > 100000 ORDER BY l DESC LIMIT 25; +SELECT SUM(ResolutionWidth), SUM(ResolutionWidth + 1), SUM(ResolutionWidth + 2), SUM(ResolutionWidth + 3), SUM(ResolutionWidth + 4), SUM(ResolutionWidth + 5), SUM(ResolutionWidth + 6), SUM(ResolutionWidth + 7), SUM(ResolutionWidth + 8), SUM(ResolutionWidth + 9), SUM(ResolutionWidth + 10), SUM(ResolutionWidth + 11), SUM(ResolutionWidth + 12), SUM(ResolutionWidth + 13), SUM(ResolutionWidth + 14), SUM(ResolutionWidth + 15), SUM(ResolutionWidth + 16), SUM(ResolutionWidth + 17), SUM(ResolutionWidth + 18), SUM(ResolutionWidth + 19), SUM(ResolutionWidth + 20), SUM(ResolutionWidth + 21), SUM(ResolutionWidth + 22), SUM(ResolutionWidth + 23), SUM(ResolutionWidth + 24), SUM(ResolutionWidth + 25), SUM(ResolutionWidth + 26), SUM(ResolutionWidth + 27), SUM(ResolutionWidth + 28), SUM(ResolutionWidth + 29), SUM(ResolutionWidth + 30), SUM(ResolutionWidth + 31), SUM(ResolutionWidth + 32), SUM(ResolutionWidth + 33), SUM(ResolutionWidth + 34), SUM(ResolutionWidth + 35), SUM(ResolutionWidth + 36), SUM(ResolutionWidth + 37), SUM(ResolutionWidth + 38), SUM(ResolutionWidth + 39), SUM(ResolutionWidth + 40), SUM(ResolutionWidth + 41), SUM(ResolutionWidth + 42), SUM(ResolutionWidth + 43), SUM(ResolutionWidth + 44), SUM(ResolutionWidth + 45), SUM(ResolutionWidth + 46), SUM(ResolutionWidth + 47), SUM(ResolutionWidth + 48), SUM(ResolutionWidth + 49), SUM(ResolutionWidth + 50), SUM(ResolutionWidth + 51), SUM(ResolutionWidth + 52), SUM(ResolutionWidth + 53), SUM(ResolutionWidth + 54), SUM(ResolutionWidth + 55), SUM(ResolutionWidth + 56), SUM(ResolutionWidth + 57), SUM(ResolutionWidth + 58), SUM(ResolutionWidth + 59), SUM(ResolutionWidth + 60), SUM(ResolutionWidth + 61), SUM(ResolutionWidth + 62), SUM(ResolutionWidth + 63), SUM(ResolutionWidth + 64), SUM(ResolutionWidth + 65), SUM(ResolutionWidth + 66), SUM(ResolutionWidth + 67), SUM(ResolutionWidth + 68), SUM(ResolutionWidth + 69), SUM(ResolutionWidth + 70), SUM(ResolutionWidth + 71), SUM(ResolutionWidth + 72), SUM(ResolutionWidth + 73), SUM(ResolutionWidth + 74), SUM(ResolutionWidth + 75), SUM(ResolutionWidth + 76), SUM(ResolutionWidth + 77), SUM(ResolutionWidth + 78), SUM(ResolutionWidth + 79), SUM(ResolutionWidth + 80), SUM(ResolutionWidth + 81), SUM(ResolutionWidth + 82), SUM(ResolutionWidth + 83), SUM(ResolutionWidth + 84), SUM(ResolutionWidth + 85), SUM(ResolutionWidth + 86), SUM(ResolutionWidth + 87), SUM(ResolutionWidth + 88), SUM(ResolutionWidth + 89) FROM hits; +SELECT SearchEngineID, ClientIP, COUNT(*) AS c, SUM(IsRefresh), AVG(ResolutionWidth) FROM hits WHERE SearchPhrase <> '' GROUP BY SearchEngineID, ClientIP ORDER BY c DESC LIMIT 10; +SELECT WatchID, ClientIP, COUNT(*) AS c, SUM(IsRefresh), AVG(ResolutionWidth) FROM hits WHERE SearchPhrase <> '' GROUP BY WatchID, ClientIP ORDER BY c DESC LIMIT 10; +SELECT WatchID, ClientIP, COUNT(*) AS c, SUM(IsRefresh), AVG(ResolutionWidth) FROM hits GROUP BY WatchID, ClientIP ORDER BY c DESC LIMIT 10; +SELECT URL, COUNT(*) AS c FROM hits GROUP BY URL ORDER BY c DESC LIMIT 10; +SELECT 1, URL, COUNT(*) AS c FROM hits GROUP BY 1, URL ORDER BY c DESC LIMIT 10; +SELECT ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3, COUNT(*) AS c FROM hits GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3 ORDER BY c DESC LIMIT 10; +SELECT URL, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-01' AND EventDate <= '2013-07-31' AND DontCountHits = 0 AND IsRefresh = 0 AND URL <> '' GROUP BY URL ORDER BY PageViews DESC LIMIT 10; +SELECT Title, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-01' AND EventDate <= '2013-07-31' AND DontCountHits = 0 AND IsRefresh = 0 AND Title <> '' GROUP BY Title ORDER BY PageViews DESC LIMIT 10; +SELECT URL, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-01' AND EventDate <= '2013-07-31' AND IsRefresh = 0 AND IsLink <> 0 AND IsDownload = 0 GROUP BY URL ORDER BY PageViews DESC LIMIT 10 OFFSET 1000; +SELECT TraficSourceID, SearchEngineID, AdvEngineID, CASE WHEN (SearchEngineID = 0 AND AdvEngineID = 0) THEN Referer ELSE '' END AS Src, URL AS Dst, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-01' AND EventDate <= '2013-07-31' AND IsRefresh = 0 GROUP BY TraficSourceID, SearchEngineID, AdvEngineID, Src, Dst ORDER BY PageViews DESC LIMIT 10 OFFSET 1000; +SELECT URLHash, EventDate, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-01' AND EventDate <= '2013-07-31' AND IsRefresh = 0 AND TraficSourceID IN (-1, 6) AND RefererHash = 3594120000172545465 GROUP BY URLHash, EventDate ORDER BY PageViews DESC LIMIT 10 OFFSET 100; +SELECT WindowClientWidth, WindowClientHeight, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-01' AND EventDate <= '2013-07-31' AND IsRefresh = 0 AND DontCountHits = 0 AND URLHash = 2868770270353813622 GROUP BY WindowClientWidth, WindowClientHeight ORDER BY PageViews DESC LIMIT 10 OFFSET 10000; +SELECT DATE_TRUNC('minute', EventTime) AS M, COUNT(*) AS PageViews FROM hits WHERE CounterID = 62 AND EventDate >= '2013-07-14' AND EventDate <= '2013-07-15' AND IsRefresh = 0 AND DontCountHits = 0 GROUP BY DATE_TRUNC('minute', EventTime) ORDER BY DATE_TRUNC('minute', EventTime) LIMIT 10 OFFSET 1000; diff --git a/duckdb-parquet/query.py b/duckdb-parquet/query.py new file mode 100755 index 000000000..c2d6c4a9b --- /dev/null +++ b/duckdb-parquet/query.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import duckdb +import timeit +import psutil +import sys + +query = sys.stdin.read() +print(query) + +con = duckdb.connect(database="my-db.duckdb", read_only=False) +# enable parquet metadata cache +con.execute("PRAGMA enable_object_cache") + +for try_num in range(3): + start = timeit.default_timer() + results = con.execute(query).fetchall() + end = timeit.default_timer() + print(end - start) diff --git a/duckdb-parquet/results/c6a.4xlarge.json b/duckdb-parquet/results/c6a.4xlarge.json new file mode 100644 index 000000000..05d85be91 --- /dev/null +++ b/duckdb-parquet/results/c6a.4xlarge.json @@ -0,0 +1,58 @@ +{ + "system": "DuckDB (Parquet)", + "date": "2022-11-15", + "machine": "c6a.4xlarge, 500gb gp2", + "cluster_size": 1, + "comment": "", + + "tags": ["C++", "column-oriented", "embedded", "stateless"], + + "load_time": 0, + "data_size": 14737666736, + + "result": [ +[0.15255265499990855,0.032177488999877824,0.03128326899991407], +[0.1512561879999339,0.05458722900016255,0.05392151399996692], +[0.17167986499998733,0.09995069000001422,0.09747308599980897], +[0.32638904600003116,0.08025165799995193,0.07781587599993145], +[1.3622741589999805,0.8020002760001717,0.7882643820000794], +[1.5986611480000192,0.905206084999918,0.8923251289998007], +[0.19578096999998706,0.1727834680000342,0.17144673999996485], +[0.14916418200004955,0.05640668699993512,0.05402569700004278], +[1.2932305809999889,0.9019594260000758,0.902378624999983], +[1.962573343000031,1.29343327100014,1.3015213239998502], +[0.504676014999859,0.2644338150000749,0.2537441370000124], +[0.8143152309999095,0.31369776199994703,0.29620394999983546], +[1.1580296610000005,0.7799177189999682,0.7586700070000916], +[3.4789537280000786,1.2198064450001311,1.206218268000157], +[1.2482245060000423,0.8424065669998981,0.8678128400001697], +[2.1837149620000673,0.8448476789999404,0.8492143610001222], +[2.9010631749999902,1.8770421239998996,1.859835455999928], +[4.6367616359998465,1.8144295800000236,2.977320546000101], +[5.932184310000139,3.7547057240001322,3.4905751789999613], +[1.0825107470000148,0.6089946629999758,0.6027930899999774], +[9.431518925000091,1.8313576000000467,1.8272091119999914], +[11.088325851000036,1.7101613590000397,1.7332129410001471], +[21.759323214000005,3.6137633480000204,3.5981952510001065], +[55.858323720000044,11.130785724999896,11.137916557000153], +[2.62945403599997,0.48112061599999834,0.47660431999997854], +[0.724943537999934,0.3750543330002074,0.37342856700001903], +[2.68823736000013,0.4855612100000144,0.5017041849998805], +[9.432771488999833,1.4729457909998018,1.4764195239999935], +[8.373684226000023,4.492152146999842,4.521108621999929], +[7.942450724999844,1.5387269580000975,1.547872401999939], +[2.4811867640000855,0.921913929000084,1.4909157100000812], +[6.329192314000011,1.1808154699999704,1.142661366000084], +[9.606873708999956,5.282511374999785,6.381937246000007], +[10.85659978700005,3.1545218410001326,3.1670173970001088], +[10.854515859000003,3.186118347999809,3.2063636679999945], +[1.615416661999916,0.8797393360000569,0.8869118689999596], +[0.27963824800008297,0.1805793179999,0.18357048100006068], +[0.18112159000020256,0.1387902070000564,0.13812656300001436], +[0.19202985199990508,0.13907866399995328,0.13576146300010805], +[0.4347770939998554,0.3260163970001031,0.3153109580000546], +[0.15686156200013102,0.08243094600015866,0.08062338900003851], +[0.1538962489998994,0.0836899139999332,0.08601155300016217], +[0.16666654100004052,0.08488733899980616,0.08224888199993075] +] +} diff --git a/duckdb-parquet/run.sh b/duckdb-parquet/run.sh new file mode 100755 index 000000000..64df8c608 --- /dev/null +++ b/duckdb-parquet/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cat queries.sql | while read query; do + sync + echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null + + ./query.py <<< "${query}" +done