如何打印记录值,而不重复基于特定条件的CSV格式的dataweave中的某些字段 [英] How to print record values without repeating certain fields in dataweave in CSV format based on specific conditions

查看:166
本文介绍了如何打印记录值,而不重复基于特定条件的CSV格式的dataweave中的某些字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在CSV中考虑以下输入示例

Please consider the following input sample in CSV

Company,FirstName,LastName,Email
Rate,Manule,Reaya,Reaya@egetmetus.org
Rate,sholy,Bonvgy,Bonvage@mollis.org

输出应如下所示:

Company,FirstName,LastName,Email
Rate,Manule,Reaya,Reaya@egetmetus.org
,sholy,Bonvgy,Bonvage@mollis.org

如果公司名称在输入中重复不同的记录,则在输出CSV中应为null。

The condition would be : if the company name repeats for different records in the input, it should be null in output CSV.

请让我知道如果这可以在Dataweave组件中处理Mule

Please let me know if this can be handled in Dataweave component in Mule

以下是更新的代码

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">

    <configuration doc:name="Configuration">
     <expression-language>
         <global-functions>
            def getCompanyName(Company){
                 if (flowVars.companyList contains Company) {
                    return "";
                 }  else {
                    flowVars.companyList.add(Company);
                    return Company;
                 }
            }
          </global-functions>
     </expression-language>
 </configuration>
    <file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
    <file:connector name="File1" autoDelete="true" outputAppend="true" streaming="true" validateConnections="true" doc:name="File"/>
    <flow name="csvtocsvrecordemptyFlow">
        <file:inbound-endpoint path="src\test\resources\input" connector-ref="File" responseTimeout="10000" doc:name="File"/>
        <set-variable variableName="companyList" value="[[]]" doc:name="Variable"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/csv header=true
---
payload map {
    CompanyName: getCompanyName($.Company),
    name:$.FirstName
}]]></dw:set-payload>
        </dw:transform-message>

        <file:outbound-endpoint path="src\test\resources\output" outputPattern="test.csv" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>


推荐答案

@Akil Karthik:当我尝试解决方案时仍然显示coerce二进制数组错误。我已经在变量声明中提供了MIME类型为application / csv。

@Akil Karthik : When I am trying the solution it is still showing the coerce binary to array error. I have already provided the MIME type as application/csv in the variable declaration.

这篇关于如何打印记录值,而不重复基于特定条件的CSV格式的dataweave中的某些字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆