-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. support arbitrary db for rewrite 2. switch to rewrite2 3. support …
…partition from rewrite
- Loading branch information
1 parent
bed71fb
commit 0fca401
Showing
5 changed files
with
86 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,53 @@ | ||
""" | ||
Usage: | ||
tpch-fed.py --file=<file> | ||
tpch-fed.py [--file=<file>] [--dir=<dir>] [--runs=<runs>] | ||
Options: | ||
--file=<file> Query file. | ||
--file=<file> Query file. | ||
--dir=<dir> Query path. | ||
--runs=<runs> # runs [default: 1]. | ||
-h --help Show this screen. | ||
--version Show version. | ||
""" | ||
import os | ||
|
||
import os | ||
import time | ||
import connectorx as cx | ||
from contexttimer import Timer | ||
from docopt import docopt | ||
import pandas as pd | ||
from pathlib import Path | ||
|
||
def run_query_from_file(query_file): | ||
with open(query_file, "r") as f: | ||
sql = f.read() | ||
print(f"file: {query_file}") | ||
|
||
with Timer() as timer: | ||
df = cx.read_sql(db_map, sql, return_type="arrow") | ||
print(f"time in total: {timer.elapsed}, {len(df)} rows, {len(df.columns)} cols") | ||
print(df) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
args = docopt(__doc__, version="Naval Fate 2.0") | ||
query_file = args["--file"] | ||
|
||
db_map = { | ||
"db1": os.environ["DB1"], | ||
"db2": os.environ["DB2"], | ||
} | ||
print(f"dbs: {db_map}") | ||
db_map = {} | ||
db_conns = os.environ["FED_CONN"] | ||
for conn in db_conns.split(','): | ||
db_map[conn.split('=', 1)[0]] = conn.split('=', 1)[1] | ||
|
||
with open(query_file, "r") as f: | ||
sql = f.read() | ||
print(f"file: {query_file}") | ||
print(f"dbs: {db_map}") | ||
|
||
with Timer() as timer: | ||
df = cx.read_sql(db_map, sql, return_type="pandas") | ||
print("time in total:", timer.elapsed) | ||
for i in range(int(args["--runs"])): | ||
print(f"=============== run {i} ================") | ||
print() | ||
if args["--file"]: | ||
filename = args["--file"] | ||
run_query_from_file(filename) | ||
elif args["--dir"]: | ||
for filename in sorted(Path(args["--dir"]).glob("q*.sql")): | ||
run_query_from_file(filename) | ||
time.sleep(2) | ||
|
||
print(df) |
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
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
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
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