使用逗号分隔的源文件,然后使用java转换来分割行

时间:2016-04-26 13:42:47

标签: informatica informatica-powercenter informatica-powerexchange

我有一个以逗号分隔的源平面文件,文件包含开头日期和结束日期的标题,下一行包含所有字段名称并继续使用数据 源文件的示例:

"2015-05-09","2015-06-05"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
"CARRIER ","CONTRACT          ","ELGBL/GRP         ","                  ","TOTAL FEES","TOTAL FEES     ","PMPM ACA    ","PMPM ACA    ","RETAIL      ","RETAIL      ","MEDICAID    ","MEDICAID    ","STATE    ","STATE    ","MAIL SERVICE","MAIL SERVICE","RETAIL      ","RETAIL      ","POSTAGE -   ","POSTAGE -   ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","SYSTEM      ","OTHER       ","OTHER       ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","          
"        ","                  ","                  ","                  ","COUNT     ","AMOUNT         ","METAL       ","METAL       ","DIRECTS     ","DIRECTS     ","            ","            ","HEALTH      ","HEALTH      ","CLAIMS      ","CLAIMS      ","PHARMACY    ","PHARMACY    ","BULK        ","BULK        ","MCRCF       ","MCRCF       ","MCRCP       ","MCRCP       ","MPA         ","MPA         ","MRXC        ","MRXC        ","PPACA       ","PPACA       ","QPC         ","QPC         ","RXSEL       ","RXSEL       ","SPCR        ","SPCR        ","COUNT       ","AMOUNT      ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","          
"        ","                  ","                  ","                  ","          ","               ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","COUNT       ","AMOUNT      ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","            ","          
"1234    ","ABCD5678          ","ABCOEFITEST1      ","                  ","         1","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200074002      ","                  ","         6","           3.20","       2","           3.20","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       4","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200178002      ","                  ","         2","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       1","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200197001      ","                  ","         1","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200204002      ","                  ","         2","           3.20","       2","           3.20","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200204003      ","                  ","         2","           3.20","       2","           3.20","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200232002      ","                  ","         4","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       3","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200300001      ","                  ","         7","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       6","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200345002      ","                  ","         1","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200414001      ","                  ","         9","           3.20","       2","           3.20","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       7","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       
"1234    ","ABCD5678          ","ABC200491003      ","                  ","         1","           1.60","       1","           1.60","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","       0","           0.00","  

所以现在我将它作为一个1000字符串的长字符串读取,然后我想使用Java转换并将它们拆分为分布在多个标题中的列名,并将它们与下面的值相关联。一个输入行将落入尽可能多的目标行。

首先:将文件逐行读入长字符串端口。

将“CurrentlyProcessedFileName”端口添加到源以捕获文件名 计算读取的行数

在逗号上拆分行 - 我该如何实现?在java中猜测表达式或java转换以及下面的整个过程或者我可以使用SP,如何在逗号上拆分行?

   If Current RowNumber = 1 Then    
        vINVC_BGN_DT := field1
        vINVC_END_DT := field2

   If Current RowNumber > 1
      If field1 != $$CARRIER Then
    NAME1 := NAME1 || field1  #Initialize NAME variables to an empty string
    NAME2 := NAME2 || field2
    NAME3 := NAME3 || field3  #repeat for each comma seperated field
      If field1 = $$CARRIER Then
    VALUE1 := field1
    VALUE2 := field2
    VALUE3 := field3          #repeat for each comma seperated field

对于每个源行,输出行数应等于不同Amount_types的数量(不包括空行)

   For i in NAME4.NAMEx loop
       if NAMEi is not spaces or null then generate row
           target.INVC_TYPE = "CLAIM"
           target.FILE_RECEIPT_SK
           target.CARRIER := VALUE1
           target.CNTRCT := VALUE2
           target.PBM_GROUP := VALUE3
           target.INVC_BGN_DT := vINVC_BGN_DT  #From row1
           target.INVC_END_DT := vINVC_END_DT  #From row1
           target.INVC_AMOUNT_TYPE := NAMEi
           target.INVC_AMOUNT := VALUEi
   end i loop..

1 个答案:

答案 0 :(得分:0)

您可以使用规范化程序将一行拆分为多行。在您的情况下,您必须单独处理第一行,接下来的3个标题行和数据行。为此,使用变量在表达式中创建seq no。

您可以在表达式中获取开始日期和结束日期:例如

begin_date:= iif(seq=1, field1, begin_date)

要分隔标题行和数据行,请使用条件为seq>1 && seq<=4seq>4

的路由器

现在,您可以使用规范化程序将行拆分为多行。对于数据行,为carrier,contract,pbm_group,count和amount创建5列,并将count和amount的出现次数设置为total no。或计数或数量列。

您可以类似地为标题列使用另一个规范化程序。最后使用joiner转换加入两个流程。

您还可以使用java转换,在输入行选项卡上,您已经编写了类似的逻辑。要拆分行,可以使用split方法。例如:

String[] fields=row.split(",");

现在,数组fields将包含所有字段作为数组元素。您可以将适当的元素分配给输出端口,并调用Informatica的generateRow()方法来创建目标记录。