获得水壶pentaho流量的值

时间:2017-04-27 17:57:48

标签: pentaho kettle pentaho-spoon pentaho-data-integration

我正在使用pentaho数据集成,Spoon。

简短描述:我想获得从流中读取的每一行的流量值出现的次数。

长描述:我正在对事实表进行转换,当我读取csv文件的数据时,我有一个客户在特定时间在某架飞机上旅行过。我想添加一个列,可用座位,无论何时看到客户在混凝土飞机上行驶的数据,请查看上一个流程中该飞机可用座位的数量并减去1。

实施例

最初,1号航班有160个座位,2号航班有320个座位。

CSV

Flight | Client

1      |   1

2      |   2

1      |   3

2      |   4

我可以添加一个列,其值是可用座位的总数。

Flight | Customer | Available seats

1      |     1    |        160

2      |     2    |        320

1      |     3    |        160

2      |     4    |        320

但之后我不知道如何获得每次阅读流量时某个航班可用座位的最小值。

我想要的最终输出......

Flight | Customer | Available seats

1      |     1    |        159

2      |     2    |        319

1      |     3    |        158

2      |     4    |        318

非常感谢您在阅读我的问题时的时间。

1 个答案:

答案 0 :(得分:2)

您可以使用Add value fields changing sequence("转换"步骤组)步骤为每个航班生成一个计数器。该步骤将要求输入按Flight字段排序。您需要在此步骤中指定Flight字段,以便在新的航班组开始后重置计数器。

然后,您可以从Available seats字段中减去计数器,以使用Calculator / JavaScript / Java公式或任何其他步骤获取当前值。

enter image description here

以下是一个示例,您可以将其复制并粘贴到Spoon画布上:

<?xml version="1.0" encoding="UTF-8"?>
<transformation-steps>
<steps>
  <step>
    <name>Add value fields changing sequence</name>
    <type>FieldsChangeSequence</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
      <start>1</start>
      <increment>1</increment>
      <resultfieldName>counter</resultfieldName>
    <fields>
      <field>
        <name>Flight</name>
        </field>
      </fields>
    <cluster_schema/>
    <remotesteps>
      <input>
      </input>
      <output>
      </output>
    </remotesteps>
    <GUI>
      <xloc>352</xloc>
      <yloc>96</yloc>
      <draw>Y</draw>
    </GUI>
    </step>

  <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>Flight</name>
        <type>Integer</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
      <field>
        <name>Customer</name>
        <type>Integer</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
      <field>
        <name>Total available seats</name>
        <type>Integer</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
    </fields>
    <data>
      <line> <item>1</item><item>1</item><item>160</item> </line>
      <line> <item>2</item><item>2</item><item>320</item> </line>
      <line> <item>1</item><item>3</item><item>160</item> </line>
      <line> <item>2</item><item>4</item><item>320</item> </line>
    </data>
    <cluster_schema/>
    <remotesteps>
      <input>
      </input>
      <output>
      </output>
    </remotesteps>
    <GUI>
      <xloc>80</xloc>
      <yloc>96</yloc>
      <draw>Y</draw>
    </GUI>
    </step>

  <step>
    <name>Sort rows &#x28;by flight&#x29;</name>
    <type>SortRows</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
      <directory>&#x25;&#x25;java.io.tmpdir&#x25;&#x25;</directory>
      <prefix>out</prefix>
      <sort_size>1000000</sort_size>
      <free_memory/>
      <compress>N</compress>
      <compress_variable/>
      <unique_rows>N</unique_rows>
    <fields>
      <field>
        <name>Flight</name>
        <ascending>Y</ascending>
        <case_sensitive>N</case_sensitive>
        <collator_enabled>N</collator_enabled>
        <collator_strength>0</collator_strength>
        <presorted>N</presorted>
      </field>
    </fields>
    <cluster_schema/>
    <remotesteps>
      <input>
      </input>
      <output>
      </output>
    </remotesteps>
    <GUI>
      <xloc>192</xloc>
      <yloc>96</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>Available seats</field_name>
      <calc_type>SUBTRACT</calc_type>
      <field_a>Total available seats</field_a>
      <field_b>counter</field_b>
      <field_c/>
      <value_type>Integer</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>496</xloc>
      <yloc>96</yloc>
      <draw>Y</draw>
    </GUI>
    </step>

</steps>
<order>
    <hop>
      <from>Add value fields changing sequence</from>
      <to>Calculator</to>
      <enabled>Y</enabled>
    </hop>

    <hop>
      <from>Data Grid</from>
      <to>Sort rows &#x28;by flight&#x29;</to>
      <enabled>Y</enabled>
    </hop>

    <hop>
      <from>Sort rows &#x28;by flight&#x29;</from>
      <to>Add value fields changing sequence</to>
      <enabled>Y</enabled>
    </hop>

</order>
<notepads>
</notepads>
<step_error_handling>
</step_error_handling>
</transformation-steps>
相关问题