betodealmeida commented on PR #34895:
URL: https://github.com/apache/superset/pull/34895#issuecomment-3239443846
That's weird, it works with this script:
```python
#!/usr/bin/env python
"""Test how Databricks monkeypatch affects other dialects"""
from typing import Any, Callable
from databricks.sql.utils import ParamEscaper
from pyathena.sqlalchemy_athena import AthenaPandasDialect
from sqlalchemy import literal_column, types
from sqlalchemy_databricks._dialect import DatabricksDialect
class DatabricksStringType(types.TypeDecorator):
impl = types.String
cache_ok = True
pe = ParamEscaper()
def process_literal_param(self, value: Any, dialect: Any) -> str:
return self.pe.escape_string(value)
def literal_processor(self, dialect: Any) -> Callable[[Any], str]:
def process(value: Any) -> str:
_step1 = self.process_literal_param(value, dialect="databricks")
if dialect.identifier_preparer._double_percents:
_step2 = _step1.replace("%", "%%")
else:
_step2 = _step1
return "%s" % _step2
return process
# monkeypatch
DatabricksDialect.colspecs = DatabricksDialect.colspecs.copy()
DatabricksDialect.colspecs[types.String] = DatabricksStringType
# Test after monkeypatch
query = literal_column("name").in_(["Anna's Decorations"])
compiled = query.compile(
dialect=AthenaPandasDialect(), compile_kwargs={"literal_binds": True}
)
print(f" PyAthena result after: {compiled}")
compiled = query.compile(
dialect=DatabricksDialect(), compile_kwargs={"literal_binds": True}
)
print(f" Databricks result after: {compiled}")
```
```bash
% python test_monkeypatch_effect.py
PyAthena result after: name IN ('Anna''s Decorations')
Databricks result after: name IN ('Anna\'s Decorations')
```
I need to do more investigation.
--
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]