Closed blindcoding9 closed 1 year ago
Hi - I added an example showing the problem and solution beginning on line 1470 of tst.tupelo.forest-examples
. The problem is caused since Tupelo Forest uses the keywords
; :*
and :**
as special wildcard symbols. If your data includes any of these, just temporarily
; encode them into a harmless version, then reverse the process.
;---------------------------------------------------------------------------------------------------
; Example of how to quote/unquote any reserved words in user data. Tupelo Forest uses the keywords
; `:*` and `:**` as special wildcard symbols. If your data includes any of these, just temporarily
; encode them into a harmless version, then reverse the process
(def symbol->code {:* :quote/kw-star
:** :quote/kw-star-star})
(def code->symbol (set/map-invert symbol->code))
(def reserved-symbols-set (set (keys symbol->code)))
(def reserved-codes-set (set (keys code->symbol)))
(defn reserved-symbol?
"Returns true if arg is a reserved symbol"
[arg] (t/contains-key? reserved-symbols-set arg))
(defn reserved-code?
"Returns true if arg is a reserved symbol code"
[arg] (t/contains-key? reserved-codes-set arg))
(defn reserved-symbol-encode
"Walk EDN data, encoding any reserved symbols"
[arg]
(walk/postwalk (fn [item]
(cond-it-> item
(reserved-symbol? it) (grab it symbol->code)))
arg))
(defn reserved-symbol-decode
"Walk EDN data, decoding any reserved symbol codes"
[arg]
(walk/postwalk (fn [item]
(cond-it-> item
(reserved-code? it) (grab it code->symbol)))
arg))
(verify
; Ensure all symbols and codes don't clash
(is (apply = true (mapv reserved-symbol? reserved-symbols-set)))
(is (apply = true (mapv reserved-code? reserved-codes-set)))
(is (apply = false (mapv reserved-code? reserved-symbols-set)))
(is (apply = false (mapv reserved-symbol? reserved-codes-set)))
; Verify encode/decode functions
(let [data-orig {:id 1
:problem-field [:* :**]}
data-encoded {:id 1, :problem-field [:quote/kw-star :quote/kw-star-star]}]
(is= data-encoded (reserved-symbol-encode data-orig))
(is= data-orig (reserved-symbol-decode data-encoded))))
From the
find-step
exemple:But if you add this keyword
:*
an exception is throw.Im trying to use tupelo forest on Honeysql data structure:
Ex.:
{:select [:*] :from [:foo] :where [:in :foo.a {:select [:a], :from [:bar]}]}