feat: push predicates into virtual datasets (#31486)

This commit is contained in:
Beto Dealmeida
2025-01-08 22:11:28 -05:00
committed by GitHub
parent f29eafd044
commit e4b3ecd372
10 changed files with 191 additions and 5 deletions

View File

@@ -74,6 +74,7 @@ from superset.extensions import (
)
from superset.models.helpers import AuditMixinNullable, ImportExportMixin, UUIDMixin
from superset.result_set import SupersetResultSet
from superset.sql.parse import SQLScript
from superset.sql_parse import Table
from superset.superset_typing import (
DbapiDescription,
@@ -740,6 +741,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
qry: Select,
catalog: str | None = None,
schema: str | None = None,
is_virtual: bool = False,
) -> str:
with self.get_sqla_engine(catalog=catalog, schema=schema) as engine:
sql = str(qry.compile(engine, compile_kwargs={"literal_binds": True}))
@@ -748,6 +750,12 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
if engine.dialect.identifier_preparer._double_percents: # noqa
sql = sql.replace("%%", "%")
# for nwo we only optimize queries on virtual datasources, since the only
# optimization available is predicate pushdown
if is_feature_enabled("OPTIMIZE_SQL") and is_virtual:
script = SQLScript(sql, self.db_engine_spec.engine).optimize()
sql = script.format()
return sql
def select_star( # pylint: disable=too-many-arguments