Search code examples
sqlxmlrcppexplorerknime

How to extract sql code from Knime Nodes?


Is there a way to automatically extract code from nodes and save it in .sql or .txt files? I'm using mostly Database SQL Executor (legacy) nodes where I have sql queries. I've found that there is settings.xml file for every node in which I can see code as a value for key="statement", maybe I could use XML Reader and XPath nodes somehow?

I would like to have .sql or .txt file for every node, that file should contain sql code that is pasted in that particular node. It would be great if I could choose a name of that file as name of a node.


Solution

  • I've decided to share the idea of my solution to that problem, maybe someone else would like to do something like this in simillar way.

    I had to work with RStudio and decided to write a script in Rcpp language (weird version of cpp that allows you to anchor R script in it). Script has a path to the Knime workflow and iterates through every Node folder in search of "Databse SQL Executor" and "Database Reader" nodes. Then extracts sql code and name of the node from settings.xml file. After saving it to the variables it clears node name from signs not allowed in windows file names (like ? : | \ / etc) or stuff that xml added. Same goes for sql code but instead of clearing xml stuff it changes it to the normal version of a sign (for example it changes %%000010 to \n or &lt to <)

    When sql code is cleared and formated it saves the code in a .sql file with the name beeing name of the node.

    It works pretty well and quite fast. One annying problem is that rcpp doesn't read UTF-8 signs so I had to clear them out from node names manually so the names are readable and not full of some nonesense.