Dynamoid icon indicating copy to clipboard operation
Dynamoid copied to clipboard

Data Modeling with Dynamoid

Open cheneveld opened this issue 13 years ago • 0 comments

If I have the following model setup with partitioning turned on:

class Table
  include Dynamoid::Document
  table :name => :table
  field :field1
  field :start_time, :datetime

  index :field1, :range_key => :start_time
end

Creates records fine. But when I try to Query the table with something like Table.where(:field1 => "123", "start_time.lt" => Time.now)

This QUERY doesn't take into account the partitioning.

This makes sense as we can't really QUERY a set of partitioned ids, as dynamoDB needs a distinct HASH_KEY and RANGE_KEY to query with. But was wondering if you intended partitioning to work with indexes?

I am currently trying to find the best way to setup a schema where I can query on 2 fields and a datetime range key in one shot.

Our current solution involves combining 2 fields as the id as seen below:

class Table  
  include Dynamoid::Document
  table :name => :table
  range :start_time, :datetime 
  field :field1
  field :field2
  field :field3
end

and inserting like

Table.new( :id => field1 + '.' + field2, , :start_time => date, :field1 => field1, :field2 => field2, :field3 => field3)

Unfortunately, this doesn't spread the hash_keys out for uniform workload. but works!

Any insight would be fantastic.

cheneveld avatar Dec 01 '12 18:12 cheneveld