PostBOUND 0.22.2__tar.gz → 0.23.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {postbound-0.22.2 → postbound-0.23.1}/PKG-INFO +7 -21
- {postbound-0.22.2 → postbound-0.23.1}/PostBOUND.egg-info/PKG-INFO +7 -21
- {postbound-0.22.2 → postbound-0.23.1}/PostBOUND.egg-info/SOURCES.txt +0 -1
- {postbound-0.22.2 → postbound-0.23.1}/PostBOUND.egg-info/requires.txt +1 -4
- {postbound-0.22.2 → postbound-0.23.1}/README.md +5 -17
- {postbound-0.22.2 → postbound-0.23.1}/postbound/__init__.pyi +0 -2
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_core.py +45 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_hints.py +23 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_ipython.py +15 -6
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_pipelines.py +80 -14
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_qep.py +21 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_stages.py +14 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/bench.py +4 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/db/__init__.py +6 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/db/_cache.py +16 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/db/_db.py +818 -361
- {postbound-0.22.2 → postbound-0.23.1}/postbound/db/_stats.py +11 -11
- {postbound-0.22.2 → postbound-0.23.1}/postbound/duckdb/_duckdb.py +103 -128
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/__init__.pyi +2 -5
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/_cardinalities.py +190 -4
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/_dynprog.py +11 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/_native.py +15 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/_randomized.py +10 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/postgres/_config.py +3 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/postgres/_explain.py +18 -8
- {postbound-0.22.2 → postbound-0.23.1}/postbound/postgres/_pg.py +252 -314
- {postbound-0.22.2 → postbound-0.23.1}/postbound/qal/__init__.py +2 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/qal/_formatter.py +4 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/qal/_qal.py +454 -6
- {postbound-0.22.2 → postbound-0.23.1}/postbound/relalg.py +150 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/train/_train.py +9 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/transform.py +56 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/collections.py +11 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/dicts.py +10 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/jsonize.py +2 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/misc.py +6 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/num.py +75 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/nx.py +5 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/proc.py +3 -1
- {postbound-0.22.2 → postbound-0.23.1}/postbound/validation.py +41 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/workloads.py +6 -1
- {postbound-0.22.2 → postbound-0.23.1}/pyproject.toml +51 -59
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_benchmarking.py +19 -0
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_core.py +2 -0
- postbound-0.23.1/tests/test_duckdb.py +332 -0
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_postgres.py +44 -0
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_qal.py +7 -2
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_util.py +5 -0
- postbound-0.22.2/postbound/mysql.py +0 -1164
- postbound-0.22.2/tests/test_duckdb.py +0 -156
- {postbound-0.22.2 → postbound-0.23.1}/LICENSE.txt +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/PostBOUND.egg-info/dependency_links.txt +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/PostBOUND.egg-info/top_level.txt +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/_base.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/duckdb/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/_enumeration.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/opt/_helpers.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/parser.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/postgres/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/postgres/_ctl.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/train/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/__init__.pyi +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/_df.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/_errors.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/logging.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/stats.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/system.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/util/typing.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/__init__.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/__init__.pyi +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/fdl.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/graphs.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/optimizer.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/plots.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/postbound/vis/trees.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/setup.cfg +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_docs.py +0 -0
- {postbound-0.22.2 → postbound-0.23.1}/tests/test_relalg.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PostBOUND
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.23.1
|
|
4
4
|
Summary: PostBOUND is a research framework to prototype and benchmark database query optimizers
|
|
5
5
|
Author-email: Rico Bergmann <rico.bergmann1@tu-dresden.de>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -21,14 +21,12 @@ Requires-Dist: numpy~=2.3
|
|
|
21
21
|
Requires-Dist: pandas~=2.3
|
|
22
22
|
Requires-Dist: pglast~=7.10
|
|
23
23
|
Requires-Dist: psycopg[binary]~=3.2
|
|
24
|
-
Requires-Dist: quacklab
|
|
24
|
+
Requires-Dist: quacklab==2.0.2
|
|
25
25
|
Requires-Dist: tqdm~=4.67
|
|
26
26
|
Provides-Extra: vis
|
|
27
27
|
Requires-Dist: matplotlib~=3.10; extra == "vis"
|
|
28
28
|
Requires-Dist: seaborn~=0.13; extra == "vis"
|
|
29
29
|
Requires-Dist: graphviz~=0.21; extra == "vis"
|
|
30
|
-
Provides-Extra: mysql
|
|
31
|
-
Requires-Dist: mysql-connector-python~=9.5; extra == "mysql"
|
|
32
30
|
Dynamic: license-file
|
|
33
31
|
|
|
34
32
|
# PostBOUND
|
|
@@ -111,7 +109,7 @@ For DuckDB, PostBOUND uses [quacklab](https://github.com/rbergm/quacklab) hints
|
|
|
111
109
|
|
|
112
110
|
> [!NOTE]
|
|
113
111
|
> PostBOUND's database interaction is designed to be independent of a specific system (such as PostgreSQL, Oracle, ...).
|
|
114
|
-
>
|
|
112
|
+
> Currently, we focus on the Postgres (most complete) and DuckDB backends.
|
|
115
113
|
> This is due to practical reasons, mostly our own time budget and the popularity of the two systems in the optimizer research
|
|
116
114
|
> community.
|
|
117
115
|
|
|
@@ -146,16 +144,11 @@ class RandomJoinOrder(pb.JoinOrdering):
|
|
|
146
144
|
if not pb.qal.is_select_query(query):
|
|
147
145
|
raise pb.OptimizationError("Expected a SELECT query")
|
|
148
146
|
|
|
149
|
-
initial_table, *free_tables = random.sample(
|
|
150
|
-
list(query.tables()), k=len(query.tables())
|
|
151
|
-
)
|
|
147
|
+
initial_table, *free_tables = random.sample(list(query.tables()), k=len(query.tables()))
|
|
152
148
|
join_tree = pb.JoinTree(base_table=initial_table)
|
|
153
149
|
|
|
154
150
|
while free_tables:
|
|
155
|
-
candidates = [
|
|
156
|
-
table for table in free_tables
|
|
157
|
-
if query.joins_between(table, join_tree.tables())
|
|
158
|
-
]
|
|
151
|
+
candidates = [table for table in free_tables if query.joins_between(table, join_tree.tables())]
|
|
159
152
|
next_table = random.choice(candidates)
|
|
160
153
|
join_tree = join_tree.join_with(next_table)
|
|
161
154
|
free_tables.remove(next_table)
|
|
@@ -169,11 +162,7 @@ class RandomJoinOrder(pb.JoinOrdering):
|
|
|
169
162
|
pg_stats = pb.postgres.connect(config_file=".psycopg_connection_stats")
|
|
170
163
|
stats = pb.workloads.stats()
|
|
171
164
|
|
|
172
|
-
optimization_pipeline = (
|
|
173
|
-
pb.MultiStageOptimizationPipeline(pg_stats)
|
|
174
|
-
.use(RandomJoinOrder())
|
|
175
|
-
.build()
|
|
176
|
-
)
|
|
165
|
+
optimization_pipeline = pb.MultiStageOptimizationPipeline(pg_stats).use(RandomJoinOrder()).build()
|
|
177
166
|
|
|
178
167
|
# (Step 3): in this example we just compare against the native Postgres optimizer
|
|
179
168
|
# Therefore, we do not need to setup any additional optimizers.
|
|
@@ -181,9 +170,7 @@ optimization_pipeline = (
|
|
|
181
170
|
# Step 4: execute the workload.
|
|
182
171
|
# We use the QueryPreparation to prewarm the database buffer and run all
|
|
183
172
|
# queries as EXPLAIN ANALYZE.
|
|
184
|
-
query_prep = pb.bench.QueryPreparation(
|
|
185
|
-
prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"]
|
|
186
|
-
)
|
|
173
|
+
query_prep = pb.bench.QueryPreparation(prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"])
|
|
187
174
|
native_results = pb.bench.execute_workload(
|
|
188
175
|
stats,
|
|
189
176
|
on=pg_stats,
|
|
@@ -200,7 +187,6 @@ optimized_results = pb.bench.execute_workload(
|
|
|
200
187
|
progressive_output="stats-results-optimized.csv",
|
|
201
188
|
logger="tqdm",
|
|
202
189
|
)
|
|
203
|
-
|
|
204
190
|
```
|
|
205
191
|
|
|
206
192
|
## 🤬 Issues
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PostBOUND
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.23.1
|
|
4
4
|
Summary: PostBOUND is a research framework to prototype and benchmark database query optimizers
|
|
5
5
|
Author-email: Rico Bergmann <rico.bergmann1@tu-dresden.de>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -21,14 +21,12 @@ Requires-Dist: numpy~=2.3
|
|
|
21
21
|
Requires-Dist: pandas~=2.3
|
|
22
22
|
Requires-Dist: pglast~=7.10
|
|
23
23
|
Requires-Dist: psycopg[binary]~=3.2
|
|
24
|
-
Requires-Dist: quacklab
|
|
24
|
+
Requires-Dist: quacklab==2.0.2
|
|
25
25
|
Requires-Dist: tqdm~=4.67
|
|
26
26
|
Provides-Extra: vis
|
|
27
27
|
Requires-Dist: matplotlib~=3.10; extra == "vis"
|
|
28
28
|
Requires-Dist: seaborn~=0.13; extra == "vis"
|
|
29
29
|
Requires-Dist: graphviz~=0.21; extra == "vis"
|
|
30
|
-
Provides-Extra: mysql
|
|
31
|
-
Requires-Dist: mysql-connector-python~=9.5; extra == "mysql"
|
|
32
30
|
Dynamic: license-file
|
|
33
31
|
|
|
34
32
|
# PostBOUND
|
|
@@ -111,7 +109,7 @@ For DuckDB, PostBOUND uses [quacklab](https://github.com/rbergm/quacklab) hints
|
|
|
111
109
|
|
|
112
110
|
> [!NOTE]
|
|
113
111
|
> PostBOUND's database interaction is designed to be independent of a specific system (such as PostgreSQL, Oracle, ...).
|
|
114
|
-
>
|
|
112
|
+
> Currently, we focus on the Postgres (most complete) and DuckDB backends.
|
|
115
113
|
> This is due to practical reasons, mostly our own time budget and the popularity of the two systems in the optimizer research
|
|
116
114
|
> community.
|
|
117
115
|
|
|
@@ -146,16 +144,11 @@ class RandomJoinOrder(pb.JoinOrdering):
|
|
|
146
144
|
if not pb.qal.is_select_query(query):
|
|
147
145
|
raise pb.OptimizationError("Expected a SELECT query")
|
|
148
146
|
|
|
149
|
-
initial_table, *free_tables = random.sample(
|
|
150
|
-
list(query.tables()), k=len(query.tables())
|
|
151
|
-
)
|
|
147
|
+
initial_table, *free_tables = random.sample(list(query.tables()), k=len(query.tables()))
|
|
152
148
|
join_tree = pb.JoinTree(base_table=initial_table)
|
|
153
149
|
|
|
154
150
|
while free_tables:
|
|
155
|
-
candidates = [
|
|
156
|
-
table for table in free_tables
|
|
157
|
-
if query.joins_between(table, join_tree.tables())
|
|
158
|
-
]
|
|
151
|
+
candidates = [table for table in free_tables if query.joins_between(table, join_tree.tables())]
|
|
159
152
|
next_table = random.choice(candidates)
|
|
160
153
|
join_tree = join_tree.join_with(next_table)
|
|
161
154
|
free_tables.remove(next_table)
|
|
@@ -169,11 +162,7 @@ class RandomJoinOrder(pb.JoinOrdering):
|
|
|
169
162
|
pg_stats = pb.postgres.connect(config_file=".psycopg_connection_stats")
|
|
170
163
|
stats = pb.workloads.stats()
|
|
171
164
|
|
|
172
|
-
optimization_pipeline = (
|
|
173
|
-
pb.MultiStageOptimizationPipeline(pg_stats)
|
|
174
|
-
.use(RandomJoinOrder())
|
|
175
|
-
.build()
|
|
176
|
-
)
|
|
165
|
+
optimization_pipeline = pb.MultiStageOptimizationPipeline(pg_stats).use(RandomJoinOrder()).build()
|
|
177
166
|
|
|
178
167
|
# (Step 3): in this example we just compare against the native Postgres optimizer
|
|
179
168
|
# Therefore, we do not need to setup any additional optimizers.
|
|
@@ -181,9 +170,7 @@ optimization_pipeline = (
|
|
|
181
170
|
# Step 4: execute the workload.
|
|
182
171
|
# We use the QueryPreparation to prewarm the database buffer and run all
|
|
183
172
|
# queries as EXPLAIN ANALYZE.
|
|
184
|
-
query_prep = pb.bench.QueryPreparation(
|
|
185
|
-
prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"]
|
|
186
|
-
)
|
|
173
|
+
query_prep = pb.bench.QueryPreparation(prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"])
|
|
187
174
|
native_results = pb.bench.execute_workload(
|
|
188
175
|
stats,
|
|
189
176
|
on=pg_stats,
|
|
@@ -200,7 +187,6 @@ optimized_results = pb.bench.execute_workload(
|
|
|
200
187
|
progressive_output="stats-results-optimized.csv",
|
|
201
188
|
logger="tqdm",
|
|
202
189
|
)
|
|
203
|
-
|
|
204
190
|
```
|
|
205
191
|
|
|
206
192
|
## 🤬 Issues
|
|
@@ -78,7 +78,7 @@ For DuckDB, PostBOUND uses [quacklab](https://github.com/rbergm/quacklab) hints
|
|
|
78
78
|
|
|
79
79
|
> [!NOTE]
|
|
80
80
|
> PostBOUND's database interaction is designed to be independent of a specific system (such as PostgreSQL, Oracle, ...).
|
|
81
|
-
>
|
|
81
|
+
> Currently, we focus on the Postgres (most complete) and DuckDB backends.
|
|
82
82
|
> This is due to practical reasons, mostly our own time budget and the popularity of the two systems in the optimizer research
|
|
83
83
|
> community.
|
|
84
84
|
|
|
@@ -113,16 +113,11 @@ class RandomJoinOrder(pb.JoinOrdering):
|
|
|
113
113
|
if not pb.qal.is_select_query(query):
|
|
114
114
|
raise pb.OptimizationError("Expected a SELECT query")
|
|
115
115
|
|
|
116
|
-
initial_table, *free_tables = random.sample(
|
|
117
|
-
list(query.tables()), k=len(query.tables())
|
|
118
|
-
)
|
|
116
|
+
initial_table, *free_tables = random.sample(list(query.tables()), k=len(query.tables()))
|
|
119
117
|
join_tree = pb.JoinTree(base_table=initial_table)
|
|
120
118
|
|
|
121
119
|
while free_tables:
|
|
122
|
-
candidates = [
|
|
123
|
-
table for table in free_tables
|
|
124
|
-
if query.joins_between(table, join_tree.tables())
|
|
125
|
-
]
|
|
120
|
+
candidates = [table for table in free_tables if query.joins_between(table, join_tree.tables())]
|
|
126
121
|
next_table = random.choice(candidates)
|
|
127
122
|
join_tree = join_tree.join_with(next_table)
|
|
128
123
|
free_tables.remove(next_table)
|
|
@@ -136,11 +131,7 @@ class RandomJoinOrder(pb.JoinOrdering):
|
|
|
136
131
|
pg_stats = pb.postgres.connect(config_file=".psycopg_connection_stats")
|
|
137
132
|
stats = pb.workloads.stats()
|
|
138
133
|
|
|
139
|
-
optimization_pipeline = (
|
|
140
|
-
pb.MultiStageOptimizationPipeline(pg_stats)
|
|
141
|
-
.use(RandomJoinOrder())
|
|
142
|
-
.build()
|
|
143
|
-
)
|
|
134
|
+
optimization_pipeline = pb.MultiStageOptimizationPipeline(pg_stats).use(RandomJoinOrder()).build()
|
|
144
135
|
|
|
145
136
|
# (Step 3): in this example we just compare against the native Postgres optimizer
|
|
146
137
|
# Therefore, we do not need to setup any additional optimizers.
|
|
@@ -148,9 +139,7 @@ optimization_pipeline = (
|
|
|
148
139
|
# Step 4: execute the workload.
|
|
149
140
|
# We use the QueryPreparation to prewarm the database buffer and run all
|
|
150
141
|
# queries as EXPLAIN ANALYZE.
|
|
151
|
-
query_prep = pb.bench.QueryPreparation(
|
|
152
|
-
prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"]
|
|
153
|
-
)
|
|
142
|
+
query_prep = pb.bench.QueryPreparation(prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"])
|
|
154
143
|
native_results = pb.bench.execute_workload(
|
|
155
144
|
stats,
|
|
156
145
|
on=pg_stats,
|
|
@@ -167,7 +156,6 @@ optimized_results = pb.bench.execute_workload(
|
|
|
167
156
|
progressive_output="stats-results-optimized.csv",
|
|
168
157
|
logger="tqdm",
|
|
169
158
|
)
|
|
170
|
-
|
|
171
159
|
```
|
|
172
160
|
|
|
173
161
|
## 🤬 Issues
|
|
@@ -8,7 +8,6 @@ from . import (
|
|
|
8
8
|
bench,
|
|
9
9
|
db,
|
|
10
10
|
duckdb,
|
|
11
|
-
mysql,
|
|
12
11
|
opt,
|
|
13
12
|
parser,
|
|
14
13
|
postgres,
|
|
@@ -135,7 +134,6 @@ __all__ = [
|
|
|
135
134
|
"db",
|
|
136
135
|
"duckdb",
|
|
137
136
|
"jointree_from_plan",
|
|
138
|
-
"mysql",
|
|
139
137
|
"operators_from_plan",
|
|
140
138
|
"opt",
|
|
141
139
|
"parameters_from_plan",
|
|
@@ -13,6 +13,7 @@ from typing import (
|
|
|
13
13
|
TypeGuard,
|
|
14
14
|
TypeVar,
|
|
15
15
|
overload,
|
|
16
|
+
override,
|
|
16
17
|
)
|
|
17
18
|
|
|
18
19
|
from .util._errors import StateError
|
|
@@ -396,6 +397,7 @@ class Cardinality(Number):
|
|
|
396
397
|
return complex(math.inf)
|
|
397
398
|
return complex(float(self.value))
|
|
398
399
|
|
|
400
|
+
@override
|
|
399
401
|
def __eq__(self, other: object) -> bool:
|
|
400
402
|
match other:
|
|
401
403
|
case Cardinality():
|
|
@@ -419,13 +421,16 @@ class Cardinality(Number):
|
|
|
419
421
|
|
|
420
422
|
return NotImplemented
|
|
421
423
|
|
|
424
|
+
@override
|
|
422
425
|
def __hash__(self) -> int:
|
|
423
426
|
# There is no need to hash _valid, since it is directly derived from _nan and _inf
|
|
424
427
|
return hash(self.raw_value)
|
|
425
428
|
|
|
429
|
+
@override
|
|
426
430
|
def __repr__(self) -> str:
|
|
427
431
|
return str(self)
|
|
428
432
|
|
|
433
|
+
@override
|
|
429
434
|
def __str__(self) -> str:
|
|
430
435
|
if self._nan:
|
|
431
436
|
return "NaN"
|
|
@@ -722,6 +727,34 @@ class TableReference:
|
|
|
722
727
|
"""
|
|
723
728
|
return TableReference(full_name, alias, virtual=True, schema=schema, catalog=catalog)
|
|
724
729
|
|
|
730
|
+
@staticmethod
|
|
731
|
+
def from_components(components: Iterable[str]) -> TableReference:
|
|
732
|
+
"""Creates a new table reference from a sequence of components.
|
|
733
|
+
|
|
734
|
+
The components must contain the table name as the last element, optionally preceded by the schema and catalog.
|
|
735
|
+
For example, the following sequences are valid:
|
|
736
|
+
|
|
737
|
+
- ["movie"] -> TableReference("movie")
|
|
738
|
+
- ["public", "movie"] -> TableReference("movie", schema="public")
|
|
739
|
+
- ["my_catalog", "public", "movie"] -> TableReference("movie", schema="public", catalog="my_catalog")
|
|
740
|
+
|
|
741
|
+
If the components contain any other number of elements, an error is raised.
|
|
742
|
+
"""
|
|
743
|
+
if not isinstance(components, Sequence):
|
|
744
|
+
components = list(components)
|
|
745
|
+
|
|
746
|
+
match len(components):
|
|
747
|
+
case 1:
|
|
748
|
+
return TableReference(components[0])
|
|
749
|
+
case 2:
|
|
750
|
+
schema, name = components
|
|
751
|
+
return TableReference(name, schema=schema)
|
|
752
|
+
case 3:
|
|
753
|
+
catalog, schema, name = components
|
|
754
|
+
return TableReference(name, schema=schema, catalog=catalog)
|
|
755
|
+
case _:
|
|
756
|
+
raise ValueError(f"Could not parse table reference with components {components}")
|
|
757
|
+
|
|
725
758
|
def __init__(
|
|
726
759
|
self,
|
|
727
760
|
full_name: str,
|
|
@@ -1031,9 +1064,11 @@ class TableReference:
|
|
|
1031
1064
|
return NotImplemented
|
|
1032
1065
|
return self._normalized_identifier < other._normalized_identifier
|
|
1033
1066
|
|
|
1067
|
+
@override
|
|
1034
1068
|
def __hash__(self) -> int:
|
|
1035
1069
|
return self._hash_val
|
|
1036
1070
|
|
|
1071
|
+
@override
|
|
1037
1072
|
def __eq__(self, other: object) -> bool:
|
|
1038
1073
|
return (
|
|
1039
1074
|
isinstance(other, type(self))
|
|
@@ -1043,12 +1078,14 @@ class TableReference:
|
|
|
1043
1078
|
and self._normalized_catalog == other._normalized_catalog
|
|
1044
1079
|
)
|
|
1045
1080
|
|
|
1081
|
+
@override
|
|
1046
1082
|
def __repr__(self) -> str:
|
|
1047
1083
|
return (
|
|
1048
1084
|
f"TableReference(full_name='{self.full_name}', alias='{self.alias}', "
|
|
1049
1085
|
f"virtual={self.virtual}, schema='{self.schema}', catalog='{self.catalog}')"
|
|
1050
1086
|
)
|
|
1051
1087
|
|
|
1088
|
+
@override
|
|
1052
1089
|
def __str__(self) -> str:
|
|
1053
1090
|
return self._sql_repr
|
|
1054
1091
|
|
|
@@ -1319,9 +1356,11 @@ class ColumnReference:
|
|
|
1319
1356
|
return False
|
|
1320
1357
|
return self.table < other.table
|
|
1321
1358
|
|
|
1359
|
+
@override
|
|
1322
1360
|
def __hash__(self) -> int:
|
|
1323
1361
|
return self._hash_val
|
|
1324
1362
|
|
|
1363
|
+
@override
|
|
1325
1364
|
def __eq__(self, other: object) -> bool:
|
|
1326
1365
|
return (
|
|
1327
1366
|
isinstance(other, (ColumnReference, BoundColumnReference))
|
|
@@ -1336,12 +1375,15 @@ class ColumnReference:
|
|
|
1336
1375
|
tab = copy.deepcopy(self.table, memo)
|
|
1337
1376
|
return ColumnReference(str(self.name), tab)
|
|
1338
1377
|
|
|
1378
|
+
@override
|
|
1339
1379
|
def __reduce__(self) -> tuple:
|
|
1340
1380
|
return (self.__class__, (self._name, self._table))
|
|
1341
1381
|
|
|
1382
|
+
@override
|
|
1342
1383
|
def __repr__(self) -> str:
|
|
1343
1384
|
return f"ColumnReference(name='{self.name}', table={self.table!r})"
|
|
1344
1385
|
|
|
1386
|
+
@override
|
|
1345
1387
|
def __str__(self) -> str:
|
|
1346
1388
|
return self._sql_repr
|
|
1347
1389
|
|
|
@@ -1360,13 +1402,16 @@ class BoundColumnReference(ColumnReference):
|
|
|
1360
1402
|
__match_args__ = ("name", "table")
|
|
1361
1403
|
|
|
1362
1404
|
@property
|
|
1405
|
+
@override
|
|
1363
1406
|
def table(self) -> TableReference:
|
|
1364
1407
|
"""Get the table to which this column belongs. This is guaranteed to be set and will never be *None*."""
|
|
1365
1408
|
return self._table # type: ignore
|
|
1366
1409
|
|
|
1410
|
+
@override
|
|
1367
1411
|
def is_bound(self) -> bool:
|
|
1368
1412
|
return True
|
|
1369
1413
|
|
|
1414
|
+
@override
|
|
1370
1415
|
def drop_table_alias(self) -> BoundColumnReference:
|
|
1371
1416
|
return super().drop_table_alias() # type: ignore
|
|
1372
1417
|
|
|
@@ -4,7 +4,7 @@ import math
|
|
|
4
4
|
import warnings
|
|
5
5
|
from collections.abc import Collection, Container, Iterable, Sequence
|
|
6
6
|
from enum import Enum
|
|
7
|
-
from typing import Any, Literal, Self, assert_never
|
|
7
|
+
from typing import Any, Literal, Self, assert_never, override
|
|
8
8
|
|
|
9
9
|
from . import util
|
|
10
10
|
from ._base import T
|
|
@@ -543,6 +543,7 @@ class PhysicalOperatorAssignment:
|
|
|
543
543
|
else:
|
|
544
544
|
return None
|
|
545
545
|
|
|
546
|
+
@override
|
|
546
547
|
def __hash__(self) -> int:
|
|
547
548
|
return hash(
|
|
548
549
|
(
|
|
@@ -552,6 +553,7 @@ class PhysicalOperatorAssignment:
|
|
|
552
553
|
)
|
|
553
554
|
)
|
|
554
555
|
|
|
556
|
+
@override
|
|
555
557
|
def __eq__(self, other: object) -> bool:
|
|
556
558
|
return (
|
|
557
559
|
isinstance(other, type(self))
|
|
@@ -560,9 +562,11 @@ class PhysicalOperatorAssignment:
|
|
|
560
562
|
and self.join_operators == other.join_operators
|
|
561
563
|
)
|
|
562
564
|
|
|
565
|
+
@override
|
|
563
566
|
def __repr__(self) -> str:
|
|
564
567
|
return str(self)
|
|
565
568
|
|
|
569
|
+
@override
|
|
566
570
|
def __str__(self) -> str:
|
|
567
571
|
global_str = ", ".join(f"{op.value}: {enabled}" for op, enabled in self.global_settings.items())
|
|
568
572
|
|
|
@@ -824,9 +828,11 @@ class PlanParameterization:
|
|
|
824
828
|
],
|
|
825
829
|
}
|
|
826
830
|
|
|
831
|
+
@override
|
|
827
832
|
def __repr__(self) -> str:
|
|
828
833
|
return str(self)
|
|
829
834
|
|
|
835
|
+
@override
|
|
830
836
|
def __str__(self) -> str:
|
|
831
837
|
return (
|
|
832
838
|
f"PlanParams(cards={self.cardinalities}, "
|
|
@@ -914,9 +920,11 @@ class ScanOperatorAssignment:
|
|
|
914
920
|
"parallel_workers": self.parallel_workers,
|
|
915
921
|
}
|
|
916
922
|
|
|
923
|
+
@override
|
|
917
924
|
def __hash__(self) -> int:
|
|
918
925
|
return self._hash_val
|
|
919
926
|
|
|
927
|
+
@override
|
|
920
928
|
def __eq__(self, other: object) -> bool:
|
|
921
929
|
return (
|
|
922
930
|
isinstance(other, type(self))
|
|
@@ -925,9 +933,11 @@ class ScanOperatorAssignment:
|
|
|
925
933
|
and self.parallel_workers == other.parallel_workers
|
|
926
934
|
)
|
|
927
935
|
|
|
936
|
+
@override
|
|
928
937
|
def __repr__(self) -> str:
|
|
929
938
|
return str(self)
|
|
930
939
|
|
|
940
|
+
@override
|
|
931
941
|
def __str__(self) -> str:
|
|
932
942
|
return f"{self.operator.value}({self.table})"
|
|
933
943
|
|
|
@@ -1052,9 +1062,11 @@ class JoinOperatorAssignment:
|
|
|
1052
1062
|
"parallel_workers": self.parallel_workers,
|
|
1053
1063
|
}
|
|
1054
1064
|
|
|
1065
|
+
@override
|
|
1055
1066
|
def __hash__(self) -> int:
|
|
1056
1067
|
return self._hash_val
|
|
1057
1068
|
|
|
1069
|
+
@override
|
|
1058
1070
|
def __eq__(self, other: object) -> bool:
|
|
1059
1071
|
return (
|
|
1060
1072
|
isinstance(other, type(self))
|
|
@@ -1063,9 +1075,11 @@ class JoinOperatorAssignment:
|
|
|
1063
1075
|
and self._parallel_workers == other._parallel_workers
|
|
1064
1076
|
)
|
|
1065
1077
|
|
|
1078
|
+
@override
|
|
1066
1079
|
def __repr__(self) -> str:
|
|
1067
1080
|
return str(self)
|
|
1068
1081
|
|
|
1082
|
+
@override
|
|
1069
1083
|
def __str__(self) -> str:
|
|
1070
1084
|
join_str = ", ".join(str(tab) for tab in self.join)
|
|
1071
1085
|
return f"{self.operator.value}({join_str})"
|
|
@@ -1141,9 +1155,11 @@ class DirectionalJoinOperatorAssignment(JoinOperatorAssignment):
|
|
|
1141
1155
|
"""
|
|
1142
1156
|
return self._outer
|
|
1143
1157
|
|
|
1158
|
+
@override
|
|
1144
1159
|
def is_directional(self) -> bool:
|
|
1145
1160
|
return True
|
|
1146
1161
|
|
|
1162
|
+
@override
|
|
1147
1163
|
def __json__(self) -> jsondict:
|
|
1148
1164
|
return {
|
|
1149
1165
|
"directional": True,
|
|
@@ -1155,6 +1171,7 @@ class DirectionalJoinOperatorAssignment(JoinOperatorAssignment):
|
|
|
1155
1171
|
|
|
1156
1172
|
__hash__ = JoinOperatorAssignment.__hash__
|
|
1157
1173
|
|
|
1174
|
+
@override
|
|
1158
1175
|
def __eq__(self, other: object) -> bool:
|
|
1159
1176
|
return (
|
|
1160
1177
|
isinstance(other, type(self))
|
|
@@ -1586,15 +1603,18 @@ class JoinTree[JoinTreeAnnotation](Container[TableReference]):
|
|
|
1586
1603
|
def __bool__(self) -> bool:
|
|
1587
1604
|
return not self.is_empty()
|
|
1588
1605
|
|
|
1606
|
+
@override
|
|
1589
1607
|
def __contains__(self, item: TableReference) -> bool:
|
|
1590
1608
|
return self.lookup(item) is not None
|
|
1591
1609
|
|
|
1592
1610
|
def __len__(self) -> int:
|
|
1593
1611
|
return len(self.tables())
|
|
1594
1612
|
|
|
1613
|
+
@override
|
|
1595
1614
|
def __hash__(self) -> int:
|
|
1596
1615
|
return self._hash_val
|
|
1597
1616
|
|
|
1617
|
+
@override
|
|
1598
1618
|
def __eq__(self, other: object) -> bool:
|
|
1599
1619
|
return (
|
|
1600
1620
|
isinstance(other, type(self))
|
|
@@ -1603,9 +1623,11 @@ class JoinTree[JoinTreeAnnotation](Container[TableReference]):
|
|
|
1603
1623
|
and self._inner == other._inner
|
|
1604
1624
|
)
|
|
1605
1625
|
|
|
1626
|
+
@override
|
|
1606
1627
|
def __repr__(self) -> str:
|
|
1607
1628
|
return str(self)
|
|
1608
1629
|
|
|
1630
|
+
@override
|
|
1609
1631
|
def __str__(self):
|
|
1610
1632
|
if self.is_scan():
|
|
1611
1633
|
assert self._table is not None
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from IPython.core.getipython import get_ipython
|
|
3
4
|
from IPython.lib import pretty
|
|
4
5
|
|
|
5
6
|
from ._hints import JoinTree, PhysicalOperatorAssignment, PlanParameterization
|
|
6
7
|
from ._qep import QueryPlan
|
|
7
|
-
from .qal import SqlQuery, format_quick
|
|
8
|
+
from .qal import SelectStatement, SetQuery, SqlQuery, format_quick
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
def pretty_print_query(query: SqlQuery, p: pretty.PrettyPrinter, cycle: bool) -> None:
|
|
@@ -43,8 +44,16 @@ def pretty_print_plan_params(parameters: PlanParameterization, p: pretty.PrettyP
|
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
def setup_pretty_printers() -> None:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
shell = get_ipython()
|
|
48
|
+
if shell is None:
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
plain_formatter = shell.display_formatter.formatters["text/plain"]
|
|
52
|
+
|
|
53
|
+
plain_formatter.for_type(SqlQuery, pretty_print_query)
|
|
54
|
+
plain_formatter.for_type(SelectStatement, pretty_print_query)
|
|
55
|
+
plain_formatter.for_type(SetQuery, pretty_print_query)
|
|
56
|
+
plain_formatter.for_type(QueryPlan, pretty_print_plan)
|
|
57
|
+
plain_formatter.for_type(JoinTree, pretty_print_join_tree)
|
|
58
|
+
plain_formatter.for_type(PhysicalOperatorAssignment, pretty_print_physical_ops)
|
|
59
|
+
plain_formatter.for_type(PlanParameterization, pretty_print_plan_params)
|