tjsdud594 opened a new issue, #31779:
URL: https://github.com/apache/superset/issues/31779

   ### Bug description
   
   Link: [Issue #26449](https://github.com/apache/superset/issues/26449)
   
   I encountered a very similar error to the case described in the issue above. 
   The only difference is that I am working with a Delta Lake table instead of 
an Iceberg table. 
   I would like to share this bug and propose a solution and potential 
improvement.
   
   ### How to reproduce the bug
   1. Create a table with partitions in the Trino catalog.
   2. Open SQL Lab
   3. Select the catalog, schema, and table from the drop downs.
   4. You will encounter the error: "trino error: line 5:7: Column 'partition' 
cannot be resolved"
   
   ### Superset Environment
   - Superset version: 4.1.1
   - Python version: 3.10.15
   - Trino version: 467
   
   ### Solution
   Referring to the previous case, I modified the trino.py module as follows:
   Module Location: `superset/db_engine_specs/trino.py : line 494~end`
   
   **_Before_**
   ```
   @classmethod
   def get_indexes(
       cls,
       database: Database,
       inspector: Inspector,
       table: Table,
   ) -> list[dict[str, Any]]:
       """
       Get the indexes associated with the specified schema/table.
   
       Trino dialect raises NoSuchTableError in get_indexes if table is empty.
   
       :param database: The database to inspect
       :param inspector: The SQLAlchemy inspector
       :param table: The table instance to inspect
       :returns: The indexes
       """
       try:
           return super().get_indexes(database, inspector, table)
       except NoSuchTableError:
           return []
   ```
   
   **_After_**
   
   ```
   @classmethod
   def get_indexes(
       cls,
       database: Database,
       inspector: Inspector,
       table: Table,
   ) -> list[dict[str, Any]]:
       """
       Get the indexes associated with the specified schema/table.
   
       Trino dialect raises NoSuchTableError in get_indexes if table is empty.
   
       :param database: The database to inspect
       :param inspector: The SQLAlchemy inspector
       :param table: The table instance to inspect
       :returns: The indexes
       """
       try:
           indexes = super().get_indexes(database, inspector, table_name, 
schema)
           # Handle delta tables. Even for non-partitioned tables, it returns a 
value
           delta_cols_ignore = {"partition", "file_count", "total_size", "data"}
           if len(indexes) == 1 and indexes[0].get("name") == "partition" and 
delta_cols_ignore.issubset(set(indexes[0].get("column_names", []))):
               return []
           return indexes
       except NoSuchTableError:
           return []
   ```
   
   This method effectively resolved the issue, allowing preview functionality 
for partitioned Delta Lake tables.
   
   ### Proposal for Improvement
   
   Since the current solution only works for Delta Lake tables, I suggest 
modifying the code to accommodate both Iceberg and Delta Lake tables.
   
   **_Final Suggested Code_**
   
   ```
   @classmethod
   def get_indexes(
       cls,
       database: Database,
       inspector: Inspector,
       table: Table,
   ) -> list[dict[str, Any]]:
       """
       Get the indexes associated with the specified schema/table.
   
       Trino dialect raises NoSuchTableError in get_indexes if table is empty.
   
       :param database: The database to inspect
       :param inspector: The SQLAlchemy inspector
       :param table: The table instance to inspect
       :returns: The indexes
       """
       try:
           indexes = super().get_indexes(database, inspector, table_name, 
schema)
           # Handle iceberg / delta tables. Even for non-partitioned tables, it 
returns a value
           cols_ignore = {"file_count", "total_size", "data"}
           if len(indexes) == 1 and indexes[0].get("name") == "partition" and 
cols_ignore.issubset(set(indexes[0].get("column_names", []))):
               return []
           return indexes
       except NoSuchTableError:
           return []
   ```
   This modification ensures compatibility with both Iceberg and Delta Lake 
tables, improving the robustness of the solution.
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   4.1.1
   
   ### Python version
   
   3.10
   
   ### Node version
   
   16
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [X] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [X] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [X] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


-- 
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]

Reply via email to