summaryrefslogtreecommitdiffstats
path: root/tests/tpch.py
blob: 0b6de63d77f591dd7a50f2f408fe47864cd1ddf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import time

from sqlglot.optimizer import optimize

INPUT = ""
OUTPUT = ""
NUM = 99
SCHEMA = {}
KIND = "DS"

with open(OUTPUT, "w", encoding="UTF-8") as fixture:
    for i in range(NUM):
        i = i + 1
        with open(INPUT.format(i=i), encoding="UTF-8") as file:
            original = "\n".join(
                line.rstrip()
                for line in file.read().split(";")[0].split("\n")
                if not line.startswith("--")
            )
            original = original.replace("`", '"')
            now = time.time()
            try:
                optimized = optimize(original, schema=SCHEMA)
            except Exception as e:
                print("****", i, e, "****")
                continue

            fixture.write(
                f"""--------------------------------------
-- TPC-{KIND} {i}
--------------------------------------
{original};
{optimized.sql(pretty=True)};

"""
            )
            print(i, time.time() - now)