Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select on multiple where conditions generate broken query #5

Closed
cibingeorge opened this issue Feb 19, 2017 · 0 comments
Closed

Select on multiple where conditions generate broken query #5

cibingeorge opened this issue Feb 19, 2017 · 0 comments
Assignees
Labels

Comments

@cibingeorge
Copy link

I have the following schema

CREATE TABLE user_events (
    account_uuid uuid,
    user_uuid uuid,
    timestamp bigint,
    event text,
        ....
    PRIMARY KEY ((account_uuid, user_uuid), timestamp, event)
    ) WITH .....


Trying to query by a timestamp

import Ecto.Query       
My.Repo.all(from event in UserEvents,
                   where: event.account_uuid == ^account_uuid and  event.user_uuid == ^user_uuid and event.timestamp >= ^timestamp)

generates a query

select * from user_events where ((account_uuid = <some uuid>) AND (user_uuid =  <some  uuid>)) AND (timestamp >= 201702140000);
SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:149 missing EOF at ')' (... AND (user_uuid =  <some uuid>)[)] AND...)">

The query works if the outer parenthesis is removed.

My.Repo.all(UserEvents |> where([c], c.account_uuid == ^account_uuid) |> where([c], c.user_uuid == ^user_uuid))
  |> where([c], c.timestamp >= ^timestamp) ) 

breaks as that case is not handled.

I could get the first case working by changing adapter/cql.ex

  defp op_to_binary({op, _, [_, _]} = expr, query) when op in @binary_ops, do:
     paren_expr(expr, query)

to

  defp op_to_binary({op, _, [_, _]} = expr, query) when op in @binary_ops, do:
    expr(expr, query)
@vintikzzz vintikzzz self-assigned this Feb 20, 2017
@vintikzzz vintikzzz added the bug label Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants