Pentaho:字符串到 SQL Select 语句

Pentaho: String to SQL Select Statement

我有动态 SQL 需要在执行前对其进行操作。基本上我通过作为字符串传递来构建查询。我终于提出了查询,但我现在的问题是如何执行上述查询。我尝试使用 table 输入,但 SQL 的内容只是一个 '?'在构建的字符串上被替换。不幸的是,它不起作用。

我该怎么做?

下面是步骤截图。我可能不需要 Select 值步骤,我只是为了自己的可见性添加了它。我对 pentaho 水壶很陌生。但是,我希望你明白了。基本上我在这里所做的是,一旦我进入计算器步骤,这就是我制定 SQL 查询的地方,因为它是一个 select,我想在 Table 上执行它输入。

这是错误:

2015/04/15 21:45:09 - Table input.0 - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : Unexpected error
2015/04/15 21:45:09 - Table input.0 - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseException: 
2015/04/15 21:45:09 - Table input.0 - An error occurred executing SQL: 
2015/04/15 21:45:09 - Table input.0 - ?
2015/04/15 21:45:09 - Table input.0 - ERROR: syntax error at or near ""
  Position: 1
2015/04/15 21:45:09 - Table input.0 - 
2015/04/15 21:45:09 - Table input.0 -   at org.pentaho.di.core.database.Database.openQuery(Database.java:1641)
2015/04/15 21:45:09 - Table input.0 -   at org.pentaho.di.trans.steps.tableinput.TableInput.doQuery(TableInput.java:235)
2015/04/15 21:45:09 - Table input.0 -   at org.pentaho.di.trans.steps.tableinput.TableInput.processRow(TableInput.java:143)
2015/04/15 21:45:09 - Table input.0 -   at org.pentaho.di.trans.step.RunThread.run(RunThread.java:60)
2015/04/15 21:45:09 - Table input.0 -   at java.lang.Thread.run(Unknown Source)
2015/04/15 21:45:09 - Table input.0 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ""
  Position: 1
2015/04/15 21:45:09 - Table input.0 -   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2101)
2015/04/15 21:45:09 - Table input.0 -   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1834)
2015/04/15 21:45:09 - Table input.0 -   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
2015/04/15 21:45:09 - Table input.0 -   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510)
2015/04/15 21:45:09 - Table input.0 -   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
2015/04/15 21:45:09 - Table input.0 -   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
2015/04/15 21:45:09 - Table input.0 -   at org.pentaho.di.core.database.Database.openQuery(Database.java:1611)
2015/04/15 21:45:09 - Table input.0 -   ... 4 more
2015/04/15 21:45:09 - getLastIncrementingPk - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : Errors detected!
2015/04/15 21:45:09 - getLastIncrementingPk - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : Errors detected!

尝试将字符串保存在变量中。 然后在替换变量上使用带有标志的 table 输入(不是输出)。

得到答案。正如我所做的和你们所有人发布的那样,在提出 SQL 语句后,我将其放入一个变量中,例如 ${GEN_SQL}。即变身1.

然后我创建了另一个 Transformation(2) 来执行 SQL。首先我 "Get Variable" 步骤然后我使用 Table 输入,至于 SQL 我放在那里 ${GEN_SQL}。然后检查"Replace variables in script".

然后完成,SQL 以预期结果执行。

感谢大家的帮助。