mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
feat: method for dynamic allows_alias_in_select (#25882)
This commit is contained in:
@@ -14,14 +14,25 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
from packaging.version import Version
|
||||
from sqlalchemy import types
|
||||
|
||||
from superset.constants import TimeGrain
|
||||
from superset.db_engine_specs.base import BaseEngineSpec
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from superset.models.core import Database
|
||||
|
||||
|
||||
# See https://github.com/apache/superset/pull/25657
|
||||
FIXED_ALIAS_IN_SELECT_VERSION = Version("24.1.0")
|
||||
|
||||
|
||||
class DremioEngineSpec(BaseEngineSpec):
|
||||
engine = "dremio"
|
||||
@@ -43,10 +54,25 @@ class DremioEngineSpec(BaseEngineSpec):
|
||||
def epoch_to_dttm(cls) -> str:
|
||||
return "TO_DATE({col})"
|
||||
|
||||
@classmethod
|
||||
def get_allows_alias_in_select(cls, database: Database) -> bool:
|
||||
"""
|
||||
Dremio supports aliases in SELECT statements since version 24.1.0.
|
||||
|
||||
If no version is specified in the DB extra, we assume the Dremio version is post
|
||||
24.1.0. This way, as we move forward people don't have to specify a version when
|
||||
setting up their databases.
|
||||
"""
|
||||
version = database.get_extra().get("version")
|
||||
if version and Version(version) < FIXED_ALIAS_IN_SELECT_VERSION:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def convert_dttm(
|
||||
cls, target_type: str, dttm: datetime, db_extra: Optional[dict[str, Any]] = None
|
||||
) -> Optional[str]:
|
||||
cls, target_type: str, dttm: datetime, db_extra: dict[str, Any] | None = None
|
||||
) -> str | None:
|
||||
sqla_type = cls.get_sqla_column_type(target_type)
|
||||
|
||||
if isinstance(sqla_type, types.Date):
|
||||
|
||||
Reference in New Issue
Block a user