|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +""" |
| 19 | +Semantic layer DAO interfaces for superset-core. |
| 20 | +
|
| 21 | +Provides abstract DAO classes for semantic layers and views that define the |
| 22 | +interface contract. Host implementations replace these with concrete classes |
| 23 | +backed by SQLAlchemy during initialization. |
| 24 | +
|
| 25 | +Usage: |
| 26 | + from superset_core.semantic_layers.daos import ( |
| 27 | + AbstractSemanticLayerDAO, |
| 28 | + AbstractSemanticViewDAO, |
| 29 | + ) |
| 30 | +""" |
| 31 | + |
| 32 | +from __future__ import annotations |
| 33 | + |
| 34 | +from abc import abstractmethod |
| 35 | +from typing import Any, ClassVar |
| 36 | + |
| 37 | +from superset_core.common.daos import BaseDAO |
| 38 | +from superset_core.semantic_layers.models import SemanticLayerModel, SemanticViewModel |
| 39 | + |
| 40 | + |
| 41 | +class AbstractSemanticLayerDAO(BaseDAO[SemanticLayerModel]): |
| 42 | + """ |
| 43 | + Abstract DAO interface for SemanticLayer. |
| 44 | +
|
| 45 | + Host implementations will replace this class during initialization |
| 46 | + with a concrete DAO providing actual database access. |
| 47 | + """ |
| 48 | + |
| 49 | + model_cls: ClassVar[type[Any] | None] = None |
| 50 | + base_filter = None |
| 51 | + id_column_name = "uuid" |
| 52 | + uuid_column_name = "uuid" |
| 53 | + |
| 54 | + @classmethod |
| 55 | + @abstractmethod |
| 56 | + def validate_uniqueness(cls, name: str) -> bool: |
| 57 | + """ |
| 58 | + Validate that a semantic layer name is unique. |
| 59 | +
|
| 60 | + :param name: Semantic layer name to validate |
| 61 | + :return: True if the name is unique, False otherwise |
| 62 | + """ |
| 63 | + ... |
| 64 | + |
| 65 | + @classmethod |
| 66 | + @abstractmethod |
| 67 | + def validate_update_uniqueness(cls, layer_uuid: str, name: str) -> bool: |
| 68 | + """ |
| 69 | + Validate that a semantic layer name is unique for an update operation, |
| 70 | + excluding the layer being updated. |
| 71 | +
|
| 72 | + :param layer_uuid: UUID of the semantic layer being updated |
| 73 | + :param name: New name to validate |
| 74 | + :return: True if the name is unique, False otherwise |
| 75 | + """ |
| 76 | + ... |
| 77 | + |
| 78 | + @classmethod |
| 79 | + @abstractmethod |
| 80 | + def find_by_name(cls, name: str) -> SemanticLayerModel | None: |
| 81 | + """ |
| 82 | + Find a semantic layer by name. |
| 83 | +
|
| 84 | + :param name: Semantic layer name |
| 85 | + :return: SemanticLayerModel instance or None |
| 86 | + """ |
| 87 | + ... |
| 88 | + |
| 89 | + @classmethod |
| 90 | + @abstractmethod |
| 91 | + def get_semantic_views(cls, layer_uuid: str) -> list[SemanticViewModel]: |
| 92 | + """ |
| 93 | + Get all semantic views associated with a semantic layer. |
| 94 | +
|
| 95 | + :param layer_uuid: UUID of the semantic layer |
| 96 | + :return: List of SemanticViewModel instances |
| 97 | + """ |
| 98 | + ... |
| 99 | + |
| 100 | + |
| 101 | +class AbstractSemanticViewDAO(BaseDAO[SemanticViewModel]): |
| 102 | + """ |
| 103 | + Abstract DAO interface for SemanticView. |
| 104 | +
|
| 105 | + Host implementations will replace this class during initialization |
| 106 | + with a concrete DAO providing actual database access. |
| 107 | + """ |
| 108 | + |
| 109 | + model_cls: ClassVar[type[Any] | None] = None |
| 110 | + base_filter = None |
| 111 | + id_column_name = "id" |
| 112 | + uuid_column_name = "uuid" |
| 113 | + |
| 114 | + @classmethod |
| 115 | + @abstractmethod |
| 116 | + def validate_uniqueness( |
| 117 | + cls, |
| 118 | + name: str, |
| 119 | + layer_uuid: str, |
| 120 | + configuration: dict[str, Any], |
| 121 | + ) -> bool: |
| 122 | + """ |
| 123 | + Validate that a semantic view is unique within a semantic layer. |
| 124 | +
|
| 125 | + Uniqueness is determined by the combination of name, layer UUID, and |
| 126 | + configuration. |
| 127 | +
|
| 128 | + :param name: View name |
| 129 | + :param layer_uuid: UUID of the parent semantic layer |
| 130 | + :param configuration: Configuration dict to compare |
| 131 | + :return: True if unique, False otherwise |
| 132 | + """ |
| 133 | + ... |
| 134 | + |
| 135 | + @classmethod |
| 136 | + @abstractmethod |
| 137 | + def validate_update_uniqueness( |
| 138 | + cls, |
| 139 | + view_uuid: str, |
| 140 | + name: str, |
| 141 | + layer_uuid: str, |
| 142 | + configuration: dict[str, Any], |
| 143 | + ) -> bool: |
| 144 | + """ |
| 145 | + Validate that a semantic view is unique within a semantic layer for an |
| 146 | + update operation, excluding the view being updated. |
| 147 | +
|
| 148 | + :param view_uuid: UUID of the view being updated |
| 149 | + :param name: New name to validate |
| 150 | + :param layer_uuid: UUID of the parent semantic layer |
| 151 | + :param configuration: Configuration dict to compare |
| 152 | + :return: True if unique, False otherwise |
| 153 | + """ |
| 154 | + ... |
| 155 | + |
| 156 | + @classmethod |
| 157 | + @abstractmethod |
| 158 | + def find_by_name(cls, name: str, layer_uuid: str) -> SemanticViewModel | None: |
| 159 | + """ |
| 160 | + Find a semantic view by name within a semantic layer. |
| 161 | +
|
| 162 | + :param name: View name |
| 163 | + :param layer_uuid: UUID of the parent semantic layer |
| 164 | + :return: SemanticViewModel instance or None |
| 165 | + """ |
| 166 | + ... |
| 167 | + |
| 168 | + |
| 169 | +__all__ = ["AbstractSemanticLayerDAO", "AbstractSemanticViewDAO"] |
0 commit comments