circles-learning-labs / ecto_adapters_dynamodb

DynamoDB adapter for Elixir's Ecto Database layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TO-DO: Handle multi-condition all... in... queries on hash key primary indexes

darrenklein opened this issue · comments

Multi-condition queries, such as

TestRepo.all(from p in Person, where: p.first_name in ^first_names and p.age < 50)

are currently working, where first_name is a hash key (either on its own or part of a composite key), but will fail for similar queries where we're querying on the primary key, such as

TestRepo.all(from p in Person, where: p.id in ^ids and p.age < 50)

will fail with the error

** (FunctionClauseError) no function clause matching in Ecto.Adapters.DynamoDB.Query.make_batched_search/2

...

     Attempted function clauses (showing 1 out of 1):
     
         defp make_batched_search([{index, {_vals, op}}], hash_batch)

This issue has been resolved (mostly) with the release of version 0.5.1 - however, this kind of query on a composite primary key will only work under certain conditions. Specifically, the second condition cannot be an "open-ended" condition like p.age > 50 - it must also be an in query, where the values correspond with the first condition. For example:

TestRepo.all(from p in Person, where: p.id in ^ids and p.age in ^ages)

where the lists of ids and ages are the same length.

We may look to support more powerful queries on composite primary keys in the future, though this needs further investigation.