您如何忽略 Dataweave 中 CSV 文件的前两行?
How do you ignore the 1st two lines of a CSV file in Dataweave?
我将 Anypoint Studio 6.1 与 Mule 3.8.1 一起使用,在转换消息组件中,我有一个输入 CSV 文件,该文件的第一行是字段名,第二行是该文件的数据类型。我想从第 3 行开始处理记录,但无法将 Reader 配置配置为错过包含数据类型的第二行。
有没有办法让第一行用于字段名,第二行被忽略,第三行以后是被处理的记录?
测试 CSV:
Product,Price
string,decimal(10,2)
phone,99
tv,499
XML流量:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<flow name="csvreaderFlow">
<dw:transform-message metadata:id="08c0a5d4-9d7d-44ad-b72b-bac83ab6b6c1" doc:name="Transform Message">
<dw:input-payload doc:sample="sample_data\list_csv.csv" mimeType="application/csv">
<dw:reader-property name="bodyStartLineNumber" value="2"/>
</dw:input-payload>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> {
products: payload01.Product
})]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
即使我将正文行开始编号增加到 10,它仍然显示第 2 行和 2 条要处理的记录。我认为这会导致错误。
谢谢
在 Dataweave 上 CSV 的输入 reader 配置中,他们有一个设置 "bodyStartLineNumber"(在您的情况下将其设置为“3”)。如果您有任何问题,请告诉我,
以下是 Dataweave 上要遵循的步骤,
1. Right click on the "Payload" label (left panel).
2. Click on the "Reader Configuration" option.
3. GUI opens with multiple options to be set.
4. Configure the "Body Start Line Number"
我将 Anypoint Studio 6.1 与 Mule 3.8.1 一起使用,在转换消息组件中,我有一个输入 CSV 文件,该文件的第一行是字段名,第二行是该文件的数据类型。我想从第 3 行开始处理记录,但无法将 Reader 配置配置为错过包含数据类型的第二行。
有没有办法让第一行用于字段名,第二行被忽略,第三行以后是被处理的记录?
测试 CSV:
Product,Price
string,decimal(10,2)
phone,99
tv,499
XML流量:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<flow name="csvreaderFlow">
<dw:transform-message metadata:id="08c0a5d4-9d7d-44ad-b72b-bac83ab6b6c1" doc:name="Transform Message">
<dw:input-payload doc:sample="sample_data\list_csv.csv" mimeType="application/csv">
<dw:reader-property name="bodyStartLineNumber" value="2"/>
</dw:input-payload>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> {
products: payload01.Product
})]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
即使我将正文行开始编号增加到 10,它仍然显示第 2 行和 2 条要处理的记录。我认为这会导致错误。
谢谢
在 Dataweave 上 CSV 的输入 reader 配置中,他们有一个设置 "bodyStartLineNumber"(在您的情况下将其设置为“3”)。如果您有任何问题,请告诉我,
以下是 Dataweave 上要遵循的步骤,
1. Right click on the "Payload" label (left panel).
2. Click on the "Reader Configuration" option.
3. GUI opens with multiple options to be set.
4. Configure the "Body Start Line Number"