如何在 PDI 中用双引号将值括起来?
How can I enclose values with double quotes in PDI?
我想创建一个 csv 文件作为输出,但流中有一些 NULL。我这样设置文本文件输出配置:
内容标签:
separator --> ,
enclosure: --> "
force the enclosure around fields? --> yes
字段选项卡:
Null --> ""
我使用的是 Kettle 6.0 版本,使用上面的配置,如果我没有在字段选项卡中为 Null 设置默认值 "",Null 值将被替换为 """""" 字符串, Null 值将不会被输出 csv 文件中的双引号括起来。如何生成具有正确输出的 CSV 文件?
提前致谢。
这是您的解决方案:
- 不要在文本文件输出中强制包含附件
- 从字段中删除“” --> Null
- 用我的例子。它会做你想做的事:
<?xml version="1.0" encoding="UTF-8"?>
<transformation-steps>
<steps>
<step>
<name>Data Grid</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>Something</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<data>
<line> <item>asda</item> </line>
<line> <item/> </line>
<line> <item>sadasd</item> </line>
<line> <item/> </line>
<line> <item>asdads</item> </line>
</data>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>159</xloc>
<yloc>125</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>Text file output</name>
<type>TextFileOutput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<separator>;</separator>
<enclosure/>
<enclosure_forced>N</enclosure_forced>
<enclosure_fix_disabled>N</enclosure_fix_disabled>
<header>Y</header>
<footer>N</footer>
<format>DOS</format>
<compression>None</compression>
<encoding/>
<endedLine/>
<fileNameInField>N</fileNameInField>
<fileNameField/>
<create_parent_folder>Y</create_parent_folder>
<file>
<name>${Internal.Transformation.Filename.Directory}\file.txt</name>
<is_command>N</is_command>
<servlet_output>N</servlet_output>
<do_not_open_new_file_init>N</do_not_open_new_file_init>
<extention>csv</extention>
<append>N</append>
<split>N</split>
<haspartno>N</haspartno>
<add_date>N</add_date>
<add_time>N</add_time>
<SpecifyFormat>N</SpecifyFormat>
<date_time_format/>
<add_to_result_filenames>Y</add_to_result_filenames>
<pad>N</pad>
<fast_dump>N</fast_dump>
<splitevery>0</splitevery>
</file>
<fields>
<field>
<name>quotes_bounded_something</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<nullif/>
<trim_type>none</trim_type>
<length>-1</length>
<precision>-1</precision>
</field>
</fields>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>547</xloc>
<yloc>126</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>Calculator</name>
<type>Calculator</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<calculation><field_name>quotes</field_name>
<calc_type>CONSTANT</calc_type>
<field_a>"</field_a>
<field_b/>
<field_c/>
<value_type>String</value_type>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<remove>N</remove>
<conversion_mask/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
</calculation>
<calculation><field_name>prefixed_field</field_name>
<calc_type>ADD</calc_type>
<field_a>quotes</field_a>
<field_b>Something</field_b>
<field_c/>
<value_type>String</value_type>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<remove>N</remove>
<conversion_mask/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
</calculation>
<calculation><field_name>quotes_bounded_something</field_name>
<calc_type>ADD</calc_type>
<field_a>prefixed_field</field_a>
<field_b>quotes</field_b>
<field_c/>
<value_type>String</value_type>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<remove>N</remove>
<conversion_mask/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
</calculation>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>279</xloc>
<yloc>125</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>If field value is null</name>
<type>IfNull</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<replaceAllByValue/>
<replaceAllMask/>
<selectFields>Y</selectFields>
<selectValuesType>N</selectValuesType>
<setEmptyStringAll>N</setEmptyStringAll>
<valuetypes>
</valuetypes>
<fields>
<field>
<name>quotes_bounded_something</name>
<value>""</value>
<mask/>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>399</xloc>
<yloc>125</yloc>
<draw>Y</draw>
</GUI>
</step>
</steps>
<order>
<hop> <from>Data Grid</from><to>Calculator</to><enabled>Y</enabled> </hop>
<hop> <from>Calculator</from><to>If field value is null</to><enabled>Y</enabled> </hop>
<hop> <from>If field value is null</from><to>Text file output</to><enabled>Y</enabled> </hop>
</order>
<notepads>
</notepads>
<step_error_handling>
</step_error_handling>
</transformation-steps>
我想创建一个 csv 文件作为输出,但流中有一些 NULL。我这样设置文本文件输出配置:
内容标签:
separator --> ,
enclosure: --> "
force the enclosure around fields? --> yes
字段选项卡:
Null --> ""
我使用的是 Kettle 6.0 版本,使用上面的配置,如果我没有在字段选项卡中为 Null 设置默认值 "",Null 值将被替换为 """""" 字符串, Null 值将不会被输出 csv 文件中的双引号括起来。如何生成具有正确输出的 CSV 文件?
提前致谢。
这是您的解决方案:
- 不要在文本文件输出中强制包含附件
- 从字段中删除“” --> Null
- 用我的例子。它会做你想做的事:
<?xml version="1.0" encoding="UTF-8"?>
<transformation-steps>
<steps>
<step>
<name>Data Grid</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>Something</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<data>
<line> <item>asda</item> </line>
<line> <item/> </line>
<line> <item>sadasd</item> </line>
<line> <item/> </line>
<line> <item>asdads</item> </line>
</data>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>159</xloc>
<yloc>125</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>Text file output</name>
<type>TextFileOutput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<separator>;</separator>
<enclosure/>
<enclosure_forced>N</enclosure_forced>
<enclosure_fix_disabled>N</enclosure_fix_disabled>
<header>Y</header>
<footer>N</footer>
<format>DOS</format>
<compression>None</compression>
<encoding/>
<endedLine/>
<fileNameInField>N</fileNameInField>
<fileNameField/>
<create_parent_folder>Y</create_parent_folder>
<file>
<name>${Internal.Transformation.Filename.Directory}\file.txt</name>
<is_command>N</is_command>
<servlet_output>N</servlet_output>
<do_not_open_new_file_init>N</do_not_open_new_file_init>
<extention>csv</extention>
<append>N</append>
<split>N</split>
<haspartno>N</haspartno>
<add_date>N</add_date>
<add_time>N</add_time>
<SpecifyFormat>N</SpecifyFormat>
<date_time_format/>
<add_to_result_filenames>Y</add_to_result_filenames>
<pad>N</pad>
<fast_dump>N</fast_dump>
<splitevery>0</splitevery>
</file>
<fields>
<field>
<name>quotes_bounded_something</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<nullif/>
<trim_type>none</trim_type>
<length>-1</length>
<precision>-1</precision>
</field>
</fields>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>547</xloc>
<yloc>126</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>Calculator</name>
<type>Calculator</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<calculation><field_name>quotes</field_name>
<calc_type>CONSTANT</calc_type>
<field_a>"</field_a>
<field_b/>
<field_c/>
<value_type>String</value_type>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<remove>N</remove>
<conversion_mask/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
</calculation>
<calculation><field_name>prefixed_field</field_name>
<calc_type>ADD</calc_type>
<field_a>quotes</field_a>
<field_b>Something</field_b>
<field_c/>
<value_type>String</value_type>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<remove>N</remove>
<conversion_mask/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
</calculation>
<calculation><field_name>quotes_bounded_something</field_name>
<calc_type>ADD</calc_type>
<field_a>prefixed_field</field_a>
<field_b>quotes</field_b>
<field_c/>
<value_type>String</value_type>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<remove>N</remove>
<conversion_mask/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
</calculation>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>279</xloc>
<yloc>125</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>If field value is null</name>
<type>IfNull</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<replaceAllByValue/>
<replaceAllMask/>
<selectFields>Y</selectFields>
<selectValuesType>N</selectValuesType>
<setEmptyStringAll>N</setEmptyStringAll>
<valuetypes>
</valuetypes>
<fields>
<field>
<name>quotes_bounded_something</name>
<value>""</value>
<mask/>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>399</xloc>
<yloc>125</yloc>
<draw>Y</draw>
</GUI>
</step>
</steps>
<order>
<hop> <from>Data Grid</from><to>Calculator</to><enabled>Y</enabled> </hop>
<hop> <from>Calculator</from><to>If field value is null</to><enabled>Y</enabled> </hop>
<hop> <from>If field value is null</from><to>Text file output</to><enabled>Y</enabled> </hop>
</order>
<notepads>
</notepads>
<step_error_handling>
</step_error_handling>
</transformation-steps>