Fork me on GitHub
#meander
<
2021-04-04
>
markaddleman23:04:42

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]]}}

markaddleman23:04:08

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