korbit-ai[bot] commented on code in PR #32520:
URL: https://github.com/apache/superset/pull/32520#discussion_r1983715531
##########
superset/datasets/schemas.py:
##########
@@ -88,6 +88,18 @@ class DatasetMetricsPutSchema(Schema):
uuid = fields.UUID(allow_none=True)
+class FolderSchema(Schema):
+ uuid = fields.UUID()
+ type = fields.String(
+ required=False,
+ validate=OneOf(["metric", "column", "folder"]),
+ )
+ name = fields.String(required=True, validate=Length(1, 250))
+ description = fields.String(allow_none=True, validate=Length(0, 1000))
+ # folder can contain metrics, columns, and subfolders:
+ children = fields.List(fields.Nested(lambda: FolderSchema()),
allow_none=True)
Review Comment:
### Unbounded Recursive Nesting <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The recursive FolderSchema definition allows unlimited nesting depth, which
could lead to stack overflow or excessive memory usage.
###### Why this matters
Without a maximum depth limit, deeply nested folder structures could cause
performance issues or crashes.
###### Suggested change ∙ *Feature Preview*
Add a depth parameter to limit nesting:
```python
class FolderSchema(Schema):
def __init__(self, max_depth=5, current_depth=0, *args, **kwargs):
super().__init__(*args, **kwargs)
self.max_depth = max_depth
self.current_depth = current_depth
children = fields.List(
fields.Nested(
lambda: FolderSchema(max_depth=self.max_depth,
current_depth=self.current_depth + 1)
if self.current_depth < self.max_depth
else None
),
allow_none=True
)
```
</details>
<sub>
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9e9a275f-9f2f-48ba-bb56-7e5a54a42ee4?suggestedFixEnabled=true)
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:e3ccfe92-95d8-4475-8874-69cd84b53e47 -->
##########
superset/migrations/versions/2025-03-03_20-52_94e7a3499973_add_folder_table.py:
##########
@@ -0,0 +1,42 @@
+# 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.
+"""Add folder table
+
+Revision ID: 94e7a3499973
+Revises: 74ad1125881c
+Create Date: 2025-03-03 20:52:24.585143
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.types import JSON
+
+# revision identifiers, used by Alembic.
+revision = "94e7a3499973"
+down_revision = "74ad1125881c"
+
+
+def upgrade():
+ op.add_column(
+ "tables",
+ sa.Column("folders", JSON, nullable=True),
+ )
Review Comment:
### Non-normalized JSON storage design <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The column name 'folders' suggests storing multiple folders in a JSON field,
which violates database normalization principles and makes querying/indexing
inefficient.
###### Why this matters
Storing multiple values in a JSON column creates difficulties in data
integrity, search performance, and relationship management. It's harder to
enforce referential integrity and perform efficient queries on nested JSON data.
###### Suggested change ∙ *Feature Preview*
Create a separate `folders` table with proper foreign key relationships to
the `tables` table:
```python
def upgrade():
op.create_table(
'folders',
sa.Column('id', sa.Integer(), primary_key=True),
sa.Column('table_id', sa.Integer(), sa.ForeignKey('tables.id')),
sa.Column('name', sa.String(length=250))
)
```
</details>
<sub>
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e9e9d9ed-30ac-4f99-ba3b-75e42c3ea462?suggestedFixEnabled=true)
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:78d07164-54e2-412c-b8e0-339e1cfe2220 -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]