首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >利用骡子中的数据编织实现CSV到CSV的转换

利用骡子中的数据编织实现CSV到CSV的转换
EN

Stack Overflow用户
提问于 2016-05-12 10:43:33
回答 2查看 1.2K关注 0票数 0

我必须对来自excel.Input Excel的输入数据进行一级规范化。

现在输出应该是likeOutput文件。我尝试将MEL(将方法定义为全局配置)结合起来使用Dataweave。在数据编织中,我试图调用上面定义为全局配置的方法。此方法无法工作,因为生成的文件是空的。有人能在这个方法中提出更好的方法或问题吗?下面是代码@Manik:

代码语言:javascript
运行
复制
 <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns:file="http://www.mulesoft.org/schema/mule/file" 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.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
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">

  <configuration doc:name="Configuration">
     <expression-language>
         <global-functions>
            def getCompanyName(name){
                 if (flowVars.companyList contains name) {
                    return "";
                 }  else {
                    flowVars.companyList.add(name);
                    return name;
                 }
            }
          </global-functions>
     </expression-language>
 </configuration>


  <file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" readFromDirectory="C:\Users\Desktop\Mule-Doc"/>
    <file:connector name="File1" autoDelete="true" outputAppend="true" streaming="true" validateConnections="true" doc:name="File"/>


    <flow name="csvnormalizationFlow">
         <file:inbound-endpoint path="C:\Users\Desktop\Mule-Doc" connector-ref="File" responseTimeout="10000" doc:name="File"/>
        <set-variable value="#[[]]" variableName="companyList" doc:name="Variable" mimeType="application/csv"/>
        <logger message="The payload is-----------------------#[payload]" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0

%output application/csv header=true
---
payload map {
    CompanyName: getCompanyName($.Company),
    location:$.Location
}]]></dw:set-payload>
        </dw:transform-message>

        <file:outbound-endpoint path="C:\Users\Desktop\Output" outputPattern="test.csv" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>
EN

Stack Overflow用户

发布于 2016-11-22 07:35:01

您可以添加一个空处理程序,取消您的数据编织表达式,并检查是否是有效负载没有写任何东西。下面是一个空句柄的例子。

代码语言:javascript
运行
复制
 (payload.listAllFlightsResponse.*return default [])
票数 -1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37184590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档