You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2025/03/06 20:39:11 UTC
(superset) branch export-folders updated (2b752c862d -> b4db95fc29)
This is an automated email from the ASF dual-hosted git repository.
beto pushed a change to branch export-folders
in repository https://gitbox.apache.org/repos/asf/superset.git
discard 2b752c862d feat: export/import for dataset folders
new b4db95fc29 feat: export/import for dataset folders
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (2b752c862d)
\
N -- N -- N refs/heads/export-folders (b4db95fc29)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../datasets/commands/importers/v1/import_test.py | 78 ++++++++++++++++++++++
1 file changed, 78 insertions(+)
(superset) 01/01: feat: export/import for dataset folders
Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch export-folders
in repository https://gitbox.apache.org/repos/asf/superset.git
commit b4db95fc293ee7bd841f9b6facf0a0c50442a907
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Mar 6 13:10:15 2025 -0500
feat: export/import for dataset folders
---
superset/connectors/sqla/models.py | 1 +
tests/unit_tests/datasets/commands/export_test.py | 67 +++++++++
.../datasets/commands/importers/v1/import_test.py | 166 +++++++++++++++++++++
3 files changed, 234 insertions(+)
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index bbcf86d634..ecfbe6089f 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -1219,6 +1219,7 @@ class SqlaTable(
"extra",
"normalize_columns",
"always_filter_main_dttm",
+ "folders",
]
update_from_object_fields = [f for f in export_fields if f != "database_id"]
export_parent = "database"
diff --git a/tests/unit_tests/datasets/commands/export_test.py b/tests/unit_tests/datasets/commands/export_test.py
index f42bbfc9cb..04bc989ba5 100644
--- a/tests/unit_tests/datasets/commands/export_test.py
+++ b/tests/unit_tests/datasets/commands/export_test.py
@@ -16,6 +16,8 @@
# under the License.
# pylint: disable=import-outside-toplevel, unused-argument, unused-import
+from uuid import UUID
+
from sqlalchemy.orm.session import Session
from superset import db
@@ -47,6 +49,7 @@ def test_export(session: Session) -> None:
type="INTEGER",
expression="revenue-expenses",
extra=json.dumps({"certified_by": "User"}),
+ uuid=UUID("00000000-0000-0000-0000-000000000005"),
),
]
metrics = [
@@ -54,6 +57,7 @@ def test_export(session: Session) -> None:
metric_name="cnt",
expression="COUNT(*)",
extra=json.dumps({"warning_markdown": None}),
+ uuid=UUID("00000000-0000-0000-0000-000000000004"),
),
]
@@ -61,6 +65,46 @@ def test_export(session: Session) -> None:
table_name="my_table",
columns=columns,
metrics=metrics,
+ folders=[
+ {
+ "uuid": "00000000-0000-0000-0000-000000000000",
+ "type": "folder",
+ "name": "Engineering",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000001",
+ "type": "folder",
+ "name": "Core",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000004",
+ "type": "metric",
+ "name": "cnt",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "uuid": "00000000-0000-0000-0000-000000000002",
+ "type": "folder",
+ "name": "Sales",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000003",
+ "type": "folder",
+ "name": "Core",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000005",
+ "type": "column",
+ "name": "profit",
+ },
+ ],
+ },
+ ],
+ },
+ ],
main_dttm_col="ds",
database=database,
offset=-8,
@@ -126,6 +170,29 @@ extra:
warning_markdown: '*WARNING*'
normalize_columns: false
always_filter_main_dttm: false
+folders:
+- uuid: 00000000-0000-0000-0000-000000000000
+ type: folder
+ name: Engineering
+ children:
+ - uuid: 00000000-0000-0000-0000-000000000001
+ type: folder
+ name: Core
+ children:
+ - uuid: 00000000-0000-0000-0000-000000000004
+ type: metric
+ name: cnt
+- uuid: 00000000-0000-0000-0000-000000000002
+ type: folder
+ name: Sales
+ children:
+ - uuid: 00000000-0000-0000-0000-000000000003
+ type: folder
+ name: Core
+ children:
+ - uuid: 00000000-0000-0000-0000-000000000005
+ type: column
+ name: profit
uuid: {payload["uuid"]}
metrics:
- metric_name: cnt
diff --git a/tests/unit_tests/datasets/commands/importers/v1/import_test.py b/tests/unit_tests/datasets/commands/importers/v1/import_test.py
index 2a2038046d..05d4b434c6 100644
--- a/tests/unit_tests/datasets/commands/importers/v1/import_test.py
+++ b/tests/unit_tests/datasets/commands/importers/v1/import_test.py
@@ -86,6 +86,7 @@ def test_import_dataset(mocker: MockerFixture, session: Session) -> None:
"d3format": None,
"extra": {"warning_markdown": None},
"warning_text": None,
+ "uuid": "00000000-0000-0000-0000-000000000001",
}
],
"columns": [
@@ -103,8 +104,49 @@ def test_import_dataset(mocker: MockerFixture, session: Session) -> None:
"extra": {
"certified_by": "User",
},
+ "uuid": "00000000-0000-0000-0000-000000000002",
}
],
+ "folders": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000000",
+ "type": "folder",
+ "name": "Engineering",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000001",
+ "type": "folder",
+ "name": "Core",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000004",
+ "type": "metric",
+ "name": "cnt",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "uuid": "00000000-0000-0000-0000-000000000002",
+ "type": "folder",
+ "name": "Sales",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000003",
+ "type": "folder",
+ "name": "Core",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000005",
+ "type": "column",
+ "name": "profit",
+ },
+ ],
+ },
+ ],
+ },
+ ],
"database_uuid": database.uuid,
"database_id": database.id,
}
@@ -136,6 +178,9 @@ def test_import_dataset(mocker: MockerFixture, session: Session) -> None:
assert sqla_table.metrics[0].d3format is None
assert sqla_table.metrics[0].extra == '{"warning_markdown": null}'
assert sqla_table.metrics[0].warning_text is None
+ assert sqla_table.metrics[0].uuid == uuid.UUID(
+ "00000000-0000-0000-0000-000000000001"
+ )
assert len(sqla_table.columns) == 1
assert sqla_table.columns[0].column_name == "profit"
assert sqla_table.columns[0].verbose_name is None
@@ -148,10 +193,131 @@ def test_import_dataset(mocker: MockerFixture, session: Session) -> None:
assert sqla_table.columns[0].description is None
assert sqla_table.columns[0].python_date_format is None
assert sqla_table.columns[0].extra == '{"certified_by": "User"}'
+ assert sqla_table.columns[0].uuid == uuid.UUID(
+ "00000000-0000-0000-0000-000000000002"
+ )
+ assert sqla_table.folders == [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000000",
+ "type": "folder",
+ "name": "Engineering",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000001",
+ "type": "folder",
+ "name": "Core",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000004",
+ "type": "metric",
+ "name": "cnt",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "uuid": "00000000-0000-0000-0000-000000000002",
+ "type": "folder",
+ "name": "Sales",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000003",
+ "type": "folder",
+ "name": "Core",
+ "children": [
+ {
+ "uuid": "00000000-0000-0000-0000-000000000005",
+ "type": "column",
+ "name": "profit",
+ },
+ ],
+ },
+ ],
+ },
+ ]
assert sqla_table.database.uuid == database.uuid
assert sqla_table.database.id == database.id
+def test_import_dataset_no_folder(mocker: MockerFixture, session: Session) -> None:
+ """
+ Test importing a dataset that was exported without folders.
+ """
+ from superset import security_manager
+ from superset.commands.dataset.importers.v1.utils import import_dataset
+ from superset.connectors.sqla.models import SqlaTable
+ from superset.models.core import Database
+
+ mocker.patch.object(security_manager, "can_access", return_value=True)
+
+ engine = db.session.get_bind()
+ SqlaTable.metadata.create_all(engine) # pylint: disable=no-member
+
+ database = Database(database_name="my_database", sqlalchemy_uri="sqlite://")
+ db.session.add(database)
+ db.session.flush()
+
+ dataset_uuid = uuid.uuid4()
+ config = {
+ "table_name": "my_table",
+ "main_dttm_col": "ds",
+ "description": "This is the description",
+ "default_endpoint": None,
+ "offset": -8,
+ "cache_timeout": 3600,
+ "catalog": "public",
+ "schema": "my_schema",
+ "sql": None,
+ "params": {
+ "remote_id": 64,
+ "database_name": "examples",
+ "import_time": 1606677834,
+ },
+ "template_params": {
+ "answer": "42",
+ },
+ "filter_select_enabled": True,
+ "fetch_values_predicate": "foo IN (1, 2)",
+ "extra": {"warning_markdown": "*WARNING*"},
+ "uuid": dataset_uuid,
+ "metrics": [
+ {
+ "metric_name": "cnt",
+ "verbose_name": None,
+ "metric_type": None,
+ "expression": "COUNT(*)",
+ "description": None,
+ "d3format": None,
+ "extra": {"warning_markdown": None},
+ "warning_text": None,
+ }
+ ],
+ "columns": [
+ {
+ "column_name": "profit",
+ "verbose_name": None,
+ "is_dttm": None,
+ "is_active": None,
+ "type": "INTEGER",
+ "groupby": None,
+ "filterable": None,
+ "expression": "revenue-expenses",
+ "description": None,
+ "python_date_format": None,
+ "extra": {
+ "certified_by": "User",
+ },
+ }
+ ],
+ "database_uuid": database.uuid,
+ "database_id": database.id,
+ }
+
+ sqla_table = import_dataset(config)
+ assert sqla_table.folders is None
+
+
def test_import_dataset_duplicate_column(
mocker: MockerFixture, session: Session
) -> None: