Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit ca3ec72

Browse files
committed
optimization hint support for oracle and mysql
1 parent 2fe17a1 commit ca3ec72

File tree

12 files changed

+44
-5
lines changed

12 files changed

+44
-5
lines changed

sqeleton/abcs/database_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ def offset_limit(self, offset: Optional[int] = None, limit: Optional[int] = None
201201
def explain_as_text(self, query: str) -> str:
202202
"Provide SQL for explaining a query, returned as table(varchar)"
203203

204+
@abstractmethod
205+
def optimizer_hints(self, hints: str) -> str:
206+
"Provide SQL for enclosing optimizer hints"
207+
204208
@abstractmethod
205209
def timestamp_value(self, t: datetime) -> str:
206210
"Provide SQL for the given timestamp value"

sqeleton/databases/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def current_timestamp(self) -> str:
168168
def explain_as_text(self, query: str) -> str:
169169
return f"EXPLAIN {query}"
170170

171+
def optimizer_hints(self, s: str):
172+
return f"/*+ {s} */ " if s else ""
173+
171174
def _constant_value(self, v):
172175
if v is None:
173176
return "NULL"

sqeleton/databases/bigquery.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def type_repr(self, t) -> str:
137137
def set_timezone_to_utc(self) -> str:
138138
raise NotImplementedError()
139139

140+
def optimizer_hints(self, hints: str) -> str:
141+
raise NotImplementedError("Optimizer hints not yet implemented in bigquery")
142+
140143

141144
class BigQuery(Database):
142145
CONNECT_URI_HELP = "bigquery://<project>/<dataset>"

sqeleton/databases/clickhouse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ def set_timezone_to_utc(self) -> str:
162162
def current_timestamp(self) -> str:
163163
return "now()"
164164

165+
def optimizer_hints(self, hints: str) -> str:
166+
raise NotImplementedError("Optimizer hints not yet implemented in clickhouse")
167+
165168

166169
class Clickhouse(ThreadedDatabase):
167170
dialect = Dialect()

sqeleton/databases/databricks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def _convert_db_precision_to_digits(self, p: int) -> int:
9494
def set_timezone_to_utc(self) -> str:
9595
return "SET TIME ZONE 'UTC'"
9696

97+
def optimizer_hints(self, hints: str) -> str:
98+
raise NotImplementedError("Optimizer hints not yet implemented in databricks")
99+
97100

98101
class Databricks(ThreadedDatabase):
99102
dialect = Dialect()

sqeleton/databases/duckdb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def set_timezone_to_utc(self) -> str:
136136
def current_timestamp(self) -> str:
137137
return "current_timestamp"
138138

139+
def optimizer_hints(self, hints: str) -> str:
140+
raise NotImplementedError("Optimizer hints not yet implemented in duckdb")
141+
139142

140143
class DuckDB(Database):
141144
dialect = Dialect()

sqeleton/databases/postgresql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def set_timezone_to_utc(self) -> str:
9696
def current_timestamp(self) -> str:
9797
return "current_timestamp"
9898

99+
def optimizer_hints(self, hints: str) -> str:
100+
raise NotImplementedError("Optimizer hints not yet implemented in postgresql")
101+
99102

100103
class PostgreSQL(ThreadedDatabase):
101104
dialect = PostgresqlDialect()

sqeleton/databases/presto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ def set_timezone_to_utc(self) -> str:
141141
def current_timestamp(self) -> str:
142142
return "current_timestamp"
143143

144+
def optimizer_hints(self, hints: str) -> str:
145+
raise NotImplementedError("Optimizer hints not yet implemented in presto")
146+
144147

145148
class Presto(Database):
146149
dialect = Dialect()

sqeleton/databases/redshift.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def concat(self, items: List[str]) -> str:
5757
def is_distinct_from(self, a: str, b: str) -> str:
5858
return f"({a} IS NULL != {b} IS NULL) OR ({a}!={b})"
5959

60+
def optimizer_hints(self, hints: str) -> str:
61+
raise NotImplementedError("Optimizer hints not yet implemented in redshift")
6062

6163
class Redshift(PostgreSQL):
6264
dialect = Dialect()

sqeleton/databases/snowflake.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def table_information(self) -> Compilable:
136136
def set_timezone_to_utc(self) -> str:
137137
return "ALTER SESSION SET TIMEZONE = 'UTC'"
138138

139+
def optimizer_hints(self, hints: str) -> str:
140+
raise NotImplementedError("Optimizer hints not yet implemented in snowflake")
141+
139142

140143
class Snowflake(Database):
141144
dialect = Dialect()

0 commit comments

Comments
 (0)