Created
May 7, 2021 16:38
-
-
Save takezoe/834189dbcbb9f761a4b20a4bbfbddaac to your computer and use it in GitHub Desktop.
Test program for trino-client-ruby using tiny-presto which is library to launch Trino/Presto using docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'trino-client' | |
require 'tiny-presto' | |
client = Trino::Client.new(server: 'localhost:8080', catalog: 'memory', user: 'test-user', schema: 'default') | |
cluster = TinyPresto::Cluster.new('trinodb/trino', '355') | |
container = cluster.run | |
loop do | |
begin | |
# Make sure to all workers are available. | |
client.run('show schemas') | |
break | |
rescue StandardError => exception | |
puts "Waiting for cluster ready... #{exception}" | |
sleep(5) | |
end | |
end | |
puts 'Cluster is ready' | |
begin | |
# tpch q01 | |
sql = <<'EOS' | |
SELECT | |
l.returnflag, | |
l.linestatus, | |
sum(l.quantity) AS sum_qty, | |
sum(l.extendedprice) AS sum_base_price, | |
sum(l.extendedprice * (1 - l.discount)) AS sum_disc_price, | |
sum(l.extendedprice * (1 - l.discount) * (1 + l.tax)) AS sum_charge, | |
avg(l.quantity) AS avg_qty, | |
avg(l.extendedprice) AS avg_price, | |
avg(l.discount) AS avg_disc, | |
count(*) AS count_order | |
FROM | |
"tpch"."tiny"."lineitem" AS l | |
WHERE | |
l.shipdate <= DATE '1998-12-01' - INTERVAL '90' DAY | |
GROUP BY | |
l.returnflag, | |
l.linestatus | |
ORDER BY | |
l.returnflag, | |
l.linestatus | |
EOS | |
columns, rows = client.run(sql) | |
puts columns | |
puts rows | |
ensure | |
cluster.stop | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment