简体   繁体   English

使用Mule Dataweave导入CSV?

[英]Using Mule Dataweave to import CSV?

My solution involves importing various CSV files and converting them to Java map structures, and I've been using a DataMapper transformer for this to great success -- that is, until I hit the test server. 我的解决方案涉及导入各种CSV文件并将它们转换为Java地图结构,我一直在使用DataMapper转换器取得巨大成功 - 也就是说,直到我点击测试服务器。 Although we have an Enterprise installation, we don't have the now-no-longer-built-it DataMapper plugin, so I'm looking into rewriting my importers using the Transform Message component (what Mule Soft also refer to as "dataweave"). 虽然我们有一个Enterprise安装,但是我们没有现在没有更长时间构建的DataMapper插件,所以我正在考虑使用Transform Message组件重写我的导入器(Mule Soft也称为“dataweave”) )。

Alas! 唉! There are plenty of examples and tutorials on using the DataMapper transformer (to read CSV files), and there are plenty of examples and tutorials on using the Transform Message component (to write CSV files), but I cannot for the life of me find any description of how to read a CSV file with a Transform Message component. 有很多关于使用DataMapper转换器(读取CSV文件)的示例和教程,有很多关于使用转换消息组件(写入CSV文件)的示例和教程,但我不能为我的生活找到任何有关如何使用转换消息组件读取 CSV文件的说明。 It seems that all examples deal with xml input. 似乎所有示例都处理xml输入。

Help! 救命!

How should I configure the "Context" (input) pane of the Transform Message component, and how should the transformation look to output a Java map structure? 我应该如何配置转换消息组件的“上下文”(输入)窗格,以及转换如何显示输出Java映射结构? For argument's sake, lets just say my CSV file format is a simple "ID,NAME,NUMBER" and does include a header row. 为了论证的缘故,我们只想说我的CSV文件格式是一个简单的“ID,NAME,NUMBER”,并且包含一个标题行。

Naturally, we are in a great hurry to get this issue resolved, so any help would be much appreciated. 当然,我们非常急于解决这个问题,所以任何帮助都会非常感激。

If you only want to output a java array of maps from a CSV input, you just need to do this: 如果您只想从CSV输入中输出java数组的地图,则只需执行以下操作:

%dw 1.0
%output application/java
---
payload

Also make sure the mime-type of your payload is set to application/csv. 还要确保有效负载的mime类型设置为application / csv。

If it's not, you can alternatively put <dw:input-payload mimeType="application/csv"/> inside your transform-message 如果不是,您可以在转换消息中添加<dw:input-payload mimeType="application/csv"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM