I want to execute a set of select-based sql queries, derived from xml-node elements within a XML file, and write the values of the corresponding resultsets in a CSV file. I'd like to clarify that no field of the sql query is parameterized, but the full sql query itself is.
The part of getting the full sql query is done as expected, but I don't know how to proceed with the part of launching the sql query so that I can get the corresponding resultset to manage it later.
What I've tried until now with no success is the following:
Execute SQL script
step: according to what it's said here, this sort of step doesn't get any resultset.Dynamic SQL Row
step: I get the corresponding sql as long as I hardcode the field 'TemplateSQL', but I can't do that because the sql queries derived from the previous step are very different among them and don't provide a fixed meta-data scheme.Table Input
step: this step only allows single values of a sql query to be parameterized, not the full query.
I'd really appreciate if some pentaho-kettle expert could tell me the right way of accomplishing the task I want to do.
Update (following @Cristian Curti instructions): The problem arise in KTR-1. When you say "you have to pass this query as a variable to another KTR", I understand that what I have to do first is setting the xml-node value in a variable and then pass it to the KTR-2. To do so, in my KTR-1 I'm using these steps:
Get Data from XML
: I'm getting 'SQLQuery' field.Set Variables
: I'm setting the field 'SQLQuery' in a variable named 'QUERY'. (Moreover, KTR-1 is set as you said, that is, in the Parameters tab I set a parameter named 'QUERY').
When I preview the second step of KTR-1, the Kettle console logs the following error:
Get data from XML.0 - Finished processing (I=2, O=0, R=0, W=2, U=0, E=0)
Set variables.0 - Setting environment variables...
Set variables.0 - Set variable QUERY to value [
SELECT "Table1".*, "table2"."field1" FROM "Table1" INNER JOIN "Table2" ON Table1"."PATIENT" = "Table2"."PATIENT" WHERE ("Table1"."field1" > Table1"."field2") AND NOT("field1" BETWEEN 'date1' AND 'date2')
]
Set variables.0 - ERROR (version 8.2.0.0-342, build 8.2.0.0-342 from 2018-1-14 10.30.55 by buildguy) : Unexpected error
Set variables.0 - ERROR (version 8.2.0.0-342, build 8.2.0.0-342 from 2018-1-14 10.30.55 by buildguy) : org.pentaho.di.core.exception.KettleStepException:
Set variables.0 - Only 1 input row was expected to set the variables and at least 2 were received.
It seems Set Variables
step only expects to receive one single row.
I don't know if I'm doing something wrong or missing something. In case you need further details, just tell me. Thanks.