Skip to content

Instantly share code, notes, and snippets.

@auxten
Created May 7, 2023 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auxten/1d691e5ac383dcf4e6387d2380ea0670 to your computer and use it in GitHub Desktop.
Save auxten/1d691e5ac383dcf4e6387d2380ea0670 to your computer and use it in GitHub Desktop.
chdb on uniswap_v2_trading_data
import chdb
data_path = "/home/Clickhouse/bench/uniswap_v2_trading_data/*.csv"
small_data_path = "/home/Clickhouse/bench/uniswap_v2_trading_data/v2_trading_history_14025747.csv"
print("Sample: ",
chdb.query(f"select * from file('{data_path}', 'CSVWithNames') limit 10", "PrettyCompact").data())
print("Count: ", chdb.query(f"select count(*) from file('{data_path}', 'CSVWithNames')").data())
# ret = chdb.query(
# f"select timestamp, tx, amount1_in, amount1_out from file('{data_path}', 'CSVWithNames') limit 10", "Pretty")
# print(ret.data())
# avg of position_in_block group by gecko_id0
ret = chdb.query(f"select gecko_id0, count(*) cnt, avg(position_in_block) pos \
from file('{data_path}', 'CSVWithNames') group by gecko_id0 order by cnt desc limit 10",
"Pretty")
print("Avg of position_in_block group by gecko_id0: ", ret.data())
ret = chdb.query(f"select gecko_id0, avg(position_in_block) pos \
from file('{data_path}', 'CSVWithNames') group by gecko_id0 limit 10", "DataFrame")
print(ret, type(ret))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment