如何在PDI中用双引号括起值?

时间:2016-10-19 02:24:23

标签: export-to-csv kettle pdi pentaho-spoon

我想创建一个csv文件作为输出,但是流中有一些NULL。我设置文本文件输出配置如下:

内容标签:

    separator --> ,

    enclosure: --> "

    force the enclosure around fields? --> yes

字段标签:

    Null --> ""

我使用Kettle 6.0版本,使用上面的配置,Null值被"""""""字符串,如果我没有设置默认值""对于字段选项卡中的Null,Null值不会被输出csv文件中的双引号括起来。如何生成具有正确输出的CSV文件?

提前致谢。

1 个答案:

答案 0 :(得分:0)

这是你的解决方案:

  1. 请勿在文本文件输出
  2. 中强制使用机箱
  3. 从字段中移除“” - >空
  4. 使用我的例子。它会做你想要的:
  5. <?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>&#x3b;</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>&#x24;&#x7b;Internal.Transformation.Filename.Directory&#x7d;&#x5c;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>&#x22;</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>&#x22;&#x22;</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>