2017-09-13 78 views
0

我在Pentaho步驟之一中創建了一個DB連接。我正在將我的環境從Oracle遷移到PostgreSQL。對PostgreSQL來說是全新的,我無法擺脫這些錯誤。加入如下:在Pentaho中使用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. 「一小時」作爲valueunit,

  2. (案((sum(a.value)/ sum(a.anzahl))/ 3600 + 0.0004,3) - 0.001,2)> b.target Then 'YES' Else 'NO' END )違反,

  3. 內部加入o.mspprov IDER = c.mspprovider和o.mspcustomer = c.mspcustomer 其中c.CalculationType在( 'MTTA', 'MTTR'))噸

我沒有進一步,因爲我粘到這些誤差進行。如果您看到,請隨時指出其他任何錯誤。 任何幫助將不勝感激。提前致謝。

回答

0

據我所知,在輸入表格字段中複製/粘貼一個查詢很簡單。

但是,輸入表的步驟是一個不是抽象的實現,這意味着你依賴於sql方言,並且還有更多隱藏的小東西,比如保留字[在'Hours'之前的值],範圍[違反是定義兩次],雙引號而不是簡單的,日期格式等...

如果你想使用水壺作爲一個抽象,沒有什麼比在輸入表中的「SELECT FROM table WHERE ORDER BY」步驟和做水壺的邏輯。

過了一段時間,你會發現它更簡單,而且對於像你這樣的複雜查詢,有時會更快。雖然,我承認,複製/粘貼是快速遷移的誘惑。

還替換?與${parameter},其中參數是在上一步中定義的字段的名稱。維護起來要簡單得多,幾個月後你就會發現,重用循環和複雜工作中的轉換是有用的。