将 PostgreSQL 与 Pentaho 结合使用

Using PostgreSQL with Pentaho

我在我的 Pentaho 步骤之一中创建了一个数据库连接。我正在将我的环境从 Oracle 转移到 PostgreSQL。作为 PostgreSQL 的新手,我无法摆脱这些错误。加入如下:

select t.contract,
   t.calender,
   t.mspprovider,
   t.mspcustomer,
   t.objectname,
   t.granularity,
   t.timeperiod,
   cast(max(t.value) as numeric) as Value,
   null as correctedvalue,
   t.valueunit,
   max(t.violated) as violated,
   null as violatedcorr,
   t.severity,
   t.relation,
   t.target,
   t.targetunit,
   t.targetperiod,
   t.calculationtype,
   t.aggregationtype,
   current_date as createdate,
   current_date as modifydate
from (select a.contract,
           a.calender,
           a.mspprovider,
           a.mspcustomer,
           a.objectname,
           ? as granularity,
           ? as timeperiod,
           Round(Round((sum(a.value)) / sum(a.anzahl)) / 3600 + 0.0004, 3) - 0.001, 2) as value,
           *****'Hour'***** as valueunit
           *****(case
             when Round(Round((sum(a.value) / sum(a.anzahl)) / 3600 + 0.0004, 3) - 0.001, 2) > b.target Then
              'YES'
             Else
              'NO'
           END)** as violated***,
           a.severity,
           a.relation,
           b.target,
           b.targetunit,
           b.targetperiod,
           a.calculationtype as calculationtype,
           b.calculationtype as aggregationtype
      from (select a.contract,
                   a.calender,
                   a.mspprovider,
                   a.mspcustomer,
                   a.objectname,
                 cast(sum(a.durationmodified) as numeric) as Value,  
                   a.severity,
                   a.relation,
                   a.calculationType as calculationtype,
                   a.originatorid,
                   a.calculationversion,
                   count(*) as anzahl
              from result_slalom a,
                   (select a.contract,
                           a.calender,
                           a.mspprovider,
                           a.mspcustomer,
                           a.objectname,
                           a.eventid,
                           a.calculationtype,
                           max(a.calculationversion) as calculationversion
                      from result_slalom a
                     group by a.contract,
                              a.calender,
                              a.mspprovider,
                              a.mspcustomer,
                              a.objectname,
                              a.eventid,
                              a.calculationtype
                     order by 1 asc, 2 asc, 6 asc, 7 asc, 8 asc) b
             where a.endkeydate >= ?
               and a.endkeydate < ?
               and b.contract = a.contract
               and b.calender = a.calender
               and b.mspprovider = a.mspprovider
               and b.mspcustomer = a.mspcustomer
               and b.objectname = a.objectname
               and b.eventid = a.eventid
               and b.calculationtype = a.calculationtype
               and a.calculationversion = b.calculationversion
               and a.impact = 'YES'
             group by a.contract,
                      a.calender,
                      a.mspprovider,
                      a.mspcustomer,
                      a.objectname,
                      a.severity,
                      a.relation,
                      a.originatorid,
                      a.calculationtype,
                      a.calculationversion
             order by 1 asc, 2 asc, 7 asc, 9 asc) a,
           contract_target_mapping b
     where b.contract = a.contract
       and b.calender = a.calender
       and b.calculationtype = 'M' || a.calculationtype
       and b.severity = a.severity
       and b.target not in ('Dynamic')
     group by a.contract,
              a.calender,
              a.mspprovider,
              a.mspcustomer,
              a.objectname,
              a.severity,a.relation,
              b.target,
              b.targetunit,
              b.targetperiod,
              a.calculationtype,
              b.calculationtype 
    union
    select c.contract,
           c.calender,
           c.mspprovider,
           c.mspcustomer,
           o.objectname as objectname,
           ? as granularity,
           ? as timeperiod,
            null as value,
           'Hour' as valueunit,
           'NO' as violated,
           c.severity,
           c.relation,
           c.target,
           c.targetunit,
           c.targetperiod,
           SubStr(c.calculationtype, 2, 200) as calculationtype,
           'M' || SubStr(c.calculationtype, 2, 200) as aggregationtype
      from contract_target_mapping c
           ***Inner Join originator o on o.mspprovider = c.mspprovider and o.mspcustomer = c.mspcustomer
     where c.CalculationType in ('MTTA','MTTR') ) t***
 group by t.contract,
      t.calender,
      t.mspprovider,
      t.mspcustomer,
      t.objectname,
      t.granularity,
      t.timeperiod,
      t.valueunit,
      t.severity,
      t.relation,
      t.target,
      t.targetunit,
      t.targetperiod,
      t.calculationtype,
      t.aggregationtype


order by 1 asc, 2 asc, 12 asc

此联接在 Oracle 中运行良好。尝试在 PostgreSQL 中使用它,但它会抛出一些错误,并且会在以下位置抛出错误(也在查询中以粗体标记):

  1. 'Hour' as valueunit,

  2. (案例 当 Round(Round((sum(a.value) / sum(a.anzahl)) / 3600 + 0.0004, 3) - 0.001, 2) > b.target 然后 'YES' 别的 'NO' END) 违规,

  3. Inner Join originator o on o.mspprovider = c.mspprovider and o.mspcustomer = c.mspcustomer 其中 c.CalculationType 在 ('MTTA','MTTR') ) t

我一直纠结于这些错误,所以没有继续进行下去。如果您看到任何其他错误,请随时指出。 任何帮助将非常感激。提前致谢。

我知道在输入 table 字段中 copy/paste 查询既快捷又容易。

但是,输入 table 步骤是一个实现而不是抽象,这意味着您依赖于 sql 方言,并且还依赖于更多隐藏的小东西,例如保留字 [之前的值'Hours']、范围[违反定义两次]、双引号代替简单、日期格式等...

如果您想使用 kettle 作为抽象,只需在输入 table 步骤中执行 "SELECT FROM table WHERE ORDER BY" 并在 Kettle 中执行逻辑即可。

一段时间后,您会发现它更简单,而且在像您这样的复杂查询中,有时速度更快。虽然,我承认,copy/paste 很想快速迁移。

还要替换 ? with ${parameter},其中参数是在上一步中定义的字段的名称。维护起来要简单得多,并且您会在几个月后发现在循环和复杂作业中重用转换非常有用。