Fork me on GitHub
Stuart Nath16:01:32

Hello All, I'm new to polylith and need some advice. • I used the polytool to generate a component. • It create a resource folder with a subfolder as the name of the component. • I put a nippy file in the folder that the component joins data from in a function call. • The component references the resource using a relative path. • The function works and runs in the component directory. • However, when I try to invoke the function via the polylith interface, in code, I get the error that it cannot find the resource nippy file, necessary for the join. In the component, the code looks like this:

(def ref-data (-> (tc/dataset ".\\resources\\geocode\\3digitzipcode.nippy")
                  (tc/convert-types "3Digit" :string)
                  (ds/column-map "meta-join" (fn [a b] (str a "-" b))
                                 ["3Digit" "Country"])
                  (tc/drop-columns "Country")))

(defn Geocode3DigitZip [dataset zip-code country] 
   (-> dataset
       (tc/convert-types zip-code :string)
       (ds/column-map :Zip3Digit (fn [a] (subs (str a) 0 3))
       (ds/column-map "meta-join" (fn [a b] (str a "-" b)) [:Zip3Digit country])
       (tc/drop-columns ["3Digit", "meta-join", ".\\resources\\geocode\\3digitzipcode.nippy.meta-join"])
       (tc/replace-missing ["State" "Country"] :value "XX")))
This code successfully runs in the component with this call:
(def sample-data (ds/->dataset {:zipcode [414 750 48168 "abc"]
                                  :country ["US" "US" "MX" "XX"]}))
(Geocode3DigitZip sample-data :zipcode :country)
However, when I call the same function via the interface,
(ns spinnakersca.07-sample
  (:require [tech.v3.dataset :as ds]
            [taoensso.nippy :as nippy]
            [tablecloth.api :as tc]
            [spinnakersca.geocode.interface :as geo]))

(def sample-data (ds/->dataset {:zipcode [414 750 48168 "abc"]
                                :country ["US" "US" "MX" "XX"]}))
(geo/Geocode3DigitZip sample-data :zipcode :country)
I get the following error: "Unable to find 3Digit" This is a field from the nippy file in the component's resource folder. Is there a setting a can adjust (perhaps in the deps.edn) to allow the component to function? Or is the solution to embed the data structure within the component file itself?


resources is on the classpath and files are generally accessed relative to the classpath so you want "geocode/3digitzipcode.nippy" -- classpath-relative -- and you'll need to ensure you use on that to get something readable.


(this is not Polylith-specific -- Clojure works that way in general)

Stuart Nath17:01:46

Thank you! This solved my problem and I learned something new about clojure.