{"action":"opened","issue":{"url":"https://api.github.com/repos/cloudera/impyla/issues/210","repository_url":"https://api.github.com/repos/cloudera/impyla","labels_url":"https://api.github.com/repos/cloudera/impyla/issues/210/labels{/name}","comments_url":"https://api.github.com/repos/cloudera/impyla/issues/210/comments","events_url":"https://api.github.com/repos/cloudera/impyla/issues/210/events","html_url":"https://github.com/cloudera/impyla/issues/210","id":175155274,"number":210,"title":"Produce invalid SQL working with SQLAlchemy (concat)","user":{"login":"DeanThompson","id":1628320,"avatar_url":"https://avatars.githubusercontent.com/u/1628320?v=3","gravatar_id":"","url":"https://api.github.com/users/DeanThompson","html_url":"https://github.com/DeanThompson","followers_url":"https://api.github.com/users/DeanThompson/followers","following_url":"https://api.github.com/users/DeanThompson/following{/other_user}","gists_url":"https://api.github.com/users/DeanThompson/gists{/gist_id}","starred_url":"https://api.github.com/users/DeanThompson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeanThompson/subscriptions","organizations_url":"https://api.github.com/users/DeanThompson/orgs","repos_url":"https://api.github.com/users/DeanThompson/repos","events_url":"https://api.github.com/users/DeanThompson/events{/privacy}","received_events_url":"https://api.github.com/users/DeanThompson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-06T03:53:44Z","updated_at":"2016-09-06T03:53:44Z","closed_at":null,"body":"Impyla uses the default `statement_compiler`, which compiles `concat` operator to `||`.\r\n\r\nFor example:\r\n\r\n```python\r\n>>> engine = create_engine('impala://localhost')\r\n>>> metadata = MetaData(engine)\r\n>>> mytable = Table(\"mytable\",\r\n                metadata,\r\n                Column('col1', STRING),\r\n                Column('col2', TINYINT),\r\n                Column('col3', INT),\r\n                Column('col4', DOUBLE))\r\n\r\n>>> stmt = mytable.select().where(mytable.c.col1.startswith('a'))\r\n>>> print stmt.compile(engine, compile_kwargs={'literal_binds': True})\r\n\r\nSELECT mytable.col1, mytable.col2, mytable.col3, mytable.col4\r\nFROM mytable\r\nWHERE (mytable.col1 LIKE 'a' || '%%')\r\n```\r\n\r\nThe SQL will cause a `DBAPIError`, while the query below is OK.\r\n\r\n```SQL\r\nSELECT mytable.col1, mytable.col2, mytable.col3, mytable.col4\r\nFROM mytable\r\nWHERE (mytable.col1 LIKE concat('a', '%%'))\r\n```\r\n\r\nThis can be fixed by override the default `visit_concat_op_binary` method of `SQLCompiler` like this:\r\n\r\n```python\r\nclass ImpalaCompiler(SQLCompiler):\r\n    def visit_concat_op_binary(self, binary, operator, **kw):\r\n        return \"concat(%s, %s)\" % (self.process(binary.left), self.process(binary.right))\r\n```\r\n\r\nthen\r\n\r\n```python\r\nclass ImpalaDialect(DefaultDialect):\r\n    statement_compiler = ImpalaCompiler   # use ImpalaCompiler instead of default SQLCompiler\r\n```"}}
{"actor":{"display_login":"DeanThompson"}}