betodealmeida commented on code in PR #37311:
URL: https://github.com/apache/superset/pull/37311#discussion_r2714618315


##########
superset/commands/importers/v1/examples.py:
##########
@@ -41,9 +43,59 @@
 from superset.dashboards.schemas import ImportV1DashboardSchema
 from superset.databases.schemas import ImportV1DatabaseSchema
 from superset.datasets.schemas import ImportV1DatasetSchema
+from superset.exceptions import QueryClauseValidationException
+from superset.models.core import Database
+from superset.sql.parse import transpile_to_dialect
 from superset.utils.core import get_example_default_schema
 from superset.utils.decorators import transaction
 
+logger = logging.getLogger(__name__)
+
+
+def transpile_virtual_dataset_sql(config: dict[str, Any], database_id: int) -> 
None:
+    """
+    Transpile virtual dataset SQL to the target database dialect.
+
+    This ensures that virtual datasets exported from one database type
+    (e.g., PostgreSQL) can be loaded into a different database type
+    (e.g., MySQL, DuckDB, SQLite).
+
+    Args:
+        config: Dataset configuration dict (modified in place)
+        database_id: ID of the target database
+    """
+    sql = config.get("sql")
+    if not sql:
+        return
+
+    database = db.session.query(Database).get(database_id)
+    if not database:
+        logger.warning("Database %s not found, skipping SQL transpilation", 
database_id)
+        return
+
+    target_engine = database.db_engine_spec.engine
+    source_engine = config.get("source_db_engine")

Review Comment:
   Let's add an early return here:
   
   ```suggestion
       target_engine = database.db_engine_spec.engine
       source_engine = config.get("source_db_engine")
       if target_engine == source_engine:
           logger.info("Source and target dialects are identical, skipping 
transpilation")
           return
   ```



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