【问题标题】:Pentaho: String to SQL Select StatementPentaho:字符串到 SQL 选择语句
【发布时间】:2015-06-21 14:52:09
【问题描述】:

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

我该怎么做?

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

这是错误:

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 "$1"
  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 "$1"
  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!

【问题讨论】:

  • 你在那里工作吗?还是来自您设置变量的同一转换?你能提供更多关于你得到的错误,你使用的步骤的信息吗?
  • 我会更详细地更新帖子。但是为了回答你的问题,我使用了一个转换。变量是在先前的转换上设置的。我为这个转换所做的是“获取变量”并从那里获取。
  • 这表明您保存在变量中的字符串不是一个好的 sql。记录该变量的值并在客户端(如 toad、sqlserver、squirrel 或其他)中执行该值

标签: sql pentaho kettle dynamic-queries


【解决方案1】:

得到了答案。正如我所做的和你们都发布的那样,在提出 SQL 语句后,我将它放在一个变量中,例如 ${GEN_SQL}。那就是转换1。

然后我创建了另一个 Transformation(2) 来执行 SQL。首先我“获取变量”步骤,然后我使用表输入,至于我放在那里的 SQL ${GEN_SQL}。然后检查“替换脚本中的变量”。

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

感谢大家的帮助。

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 已经保存在一个变量中,是的,我很抱歉我的意思是表格输入(将更新我的帖子)。就像我说的,我试过了,但没有用。它给出了一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 2011-10-28
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    相关资源
    最近更新 更多