简体   繁体   English

如何从 Knime 节点中提取 sql 代码?

[英]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?有没有办法自动从节点中提取代码并将其保存在 .sql 或 .txt 文件中? I'm using mostly Database SQL Executor (legacy) nodes where I have sql queries.我主要使用数据库 SQL 执行器(旧版)节点,其中我有 sql 查询。 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?我发现每个节点都有 settings.xml 文件,我可以在其中看到代码作为key="statement",也许我可以使用XML ReaderZB6454D498635710A189184CEA13节点?

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.我希望每个节点都有 .sql 或 .txt 文件,该文件应包含粘贴在该特定节点中的 sql 代码。 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).我不得不使用 RStudio 并决定用 Rcpp 语言编写一个脚本(奇怪的 cpp 版本允许您在其中锚定 R 脚本)。 Script has a path to the Knime workflow and iterates through every Node folder in search of "Dataase SQL Executor" and "Database Reaser" nodes.脚本具有 Knime 工作流的路径,并遍历每个节点文件夹以搜索“Dataase SQL Executor”和“Database Reaser”节点。 Then extracts sql code and name of the node from settings.xml file.然后从 settings.xml 文件中提取 sql 代码和节点名称。 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.将其保存到变量后,它会清除 windows 文件名中不允许的符号(如? : | \ /等)或 xml 添加的内容中的节点名称。 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 < ) sql 代码也是如此,但不是清除 xml 的东西,而是将其更改为符号的正常版本(例如,它将%%000010更改为\n&lt<

When sql code is cleared and formated it saves the code in a.sql file with the name beeing name of the node.当 sql 代码被清除并格式化时,它会将代码保存在一个.sql 文件中,名称为节点的名称。

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.一个棘手的问题是 rcpp 不读取 UTF-8 标志,所以我必须手动从节点名称中清除它们,这样名称才可读且不包含一些废话。

The Vernalis community contribution has a DB to Variable node. Vernalis 社区贡献有一个DB to Variable节点。 If you change the input port type to DB Data Port , then one of the output variables will be the SQL query.如果将输入端口类型更改为DB Data Port ,则 output 变量之一将是 SQL 查询。 If you are using the Legacy nodes, then the corresponding Database To Variable (Legacy) node will to the same thing.如果您使用的是 Legacy 节点,那么相应的Database To Variable (Legacy)节点将指向同一事物。

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在变量中包含 SQL 后,您可以使用Variable to Table Row节点,然后使用 Vernalis Save File Locally节点,或者如果您需要更多选项, String to Binary ObjectsBinary Objects to Files节点将允许这样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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