2017-09-13 29 views
0

私は自分のPentahoステップの1つで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で正常に動作します。ケース(

valueunitとして

  1. 「時間」、

  2. :PostgreSQLの中でそれを使用してみましたが、それはいくつかのエラーをスローし、エラーが次の場所(また、クエリに太字で表示)でスローされます 'YES' 'NO' END(この場合、丸め(a.value)/合計(a.anzahl) )違反したとして、

  3. インナーo.mspprov IDER = c.mspproviderとo.mspcustomer = c.mspcustomer私はこれらのエラーに貼り付けていますようc.CalculationTypeが( 'MTTA'、 'MTTR'))T

に、私はさらに進んでいない 。表示されている場合は、他のエラーを指摘してください。 ご協力いただければ幸いです。前もって感謝します。

答えて

0

私は入力テーブルのフィールドでクエリをコピー/ペーストして、迅速かつ簡単であることを理解しています。

しかし、入力テーブルのステップは抽象的なものではなく、SQLの方言に依存していることを意味し、予約語['Hours'の直前の値]、[[二重定義されている場合は、単純な日付書式の代わりに二重引用符を使用します。

ケトルを抽象化として使用する場合は、入力テーブルのステップで「SELECT FROM table WHERE ORDER BY」以上ケトルで論理をする。

は、しばらくして、あなたは時々より速く、あなたのような複雑なクエリに、それは簡単です見つけてます。私は、コピー/ペーストは素早い移行のために魅力的であると認めますが、

また、 ${parameter}で、parameterは前のステップで定義されたフィールドの名前です。ループや複雑なジョブで変換を再利用するために有用であることが、いくつかの月に、維持するために、そして、あなたは発見するでしょうはるかに簡単です。

関連する問題