mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
[bugfix] fix timegrain addon regression (#8165)
* Fix regression in time grain addons * Revert privatization of time_grain_functions * Fix test * Rename variable * Fix test * Fix typing error * Refactor and add tests * Add TODO
This commit is contained in:
@@ -24,12 +24,9 @@ from sqlalchemy.engine.result import RowProxy
|
||||
from sqlalchemy.sql import select
|
||||
from sqlalchemy.types import String, UnicodeText
|
||||
|
||||
from superset import app
|
||||
from superset.db_engine_specs import engines
|
||||
from superset.db_engine_specs.base import (
|
||||
_create_time_grains_tuple,
|
||||
BaseEngineSpec,
|
||||
builtin_time_grains,
|
||||
)
|
||||
from superset.db_engine_specs.base import BaseEngineSpec, builtin_time_grains
|
||||
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
||||
from superset.db_engine_specs.hive import HiveEngineSpec
|
||||
from superset.db_engine_specs.mssql import MssqlEngineSpec
|
||||
@@ -38,6 +35,7 @@ from superset.db_engine_specs.oracle import OracleEngineSpec
|
||||
from superset.db_engine_specs.pinot import PinotEngineSpec
|
||||
from superset.db_engine_specs.postgres import PostgresEngineSpec
|
||||
from superset.db_engine_specs.presto import PrestoEngineSpec
|
||||
from superset.db_engine_specs.sqlite import SqliteEngineSpec
|
||||
from superset.models.core import Database
|
||||
from superset.utils.core import get_example_database
|
||||
from .base_tests import SupersetTestCase
|
||||
@@ -315,14 +313,21 @@ class DbEngineSpecsTestCase(SupersetTestCase):
|
||||
)
|
||||
|
||||
def test_time_grain_blacklist(self):
|
||||
blacklist = ["PT1M"]
|
||||
time_grains = {"PT1S": "second", "PT1M": "minute"}
|
||||
time_grain_functions = {"PT1S": "{col}", "PT1M": "{col}"}
|
||||
time_grains = _create_time_grains_tuple(
|
||||
time_grains, time_grain_functions, blacklist
|
||||
)
|
||||
self.assertEqual(1, len(time_grains))
|
||||
self.assertEqual("PT1S", time_grains[0].duration)
|
||||
with app.app_context():
|
||||
app.config["TIME_GRAIN_BLACKLIST"] = ["PT1M"]
|
||||
time_grain_functions = SqliteEngineSpec.get_time_grain_functions()
|
||||
self.assertNotIn("PT1M", time_grain_functions)
|
||||
|
||||
def test_time_grain_addons(self):
|
||||
with app.app_context():
|
||||
app.config["TIME_GRAIN_ADDONS"] = {"PTXM": "x seconds"}
|
||||
app.config["TIME_GRAIN_ADDON_FUNCTIONS"] = {
|
||||
"sqlite": {"PTXM": "ABC({col})"}
|
||||
}
|
||||
time_grains = SqliteEngineSpec.get_time_grains()
|
||||
time_grain_addon = time_grains[-1]
|
||||
self.assertEqual("PTXM", time_grain_addon.duration)
|
||||
self.assertEqual("x seconds", time_grain_addon.label)
|
||||
|
||||
def test_engine_time_grain_validity(self):
|
||||
time_grains = set(builtin_time_grains.keys())
|
||||
@@ -330,8 +335,8 @@ class DbEngineSpecsTestCase(SupersetTestCase):
|
||||
for engine in engines.values():
|
||||
if engine is not BaseEngineSpec:
|
||||
# make sure time grain functions have been defined
|
||||
self.assertGreater(len(engine.time_grain_functions), 0)
|
||||
# make sure that all defined time grains are supported
|
||||
self.assertGreater(len(engine.get_time_grain_functions()), 0)
|
||||
# make sure all defined time grains are supported
|
||||
defined_grains = {grain.duration for grain in engine.get_time_grains()}
|
||||
intersection = time_grains.intersection(defined_grains)
|
||||
self.assertSetEqual(defined_grains, intersection, engine)
|
||||
|
||||
Reference in New Issue
Block a user