nervous-systems / hildebrand

Asynchronous DynamoDB client for Clojure & Clojurescript/Node
The Unlicense
66 stars 10 forks source link

create-table! without :indexes. "number of attributes in key schema must match .." #11

Closed andreasthoelke closed 8 years ago

andreasthoelke commented 8 years ago

Thank you for hildebrand, it looks great!

I'm seeing some strange behaviour when trying to use create-table! without the :indexes key in the table-spec. (Which I assume is optional based on http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html ?) E.g. this works:

(hc/create-table!!
 creds
 {:table :curries
  :throughput {:read 1 :write 1}
  :attrs {:name :string :region :string :spiciness :number}
  :keys  [:name]
  :indexes {:global
            [{:name :curries-by-region-spiciness
              :keys [:region :spiciness]
              :project [:all]
              :throughput {:read 1 :write 1}}]}})

But this gives me an error (“validation-exception: The number of attributes in key schema must match the number of attributesdefinined in attribute definitions.”):

(hc/create-table!!
 creds
 {:table :curries1
  :throughput {:read 1 :write 1}
  :attrs {:name :string :region :string :spiciness :number}
  :keys  [:name]})

On the other hand this works:

(hc/create-table!!
 creds
 {:table :curries2
  :throughput {:read 1 :write 1}
  :attrs {:name :string}
  :keys  [:name]})

However this gives me the same error as above:

(hc/create-table!!
 creds
 {:table :curries3
  :throughput {:read 1 :write 1}
  :attrs {:name :string :region :string}
  :keys  [:name]})

This again works:

(hc/create-table!!
 creds
 {:table :curries4
  :throughput {:read 1 :write 1}
  :attrs {:name :string :region :string}
  :keys  [:name :region]})

.. which made me expect that this would work, but it fails with the same error as above:

(hc/create-table!!
 creds
 {:table :curries5
  :throughput {:read 1 :write 1}
  :attrs {:name :string :region :string :spiciness :number}
  :keys  [:name :region :spiciness]})

The way I understood it so far

moea commented 8 years ago

Hey, I'm not at an actual computer, but I think in general the problems you're seeing are around the declaration of attributes which aren't used in some combination of the key / index schema. If an attribute isn't used in either, it can't be declared in :attrs.

The last example is incorrect due the use of three entries in : keys - at best, this library will ignore the last item - the acceptable forms being [hash] or [hash range].

In your first non-working example, trimming :attrs down to only contain :name ought to fix it. Which won't affect your ability to attach the evicted attrs - or any others - to the items in the table.

Let me know if that works out, and what else I can do to help.

andreasthoelke commented 8 years ago

Thanks, this cleared up two misconceptions I had:

So yes, everything works fine now. Thanks again!

moea commented 8 years ago

Great - please don't hesitate to file any follow-up issues if you have any questions.