Created
March 12, 2023 00:39
-
-
Save vimota/1735ed29bcce83695f170192501bac75 to your computer and use it in GitHub Desktop.
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
import duckdb | |
# Check if the file exists: | |
import os | |
path = "/tmp/localpy.duckdb" | |
file_exists = os.path.isfile(path) | |
con = duckdb.connect(path) | |
con.sql("install httpfs") | |
if not file_exists: | |
con.sql( | |
"create table taxi as select *, md5(total_amount), md5(tpep_pickup_datetime), md5(tpep_dropoff_datetime) FROM parquet_scan('https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2022-01.parquet')" | |
) | |
con.sql( | |
"insert into taxi select *, md5(total_amount), md5(tpep_pickup_datetime), md5(tpep_dropoff_datetime) FROM parquet_scan('https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2022-01.parquet')" | |
) | |
con.sql( | |
"create table taxi_relationships as select vendorID, vendorID + 1 as follower FROM taxi" | |
) | |
print("Table created") | |
for i in range(100): | |
input("Press Enter to continue...") | |
print( | |
con.sql( | |
""" | |
with "inner" as (select r.follower as "id" from "taxi_relationships" as "r" where "r"."VendorID" in ('1', '2') group by "id") select * from "inner" inner join "taxi" as "u" on "inner"."id" = "u"."VendorId" order by u.total_amount desc limit 30 | |
""" | |
) | |
) | |
print("Query 1 executed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment