繁体   English   中英

如何在Mule Dataweave中读取带有空行和多余标题的CSV文件

[英]How to read CSV files with blank lines and extra headers in Mule dataweave

我的CSV包含空白行和下面的多余牧民,如下所示:

**blank line**
Available_Date_Feed
productID,availableDate
148305801,2015-08-07T00:00:00.000+0000
160611862,2015-07-29T00:00:00.000+0000
160611715,2015-07-29T00:00:00.000+0000
160342798,2015-07-29T00:00:00.000+0000

我想读取productID和availableDate的值。 如果我们使用dataweave进行常规转换,它将返回空值

这是我在dataweave中编写的代码:

%dw 1.0
%input in0 application/csv headers=true
%output application/java
---
payload  map  {
    productID:$.productID,
    availableDate:$.availableDate
}

返回有效载荷为:

[{productID=null, availableDate=null}, {productID=null, availableDate=null}, {productID=null, availableDate=null}, {productID=null, availableDate=null}]

有什么建议吗? 我们可以为此使用Groovy / MEL / regex表达式吗? 如何使用行在Dataweave中忽略?

我们可以使用groovy / regex跳过前2行吗?

我面临以下常规问题的性能问题。 ule子花费太多时间来转换甚至1 MB的文件。 还有其他解决方案吗?

我已经使用Groovy跳过了前2行。 该脚本直接获取逗号分隔的值

 csvContent = message.payload
def filteredContent = new StringBuffer()
regexPattern = /(\S*),(\S*)/
finder = csvContent =~ regexPattern

(0..<finder.count).each {
    //println "Iteration: ${it+1}:"
    filteredContent.append(finder[it][0])
    filteredContent.append('\n')

}

return filteredContent.toString()

在Groovy之前使用object to string

我知道已经晚了。 如果仍在等待答案,请尝试此操作。 仅在dataweave中完成。

%dw 1.0
%output application/csv header=false
---
payload[3..-1] map {
    productId:$[0],
    date: $[1]
}

希望能帮助到你。

此链接可能有帮助

https://developer.mulesoft.com/docs/dataweave

并阅读以上文档中的以下代码片段以跳过空值

%output application / xml skipNullOn =“无处不在”

暂无
暂无

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

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