betodealmeida edited a comment on issue #13491:
URL: https://github.com/apache/superset/issues/13491#issuecomment-792057345
Since `FETCH_MANY` is inefficient, another way to solve the problem of
databases like Teradata and Firebird that use a syntax other than `LIMIT` is to
implement the `apply_limit_to_sql` method in the DB engine spec. The base
method (in `superset/db_engine_specs/base.py`) is:
```python
@classmethod
def apply_limit_to_sql(cls, sql: str, limit: int, database: "Database")
-> str:
"""
Alters the SQL statement to apply a LIMIT clause
:param sql: SQL query
:param limit: Maximum number of rows to be returned by the query
:param database: Database instance
:return: SQL query with limit clause
"""
# TODO: Fix circular import caused by importing Database
if cls.limit_method == LimitMethod.WRAP_SQL:
sql = sql.strip("\t\n ;")
qry = (
select("*")
.select_from(TextAsFrom(text(sql), ["*"]).alias("inner_qry"))
.limit(limit)
)
return database.compile_sqla_query(qry)
if cls.limit_method == LimitMethod.FORCE_LIMIT:
parsed_query = sql_parse.ParsedQuery(sql)
sql = parsed_query.set_or_update_query_limit(limit)
return sql
```
You could implement a custom method in
`superset/db_engine_specs/teradata.py` that applies the correct syntax for
Teradata.
This approach would be better than the one you have modifying
`superset/db_engine_specs/base.py`, `superset/sql_lab.py`, and
`superset/sql_parse.py`, since all the changes needed to support Teradata would
be self-contained in `db_engine_specs/teradata.py`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]