I have a meander puzzler: Use rewrite
to efficiently fully qualify column references in a honeysql data structure. For example:
{:select [:a] :from [:t]}
should be converted into
{:select [:t.a] :from [:t]}
There are many complicating factors including identifying column references. In my case, all column references are a special type so, the above example is more properly:
{:select [#ColRef[:a]] :from [#TableRef[:t]]}
converted to
{:select [#ColRef[:t :a]] :from [#TableRef[:t]]}
There are additional complications that are not as easy to handle including subqueries. For example:
{:select [#ColRef[:a] {:select #call["MAX" :a] :from [#TableRef[:s]]}] :from [#TableRef[:t]]}
Another complication is that some column references are already fully qualified and, thus, should not be rewritten:
{:select [#colRef[:a]] :from [#TableRef[:t]] :where #call["IN" #ColRef[:b] {:select [#ColRef[:b]] :from [#TableRef[:s]] :where #Call["=" #ColRef[:t :a] #ColRef[:s :a]]}}
I have a meander program that performs the correct rewriting but pretty slow on large honeysql data structures because (I believe) an overuse of m/$
to search for queries and column references. I don't know how to convert it to a more efficient meander program and would love some ideas