Sorry, this is the problem with working all night. My sleep deprived eyes skipped over this line:
old-field-value (get old-documents field-name []) I fetch the value from the wrong map. Such a basic error. On Wednesday, October 11, 2017 at 1:44:13 PM UTC-4, lawrence...@gmail.com wrote: > > I should remove the parens before they confuse anyone. They are added by > the log statement. Without the parens: > > > > {:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]} > > field-name: > :company_profile_id > > field-value: > ["2"] > > but I in the final document I only get: > > "final document: " {:company_profile_id ["2"], :topic :company, :url [" > mikeshawauto.com"]} > > I want: > > "final document: " {:company_profile_id ["2" "2"], :topic :company, :url [" > mikeshawauto.com"]} > > > > On Wednesday, October 11, 2017 at 1:42:12 PM UTC-4, lawrence...@gmail.com > wrote: >> >> So I tried this: >> >> new-field-value (into [] (concat old-field-value >> field-value)) >> >> And I did not get what I expected. Maybe I am sleep deprived, but I don't >> see why I can't build up a vector with several values. This is in a map in >> an atom. This is the code: >> >> (swap! documents >> (fn [old-documents] >> (let [ >> document (get old-documents denormalized-id {}) >> >> _ (errors/log document) >> _ (errors/log field-name) >> _ (errors/log field-value) >> >> old-field-value (get old-documents field-name []) >> new-field-value (into [] (concat old-field-value >> field-value)) >> document (assoc document field-name new-field-value) >> >> _ (errors/log "final document: " document) >> new-documents (assoc old-documents denormalized-id >> document) >> ] >> new-documents) >> >> Those log statements show me this for old-field-value: >> >> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]}) >> >> field-name: >> (:company_profile_id) >> >> field-value: >> (["2"]) >> >> but I in the final document I only get: >> >> ("final document: " {:company_profile_id ["2"], :topic :company, :url [" >> mikeshawauto.com"]}) >> >> I want: >> >> ("final document: " {:company_profile_id ["2", "2"], :topic :company, >> :url ["mikeshawauto.com"]}) >> >> What am I missing here? >> >> >> >> >> On Wednesday, October 11, 2017 at 12:28:59 PM UTC-4, >> lawrence...@gmail.com wrote: >>> >>> So I have this: >>> >>> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com >>> "]}) >>> >>> And then I get this field name and value: >>> >>> (:company_profile_id) >>> >>> (["2"]) >>> >>> The next 3 lines of code are: >>> >>> old-field-value (get old-documents field-name []) >>> new-field-value (into old-field-value field-value) >>> document (assoc document field-name new-field-value) >>> >>> And when the function is next called, I end up with : >>> >>> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com >>> "]}) >>> >>> I need: >>> >>> ({:company_profile_id ["2", "2"], :topic :company, :url [" >>> mikeshawauto.com"]}) >>> >>> So perhaps I've misunderstood what (into) is for? How do I add another >>> the values of these 2 vectors together? >>> >>> >>> >>> >>> >>> On Wednesday, October 11, 2017 at 12:20:55 PM UTC-4, >>> lawrence...@gmail.com wrote: >>>> >>>> Using conj instead of into, for no particular reason, except debugging. >>>> The document is slowly built-up: >>>> >>>> ({:company_profile_id [["2"]], :topic :company, :url [[" >>>> mikeshawauto.com"]]}) >>>> >>>> ({:company_profile_id [["2"]], :topic :company, :url [[" >>>> mikeshawauto.com"]]}) >>>> >>>> ({:company_profile_id [["2"]], :topic :company, :url [[" >>>> mikeshawauto.com"]], :reference_id [["331089191"]]}) >>>> >>>> In the transition from row 1 to row 2, I assume the field being added >>>> is company_profile_id. Why is there no change? Why isn't a new value added >>>> to the vector? I must be missing something obvious. >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> On Wednesday, October 11, 2017 at 11:44:40 AM UTC-4, >>>> lawrence...@gmail.com wrote: >>>>> >>>>> I seem unable to figure out where I made a mistake, though this should >>>>> be simple. >>>>> >>>>> I have two SQL calls that bring back 5 fields: >>>>> >>>>> SELECT company_profile_id , reference_id, reference_source FROM >>>>> company_reference_id limit 1 ; >>>>> >>>>> +--------------------+--------------+------------------+ >>>>> | company_profile_id | reference_id | reference_source | >>>>> +--------------------+--------------+------------------+ >>>>> | 2 | 331089191 | EIN | >>>>> +--------------------+--------------+------------------+ >>>>> >>>>> SELECT company_profile_id, url FROM company_website >>>>> limit 1 ; >>>>> >>>>> +--------------------+------------------+ >>>>> | company_profile_id | url | >>>>> +--------------------+------------------+ >>>>> | 2 | mikeshawauto.com | >>>>> +--------------------+------------------+ >>>>> >>>>> This brings back a total of 5 values. I need to have a document that >>>>> has 5 values, though if values have the same field-name, then I want to >>>>> consolidate them into one vector. There are 4 unique field names, so I >>>>> expect to end up with 4 vectors, holding 5 values. Instead, I get this: >>>>> >>>>> ({:company_profile_id ["2"], :topic :company, >>>>> :how-many-rows-and-fields-from-database 13, :url ["mikeshawauto.com"], >>>>> :reference_id ["331089191"], :reference_source ["ein"]}) >>>>> >>>>> I expect: >>>>> >>>>> {:company_profile_id ["2" "2"] >>>>> >>>>> but I get: >>>>> >>>>> {:company_profile_id ["2"] >>>>> >>>>> The documents are combined in a map in an atom, with this function: >>>>> >>>>> >>>>> (def documents (atom {})) >>>>> >>>>> >>>>> (defn update-documents >>>>> [denormalized-id field-name field-value >>>>> how-many-rows-and-fields-from-database topic] >>>>> {:pre [ >>>>> (not (nil? denormalized-id)) >>>>> (not (nil? field-name)) >>>>> (vector? field-value) >>>>> ]} >>>>> (swap! documents >>>>> (fn [old-documents] >>>>> (slingshot/try+ >>>>> (let [ >>>>> document (get old-documents denormalized-id {}) >>>>> old-field-value (get old-documents field-name []) >>>>> new-field-value (into old-field-value field-value) >>>>> document (assoc document field-name new-field-value) >>>>> >>>>> previous-how-many-rows-and-fields-from-database (get >>>>> document :how-many-rows-and-fields-from-database 0) >>>>> new-how-many-rows-and-fields-from-database (+ >>>>> previous-how-many-rows-and-fields-from-database >>>>> how-many-rows-and-fields-from-database) >>>>> document (assoc document :topic topic) >>>>> document (assoc document >>>>> :how-many-rows-and-fields-from-database >>>>> new-how-many-rows-and-fields-from-database) >>>>> new-documents (assoc old-documents denormalized-id >>>>> document) >>>>> ] >>>>> new-documents) >>>>> (catch Object o >>>>> (errors/log o) >>>>> (slingshot/throw+ { >>>>> :type ::update-documents >>>>> :error o >>>>> } >>>>> )))))) >>>>> >>>>> Can I assume that this always gives me 2 values in a vector? >>>>> >>>>> old-field-value (get old-documents field-name []) >>>>> new-field-value (into old-field-value field-value) >>>>> document (assoc document field-name new-field-value) >>>>> >>>>> I'm going to guess that the bug is somewhere else in my code. But if >>>>> anyone sees a flaw in this function, I'd be grateful if you could point >>>>> it >>>>> out to me. >>>>> >>>>> >>>>> >>>>> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.