From b042dfae605e981828be2b328346e949466c4f2d Mon Sep 17 00:00:00 2001 From: Will <32901547+WBSemple@users.noreply.github.com> Date: Fri, 10 May 2024 11:48:12 +0100 Subject: [PATCH] multi gsi --- src/taoensso/faraday.clj | 5 +++-- test/taoensso/faraday/tests/main.clj | 32 ++++++++++------------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/taoensso/faraday.clj b/src/taoensso/faraday.clj index e5639e9..0aa59f0 100644 --- a/src/taoensso/faraday.clj +++ b/src/taoensso/faraday.clj @@ -836,13 +836,14 @@ [table table-desc {:keys [throughput gsindexes stream-spec billing-mode] :as params}] (assert (not (and throughput (= :pay-per-request billing-mode))) "Can't specify :throughput and :pay-per-request billing-mode") - (let [attr-defs (keydefs nil nil nil [gsindexes])] + (let [gsindexes (cond-> gsindexes (map? gsindexes) vector) + attr-defs (keydefs nil nil nil gsindexes)] (doto-cond [_ (UpdateTableRequest.)] :always (.setTableName (name table)) throughput (.setProvisionedThroughput (provisioned-throughput throughput)) billing-mode (.setBillingMode (utils/enum billing-mode)) - gsindexes (.setGlobalSecondaryIndexUpdates [(global-2nd-index-updates table-desc gsindexes)]) + gsindexes (.setGlobalSecondaryIndexUpdates (mapv (partial global-2nd-index-updates table-desc) gsindexes)) stream-spec (.setStreamSpecification (stream-specification stream-spec)) (seq attr-defs) (.setAttributeDefinitions attr-defs)))) diff --git a/test/taoensso/faraday/tests/main.clj b/test/taoensso/faraday/tests/main.clj index 6e8d645..d767822 100644 --- a/test/taoensso/faraday/tests/main.clj +++ b/test/taoensso/faraday/tests/main.clj @@ -1070,18 +1070,16 @@ }}) ;; We need to wait until the index is created before updating it, or the call will fail _ @(index-status-watch *client-opts* temp-table :gsindexes "genre-index") - inc-idx @(far/update-table *client-opts* temp-table - {:gsindexes {:operation :update - :name "genre-index" - :throughput {:read 6 :write 6} - }}) - ;; We can create a second index right after - amt-idx @(far/update-table *client-opts* temp-table - {:gsindexes {:operation :create - :name "amount-index" - :hash-keydef [:amount :n] - :throughput {:read 1 :write 1} - }}) + inc-and-amt-idxs @(far/update-table *client-opts* temp-table + {:gsindexes [{:operation :update + :name "genre-index" + :throughput {:read 6 :write 6} + } + {:operation :create + :name "amount-index" + :hash-keydef [:amount :n] + :throughput {:read 1 :write 1} + }]}) ;; Let's wait until amount-index is created before deleting genre-index, ;; so that we can consistently evaluate the result (otherwise we might not ;; know if size/item-count are 0 or nil. @@ -1103,14 +1101,6 @@ :throughput {:read 4 :write 2 :last-decrease nil :last-increase nil :num-decreases-today nil}}] (->> (:gsindexes new-idx) (map #(dissoc % :size :item-count)))))) (testing "The updated index has the new throughput values, as well as a size and item-count since it was already created" - (is (= [{:name :genre-index - :size 0 - :item-count 0 - :key-schema [{:name :genre :type :hash}] - :projection {:projection-type "ALL" :non-key-attributes nil} - :throughput {:read 6 :write 6 :last-decrease nil :last-increase nil :num-decreases-today nil}}] - (:gsindexes inc-idx)))) - (testing "The second index created comes back" (is (= #{{:name :amount-index :key-schema [{:name :amount :type :hash}] :projection {:projection-type "ALL" :non-key-attributes nil} @@ -1119,7 +1109,7 @@ :key-schema [{:name :genre :type :hash}] :projection {:projection-type "ALL" :non-key-attributes nil} :throughput {:read 6 :write 6 :last-decrease nil :last-increase nil :num-decreases-today nil}}} - (set (->> (:gsindexes amt-idx) (map #(dissoc % :size :item-count))))))) + (set (->> (:gsindexes inc-and-amt-idxs) (map #(dissoc % :size :item-count))))))) (testing "When we request that the genre index be deleted, it returns that it's being destroyed" (is (= #{{:name :amount-index :key-schema [{:name :amount :type :hash}]