简体   繁体   中英

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.

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 "Dataase SQL Executor" and "Database Reaser" 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.

The Vernalis community contribution has a DB to Variable node. If you change the input port type to DB Data Port , then one of the output variables will be the SQL query. If you are using the Legacy nodes, then the corresponding Database To Variable (Legacy) node will to the same thing.

Once you have the SQL in the variable, you can use a Variable to Table Row node, and then eg the Vernalis Save File Locally node, or if you require further options, String to Binary Objects and Binary Objects to Files nodes will allow that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM