-
Notifications
You must be signed in to change notification settings - Fork 18.3k
feat: semantic layer extension #37815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
4255fbc
feat: semantic layer extension
betodealmeida 6babb2a
chore: remove AdhocFilter
betodealmeida 75f9fb7
Address TODOs
betodealmeida fb72646
Address comments
betodealmeida b54b0fa
feat: add @semantic_layer decorator for extension discovery
betodealmeida d705ddf
docs: add semantic layers to contribution types
betodealmeida 6bd91c8
Simplify
betodealmeida c3ccbb0
Fix tests
betodealmeida b4f32bc
Improve types
betodealmeida c163c0c
Fix lint/tests
betodealmeida ae18e37
feat: models and DAOs
betodealmeida 72397b0
Improvements
betodealmeida 9040d2c
Address comments
betodealmeida a27f644
Address more comments
betodealmeida db6d20c
feat: Explore integration
betodealmeida 8517555
Fix Datasource type
betodealmeida 3730bc0
feat: API for semantic views
betodealmeida ef24357
Check uniqueness
betodealmeida 24feed7
Fix DAO
betodealmeida 7c1c0f7
feat: UI for semantic views
betodealmeida f7c6e8b
Fix imports
betodealmeida bc9abd3
Address comments
betodealmeida 1a1adcf
Move logic to commands
betodealmeida 8dc3ad6
Address comments
betodealmeida 0672248
feat: API for semantic layers
betodealmeida 2727d83
Address comments
betodealmeida 1bb51d1
Update permissions
betodealmeida 4dc5b0a
feat: UI for semantic layers
betodealmeida 8794101
Fix rebase
betodealmeida 41a938d
Address semantic layer review nits
betodealmeida 007bf4e
feat: CRUD for adding/deleting semantic views
betodealmeida 59dab47
Fix imports
betodealmeida b60a354
Fix lint/tests
betodealmeida 69126bd
Improve design
betodealmeida f1b3d06
Address comments
betodealmeida 18fe528
Bulk delete
betodealmeida cb37041
Small fixes
betodealmeida 05ec534
chore: rename database/database when using semantic layers
betodealmeida 64a8fbd
More fixes
betodealmeida ca3a230
Revert some aggressive renames
betodealmeida 5d6ce82
Fix lint
betodealmeida 0d09eca
Small fixes
betodealmeida 6a3c227
Fix data connection name
betodealmeida 18ec6e5
Fix header name
betodealmeida 0e0c443
Working on filters
betodealmeida e779abe
Working on filters
betodealmeida 7e169bc
Fix filters
betodealmeida 3808551
Fix lint
betodealmeida db97eb5
Small fixes
betodealmeida c2e2746
Fix edit dataset
betodealmeida e200f7c
feat: dynamic columns
betodealmeida 1cec3da
Explorable protocol
betodealmeida d0afbe1
Dynamic columns/metrics
betodealmeida fa8928f
Disable adhoc SQL
betodealmeida c06d03d
Small fix
betodealmeida 72fd9eb
Disable adhoc
betodealmeida bc98daa
Sort metrics/columns
betodealmeida 8b5e9aa
Small fixes
betodealmeida ff2a9e0
Address comments from Max
betodealmeida ac02b32
Fix package
betodealmeida 27aeaf8
Fix tests and lint
betodealmeida 6602cb4
Increase coverage to 100% and fix lint
betodealmeida c484abf
Fix test
betodealmeida 51954cb
Fix more tests
betodealmeida 7fd3004
More tests
betodealmeida 18091b7
Small fix
betodealmeida 9ef6261
feat(semantic layers): edit modal for semantic views (#39628)
betodealmeida abfa30a
Sl permissions (#39640)
betodealmeida a4aa176
Fix test
betodealmeida 16325ad
More tests
betodealmeida baf17a0
Fix react-checkbox-tree
betodealmeida 7c44fa5
Fix Data connection column for semantic views
betodealmeida 18dcf6a
Address comments
betodealmeida 2b123ff
Fix ts errors
betodealmeida 1f7a4e3
Address bot
betodealmeida 6770c57
More comments addressed
betodealmeida 39933ea
Fix test
betodealmeida 66f7f62
Increase coverage
betodealmeida 6d75bff
Fix CI
betodealmeida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| def build_configuration_schema( | ||
| config_class: type[BaseModel], | ||
| configuration: BaseModel | None = None, | ||
| ) -> dict[str, Any]: | ||
| """ | ||
| Build a JSON schema from a Pydantic configuration class. | ||
|
|
||
| Handles generic boilerplate that any semantic layer with dynamic fields needs: | ||
|
|
||
| - Reorders properties to match model field order (Pydantic sorts alphabetically) | ||
| - When ``configuration`` is None, sets ``enum: []`` on all ``x-dynamic`` properties | ||
| so the frontend renders them as empty dropdowns | ||
|
|
||
| Semantic layer implementations call this instead of | ||
| ``model_json_schema()`` directly, | ||
| then only need to add their own dynamic population logic. | ||
| """ | ||
| schema = config_class.model_json_schema() | ||
|
|
||
| # Pydantic sorts properties alphabetically; restore model field order | ||
| field_order = [ | ||
| field.alias or name for name, field in config_class.model_fields.items() | ||
| ] | ||
| schema["properties"] = { | ||
| key: schema["properties"][key] | ||
| for key in field_order | ||
| if key in schema["properties"] | ||
| } | ||
|
|
||
| if configuration is None: | ||
| for prop_schema in schema["properties"].values(): | ||
| if prop_schema.get("x-dynamic"): | ||
| prop_schema["enum"] = [] | ||
|
|
||
| return schema | ||
|
|
||
|
|
||
| def check_dependencies( | ||
| prop_schema: dict[str, Any], | ||
| configuration: BaseModel, | ||
| ) -> bool: | ||
| """ | ||
| Check whether a dynamic property's dependencies are satisfied. | ||
|
|
||
| Reads the ``x-dependsOn`` list from the property schema and returns ``True`` | ||
| when every referenced attribute on ``configuration`` is truthy. | ||
| """ | ||
| dependencies = prop_schema.get("x-dependsOn", []) | ||
| return all(getattr(configuration, dep, None) for dep in dependencies) |
169 changes: 169 additions & 0 deletions
169
superset-core/src/superset_core/semantic_layers/daos.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| """ | ||
| Semantic layer DAO interfaces for superset-core. | ||
|
|
||
| Provides abstract DAO classes for semantic layers and views that define the | ||
| interface contract. Host implementations replace these with concrete classes | ||
| backed by SQLAlchemy during initialization. | ||
|
|
||
| Usage: | ||
| from superset_core.semantic_layers.daos import ( | ||
| AbstractSemanticLayerDAO, | ||
| AbstractSemanticViewDAO, | ||
| ) | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import abstractmethod | ||
| from typing import Any, ClassVar | ||
|
|
||
| from superset_core.common.daos import BaseDAO | ||
| from superset_core.semantic_layers.models import SemanticLayerModel, SemanticViewModel | ||
|
|
||
|
|
||
| class AbstractSemanticLayerDAO(BaseDAO[SemanticLayerModel]): | ||
| """ | ||
| Abstract DAO interface for SemanticLayer. | ||
|
|
||
| Host implementations will replace this class during initialization | ||
| with a concrete DAO providing actual database access. | ||
| """ | ||
|
|
||
| model_cls: ClassVar[type[Any] | None] = None | ||
| base_filter = None | ||
| id_column_name = "uuid" | ||
| uuid_column_name = "uuid" | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def validate_uniqueness(cls, name: str) -> bool: | ||
| """ | ||
| Validate that a semantic layer name is unique. | ||
|
|
||
| :param name: Semantic layer name to validate | ||
| :return: True if the name is unique, False otherwise | ||
| """ | ||
| ... | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def validate_update_uniqueness(cls, layer_uuid: str, name: str) -> bool: | ||
| """ | ||
| Validate that a semantic layer name is unique for an update operation, | ||
| excluding the layer being updated. | ||
|
|
||
| :param layer_uuid: UUID of the semantic layer being updated | ||
| :param name: New name to validate | ||
| :return: True if the name is unique, False otherwise | ||
| """ | ||
| ... | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def find_by_name(cls, name: str) -> SemanticLayerModel | None: | ||
| """ | ||
| Find a semantic layer by name. | ||
|
|
||
| :param name: Semantic layer name | ||
| :return: SemanticLayerModel instance or None | ||
| """ | ||
| ... | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def get_semantic_views(cls, layer_uuid: str) -> list[SemanticViewModel]: | ||
| """ | ||
| Get all semantic views associated with a semantic layer. | ||
|
|
||
| :param layer_uuid: UUID of the semantic layer | ||
| :return: List of SemanticViewModel instances | ||
| """ | ||
| ... | ||
|
|
||
|
|
||
| class AbstractSemanticViewDAO(BaseDAO[SemanticViewModel]): | ||
| """ | ||
| Abstract DAO interface for SemanticView. | ||
|
|
||
| Host implementations will replace this class during initialization | ||
| with a concrete DAO providing actual database access. | ||
| """ | ||
|
|
||
| model_cls: ClassVar[type[Any] | None] = None | ||
| base_filter = None | ||
| id_column_name = "id" | ||
| uuid_column_name = "uuid" | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def validate_uniqueness( | ||
| cls, | ||
| name: str, | ||
| layer_uuid: str, | ||
| configuration: dict[str, Any], | ||
| ) -> bool: | ||
| """ | ||
| Validate that a semantic view is unique within a semantic layer. | ||
|
|
||
| Uniqueness is determined by the combination of name, layer UUID, and | ||
| configuration. | ||
|
|
||
| :param name: View name | ||
| :param layer_uuid: UUID of the parent semantic layer | ||
| :param configuration: Configuration dict to compare | ||
| :return: True if unique, False otherwise | ||
| """ | ||
| ... | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def validate_update_uniqueness( | ||
| cls, | ||
| view_uuid: str, | ||
| name: str, | ||
| layer_uuid: str, | ||
| configuration: dict[str, Any], | ||
| ) -> bool: | ||
| """ | ||
| Validate that a semantic view is unique within a semantic layer for an | ||
| update operation, excluding the view being updated. | ||
|
|
||
| :param view_uuid: UUID of the view being updated | ||
| :param name: New name to validate | ||
| :param layer_uuid: UUID of the parent semantic layer | ||
| :param configuration: Configuration dict to compare | ||
| :return: True if unique, False otherwise | ||
| """ | ||
| ... | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def find_by_name(cls, name: str, layer_uuid: str) -> SemanticViewModel | None: | ||
| """ | ||
| Find a semantic view by name within a semantic layer. | ||
|
|
||
| :param name: View name | ||
| :param layer_uuid: UUID of the parent semantic layer | ||
| :return: SemanticViewModel instance or None | ||
| """ | ||
| ... | ||
|
|
||
|
|
||
| __all__ = ["AbstractSemanticLayerDAO", "AbstractSemanticViewDAO"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.