john-bodley commented on a change in pull request #9854:
URL:
https://github.com/apache/incubator-superset/pull/9854#discussion_r428236021
##########
File path: superset/connectors/sqla/models.py
##########
@@ -167,15 +167,26 @@ def is_temporal(self) -> bool:
self.type, utils.DbColumnType.TEMPORAL
)
- def get_sqla_col(self, label: Optional[str] = None) -> Column:
- label = label or self.column_name
+ def get_sqla_col(
Review comment:
I've played with this in the past by forcing
`render_label_as_label=None` when calling the `super()`. For your scenario it
seems like it may need to differ based on the context, i.e., within the `WHERE`
clause.
For example we needed to ensure that the `ORDER BY` didn't contain the
alias/label, so we did,
```python
class MyCompilier(DruidCompiler):
def visit_label( # pylint: disable=too-many-arguments
self,
label: _CompileLabel,
add_to_result_map: Optional[Callable] = None,
within_label_clause: Optional[bool] = False,
within_columns_clause: Optional[bool] = False,
render_label_as_label: Optional[_CompileLabel] = None,
**kwargs: Any,
) -> str:
"""
Only render labels (aliases) within the column clause.
Note this overrides the default behavior of rendering labels within
the ORDER BY
clause since the ORDER BY clause does not support aliases.
"""
return super().visit_label(
label,
add_to_result_map=add_to_result_map,
within_label_clause=within_label_clause,
within_columns_clause=within_columns_clause,
render_label_as_label=None,
**kwargs,
)
```
which was tested (using `pytest`) via:
```python
from sqlalchemy.engine import Engine
from sqlalchemy.sql import literal_column, select
def test_identifier_preparer(engine: Engine) -> None:
col = literal_column("SUM(x)").label("total")
stmt = select([col])
assert str(stmt) == "SELECT SUM(x) AS total"
assert str(stmt.compile(engine)) == 'SELECT SUM(x) AS "total"'
def test_visit_label(engine: Engine) -> None:
col = literal_column("SUM(x)").label("total")
stmt = select([col]).order_by(col)
assert str(stmt).endswith("ORDER BY total")
assert str(stmt.compile(engine)).endswith("ORDER BY SUM(x)")
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]