-
Notifications
You must be signed in to change notification settings - Fork 16.7k
fix: ODPS (MaxCompute) data source table preview failed #38174
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
base: master
Are you sure you want to change the base?
Changes from all commits
3e0f47a
687fdff
8ad7747
26e61ea
b6b0e83
592cb3c
aabc26d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,192 @@ | ||||||||
| # 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 | ||||||||
|
|
||||||||
| import logging | ||||||||
| from typing import Any, Optional, TYPE_CHECKING | ||||||||
|
|
||||||||
| from sqlalchemy import select, text | ||||||||
| from sqlalchemy.engine.base import Engine | ||||||||
|
|
||||||||
| from superset.databases.schemas import ( | ||||||||
| TableMetadataColumnsResponse, | ||||||||
| TableMetadataResponse, | ||||||||
| ) | ||||||||
| from superset.databases.utils import ( | ||||||||
| get_col_type, | ||||||||
| get_foreign_keys_metadata, | ||||||||
| get_indexes_metadata, | ||||||||
| ) | ||||||||
| from superset.db_engine_specs.base import BaseEngineSpec, BasicParametersMixin | ||||||||
| from superset.sql.parse import Partition, SQLScript, Table | ||||||||
| from superset.superset_typing import ResultSetColumnType | ||||||||
|
|
||||||||
| if TYPE_CHECKING: | ||||||||
| from superset.models.core import Database | ||||||||
|
|
||||||||
| logger = logging.getLogger(__name__) | ||||||||
|
|
||||||||
|
|
||||||||
| class OdpsBaseEngineSpec(BaseEngineSpec): | ||||||||
| @classmethod | ||||||||
| def get_table_metadata( | ||||||||
| cls, | ||||||||
| database: Database, | ||||||||
| table: Table, | ||||||||
| partition: Optional[Partition] = None, | ||||||||
| ) -> TableMetadataResponse: | ||||||||
| """ | ||||||||
| Returns basic table metadata | ||||||||
| :param database: Database instance | ||||||||
| :param table: A Table instance | ||||||||
| :param partition: A Table partition info | ||||||||
| :return: Basic table metadata | ||||||||
| """ | ||||||||
| return cls.get_table_metadata(database, table, partition) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Infinite Recursion Bug
The method calls itself recursively, leading to infinite recursion. It should call the base implementation from utils instead. Code suggestionCheck the AI-generated fix before applying Code Review Run #3ebe85 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The Severity Level: Major
|
||||||||
| return cls.get_table_metadata(database, table, partition) | |
| # Delegate to the base implementation; the partition argument is currently unused. | |
| return super().get_table_metadata(database, table) |
Steps of Reproduction ✅
1. Import the ODPS engine spec base class from the PR code: `from
superset.db_engine_specs.odps import OdpsBaseEngineSpec` (defined at
`superset/db_engine_specs/odps.py:44`).
2. In any Python context (tests, shell, or application code), call
`OdpsBaseEngineSpec.get_table_metadata(database=None, table=None)`; the arguments are not
used before the recursion (`superset/db_engine_specs/odps.py:46-59`).
3. The classmethod body executes `return cls.get_table_metadata(database, table,
partition)` which re-invokes the same `OdpsBaseEngineSpec.get_table_metadata`
implementation with identical arguments (line 59).
4. This self-call repeats with no termination condition until Python's recursion limit is
exceeded, raising a `RecursionError` before any actual metadata lookup can occur.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/db_engine_specs/odps.py
**Line:** 59:59
**Comment:**
*Logic Error: The `OdpsBaseEngineSpec.get_table_metadata` classmethod calls `cls.get_table_metadata` with the same signature it defines, which for `OdpsBaseEngineSpec` itself results in infinite recursion and a `RecursionError` whenever it is invoked; it should instead delegate to the base implementation on `BaseEngineSpec` and ignore the extra `partition` argument.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: OdpsEngineSpec.select_star assumes its third argument engine always has a .dialect attribute, but in the generic code path Database.select_star passes a SQLAlchemy Dialect object instead, causing an AttributeError; the method should accept either an engine or a dialect and normalize to a dialect before calling quote_table. [logic error]
Severity Level: Critical 🚨
- ❌ /api/v1/database/<pk>/select_star fails for ODPS.
- ❌ SQLLab cannot generate SELECT * for ODPS tables.
- ⚠️ ODPS engine diverges from BaseEngineSpec.select_star contract.| full_table_name = cls.quote_table(table, engine.dialect) | |
| dialect = getattr(engine, "dialect", engine) | |
| full_table_name = cls.quote_table(table, dialect) |
Steps of Reproduction ✅
1. Configure an ODPS (MaxCompute) database and ensure its backend is `"odps"`, so
`Database.db_engine_spec` resolves to `OdpsEngineSpec` (see
`superset/models/core.py:1021-1038` and `superset/db_engine_specs/odps.py:62-65`).
2. Trigger the `/api/v1/database/<pk>/select_star/<table_name>/` endpoint defined in
`DatabaseRestApi.select_star` (`superset/databases/api.py:1181-1242`) for this ODPS
database, for example from the UI "select star" feature in SQLLab.
3. Inside `DatabaseRestApi.select_star`, Superset calls
`database.select_star(Table(table_name, schema_name, database.get_default_catalog()),
latest_partition=True)` (`superset/databases/api.py:1232-1237`).
4. `Database.select_star` (`superset/models/core.py:825-845`) computes `dialect =
self.get_dialect()` and then calls `self.db_engine_spec.select_star(self, table,
dialect=dialect, limit=..., show_cols=..., indent=..., latest_partition=..., cols=cols)`.
Because `OdpsEngineSpec.select_star` is defined with signature `(database, table, engine,
...)` and no `dialect` keyword (`superset/db_engine_specs/odps.py:129-140`), Python raises
`TypeError: select_star() got an unexpected keyword argument 'dialect'` before reaching
the `engine.dialect` access at lines 166-167.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/db_engine_specs/odps.py
**Line:** 166:166
**Comment:**
*Logic Error: `OdpsEngineSpec.select_star` assumes its third argument `engine` always has a `.dialect` attribute, but in the generic code path `Database.select_star` passes a SQLAlchemy `Dialect` object instead, causing an `AttributeError`; the method should accept either an engine or a dialect and normalize to a dialect before calling `quote_table`.
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.| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -321,6 +321,37 @@ def qualify( | |||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @dataclass(eq=True, frozen=True) | ||||||
| class Partition: | ||||||
| """ | ||||||
| Partition object, with two attribute keys: | ||||||
| ispartitioned_table and partition_comlumn, | ||||||
| used to provide partition information | ||||||
| Here is an example of an object: | ||||||
| {"ispartitioned_table":true,"partition_column":["month","day"]} | ||||||
| """ | ||||||
|
|
||||||
| is_partitioned_table: bool | ||||||
| partition_column: list[str] | None = None | ||||||
|
|
||||||
| def __str__(self) -> str: | ||||||
| """ | ||||||
| Return the partition columns of table name. | ||||||
| """ | ||||||
| partition_column_str = ( | ||||||
| ", ".join(map(str, self.partition_column)) | ||||||
| if self.partition_column | ||||||
| else "None" | ||||||
| ) | ||||||
| return ( | ||||||
| f"Partition(is_partitioned_table={self.is_partitioned_table}, " | ||||||
| f"partition_column=[{partition_column_str}])" | ||||||
| ) | ||||||
|
|
||||||
| def __eq__(self, other: Any) -> bool: | ||||||
| return str(self) == str(other) | ||||||
|
Comment on lines
+351
to
+352
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect equality implementation
The custom eq compares string representations, which is incorrect and violates hash consistency for the frozen dataclass. Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #60811b Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||
|
|
||||||
|
|
||||||
| # To avoid unnecessary parsing/formatting of queries, the statement has the concept of | ||||||
| # an "internal representation", which is the AST of the SQL statement. For most of the | ||||||
| # engines supported by Superset this is `sqlglot.exp.Expression`, but there is a special | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The ODPS partition detection is performed before checking the user's table access, meaning an unauthorized caller can still trigger ODPS API calls (and potentially learn about table existence or cause backend errors) before a permission check is enforced; move the partition lookup after the security check so that only authorized users can hit the ODPS backend for metadata. [security]
Severity Level: Major⚠️
Steps of Reproduction ✅
Prompt for AI Agent 🤖