codeant-ai-for-open-source[bot] commented on code in PR #43759:
URL: https://github.com/apache/superset/pull/43759#discussion_r4054141942
##########
superset/connectors/sqla/partition_mapping.py:
##########
@@ -651,6 +651,73 @@ def validate_transform(
return []
+def preview_partition_mapping(
+ datasource: SqlaTable,
+ *,
+ mapped_column: str,
+ value_transform: str | None,
+ sample_value: str,
+) -> dict[str, Any]:
+ """
+ Evaluate a candidate mapping and describe the predicate it would emit.
+
+ Shares the evaluator -- and therefore the probe cache -- with the query
+ path, so preview and runtime cannot drift and a previewed transform warms
+ the chart path for free.
+
+ Validation runs first and the engine second: a half-typed transform is by
+ definition unparseable, so most of what a text input produces costs zero
+ queries.
+ """
+ partition_column = datasource.partition_column
+ if not partition_column:
+ return {"valid": False, "error": _("No partition column is set.")}
+
+ column_names = {str(column.column_name) for column in datasource.columns}
+ if mapped_column not in column_names:
+ return {
+ "valid": False,
+ "error": _("%(name)s is not a column on this dataset.",
name=mapped_column),
+ }
+
+ engine = datasource.database.backend
+ for issue in validate_partition_mapping(
+ column_names=column_names,
+ partition_column=str(partition_column),
+ partition_mapped_column=mapped_column,
+ main_dttm_col=datasource.main_dttm_col,
+ transform=value_transform,
+ engine=engine,
+ ):
+ return {"valid": False, "error": str(issue.message)}
+
+ evaluated = evaluate_transform(
+ datasource.database,
+ datasource.catalog,
+ datasource.schema,
+ cast(str, value_transform),
+ [sample_value],
+ )
+ if evaluated is None:
+ return {
+ "valid": False,
+ "error": _("The transform could not be evaluated against the
database."),
+ }
+
+ return {
+ "valid": True,
+ "emitted_predicate": (f"{partition_column} >=
{_render_literal(evaluated[0])}"),
Review Comment:
**Suggestion:** `partition_column` is interpolated without identifier
quoting, so columns containing spaces or reserved words produce invalid preview
predicates.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Api mismatch`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3040cf7986ba4aedb0a4172f61882e6c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3040cf7986ba4aedb0a4172f61882e6c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/connectors/sqla/partition_mapping.py
**Line:** 709:709
**Comment:**
*Api Mismatch: `partition_column` is interpolated without identifier
quoting, so columns containing spaces or reserved words produce invalid preview
predicates.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43759&comment_hash=68f216da6fe169c3f57b969b6d1d779f3ab9d7905cda771d5e26dffcdb3c82f6&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43759&comment_hash=68f216da6fe169c3f57b969b6d1d779f3ab9d7905cda771d5e26dffcdb3c82f6&reaction=dislike'>๐</a>
##########
superset/connectors/sqla/partition_mapping.py:
##########
@@ -651,6 +651,73 @@ def validate_transform(
return []
+def preview_partition_mapping(
+ datasource: SqlaTable,
+ *,
+ mapped_column: str,
+ value_transform: str | None,
+ sample_value: str,
+) -> dict[str, Any]:
+ """
+ Evaluate a candidate mapping and describe the predicate it would emit.
+
+ Shares the evaluator -- and therefore the probe cache -- with the query
+ path, so preview and runtime cannot drift and a previewed transform warms
+ the chart path for free.
+
+ Validation runs first and the engine second: a half-typed transform is by
+ definition unparseable, so most of what a text input produces costs zero
+ queries.
+ """
+ partition_column = datasource.partition_column
+ if not partition_column:
+ return {"valid": False, "error": _("No partition column is set.")}
+
+ column_names = {str(column.column_name) for column in datasource.columns}
+ if mapped_column not in column_names:
+ return {
+ "valid": False,
+ "error": _("%(name)s is not a column on this dataset.",
name=mapped_column),
+ }
+
+ engine = datasource.database.backend
+ for issue in validate_partition_mapping(
+ column_names=column_names,
+ partition_column=str(partition_column),
+ partition_mapped_column=mapped_column,
+ main_dttm_col=datasource.main_dttm_col,
+ transform=value_transform,
+ engine=engine,
+ ):
+ return {"valid": False, "error": str(issue.message)}
+
+ evaluated = evaluate_transform(
+ datasource.database,
+ datasource.catalog,
+ datasource.schema,
+ cast(str, value_transform),
+ [sample_value],
+ )
+ if evaluated is None:
+ return {
+ "valid": False,
+ "error": _("The transform could not be evaluated against the
database."),
+ }
+
+ return {
+ "valid": True,
+ "emitted_predicate": (f"{partition_column} >=
{_render_literal(evaluated[0])}"),
+ }
+
+
+def _render_literal(value: Any) -> str:
+ """Render a probed value the way it appears in the generated SQL."""
+ if isinstance(value, str):
+ escaped = value.replace("'", "''")
+ return f"'{escaped}'"
+ return str(value)
+
Review Comment:
**Suggestion:** Non-string results are rendered with Python `str()`, so
`NULL` becomes `None` and datetimes remain unquoted, producing invalid or
misleading SQL.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Type error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9534cc834c2c43c5b5710049ad0eef5f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9534cc834c2c43c5b5710049ad0eef5f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/connectors/sqla/partition_mapping.py
**Line:** 713:719
**Comment:**
*Type Error: Non-string results are rendered with Python `str()`, so
`NULL` becomes `None` and datetimes remain unquoted, producing invalid or
misleading SQL.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43759&comment_hash=40507ab0a32159c4ce196f8eb55f7e5a64920d6f69caca1647c8544f45ee3f43&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43759&comment_hash=40507ab0a32159c4ce196f8eb55f7e5a64920d6f69caca1647c8544f45ee3f43&reaction=dislike'>๐</a>
##########
superset/datasets/api.py:
##########
@@ -153,6 +161,31 @@
)
+def _consume_preview_rate_limit(dataset_id: int) -> bool:
+ """
+ Fixed-window per-user, per-dataset throttle on the preview endpoint.
+
+ Debouncing on the client is a courtesy, not a guard: a held keydown, or a
+ handful of owners with the editor open, becomes sustained load on a
+ production cluster. Returns False once the window's budget is spent.
+ """
+ limit = app.config.get("PARTITION_TRANSFORM_PREVIEW_RATE_LIMIT", 30)
+ if not limit:
+ return True
+
+ user_id = get_user_id() or 0
+ key = f"partition_mapping_preview:{user_id}:{dataset_id}"
+ try:
+ used = cache_manager.cache.get(key) or 0
+ if used >= limit:
+ return False
+ cache_manager.cache.set(key, used + 1, timeout=60)
Review Comment:
**Suggestion:** Resetting the 60-second timeout on every request makes this
a sliding window, so sustained traffic can remain blocked indefinitely instead
of using the documented fixed window.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Logic error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9e008c7b4e2c46838a7d6edebe3d43c1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9e008c7b4e2c46838a7d6edebe3d43c1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/datasets/api.py
**Line:** 179:182
**Comment:**
*Logic Error: Resetting the 60-second timeout on every request makes
this a sliding window, so sustained traffic can remain blocked indefinitely
instead of using the documented fixed window.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43759&comment_hash=acde1d9f9db46fe530acc7fddcda5c0c26697ef90e5b806bc6243acc25ef8d61&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43759&comment_hash=acde1d9f9db46fe530acc7fddcda5c0c26697ef90e5b806bc6243acc25ef8d61&reaction=dislike'>๐</a>
--
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]