mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: use sqlglot to set limit (#33473)
This commit is contained in:
@@ -761,11 +761,19 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
|
||||
)
|
||||
|
||||
def apply_limit_to_sql(
|
||||
self, sql: str, limit: int = 1000, force: bool = False
|
||||
self,
|
||||
sql: str,
|
||||
limit: int = 1000,
|
||||
force: bool = False,
|
||||
) -> str:
|
||||
if self.db_engine_spec.allow_limit_clause:
|
||||
return self.db_engine_spec.apply_limit_to_sql(sql, limit, self, force=force)
|
||||
return self.db_engine_spec.apply_top_to_sql(sql, limit)
|
||||
script = SQLScript(sql, self.db_engine_spec.engine)
|
||||
statement = script.statements[-1]
|
||||
current_limit = statement.get_limit_value() or float("inf")
|
||||
|
||||
if limit < current_limit or force:
|
||||
statement.set_limit_value(limit, self.db_engine_spec.limit_method)
|
||||
|
||||
return script.format()
|
||||
|
||||
def safe_sqlalchemy_uri(self) -> str:
|
||||
return self.sqlalchemy_uri
|
||||
|
||||
Reference in New Issue
Block a user