Hitachi Vantara Pentaho Community Forums
Results 1 to 11 of 11

Thread: How to rename a field using javascript?

  1. #1
    Join Date
    Jul 2007
    Posts
    247

    Default How to rename a field using javascript?

    Hi everybody,

    I have two input fields in a row, for example FIELD1 and VALUE1. FIELD1 contains the field name of VALUE1, so I would like to rename VALUE1 according to the content of FIELD1.

    I thought of JavaScript to do this but I can't really find a proper solution for it.

    Any ideas/guideline anyone?


    Thx in advance,
    Ben

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    In 2.5 you could via a setter function on Value, in 3.0 you can get at metadata but I don't know whether it's actually intended to be used to change fieldnames (probably not): object rowMeta is defined in javascript which is the interface to the row meta-data.

    However in your case it doesn't make sense... all rows flowing over the same hop have to have the same structure, fields of the same name/type/... so you can't just rename fields based on row contents. Unless they all have the same value, ...

    Regards,
    Sven
    Last edited by sboden; 09-13-2007 at 12:15 PM.

  3. #3
    Join Date
    Jul 2007
    Posts
    247

    Default

    Thx for reply, I forgot to mention that there's only 1 row

    What do you exactly mean by "via setter function", do I have to use a java method or is an implemented function in the javascript step?

    Could you provide a short example?


    Thx,
    Ben

  4. #4
    Join Date
    May 2006
    Posts
    4,882

    Default

    In 2.5 when one of your input fields was named "test" you could do a "test.setName("a");" and test would become a (at the output side)... but it's not going to happen in v3.

    Regards,
    Sven

  5. #5
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    Even in 2.x you get weird results. For example, the name change is not picked up at design time and is only performed at run-time.

    Anyway, I don't see the use case for allowing it in 3.0.
    You would think that there are already hundreds of ways to change the name of a field. :-)

    Matt

  6. #6
    Join Date
    Mar 2007
    Posts
    216

    Smile

    Hi,

    I have exactly the same problem : attribute names and attribute values defined in the same row, e.g.
    item_id attribute_name attribute_value
    01 colour black
    and I need to fill a table which output would be like
    item_id colour
    01 black
    How can I manage this in earlier versions of Kettle ?

    a+, =)
    -=Clément=-

  7. #7
    Join Date
    May 2006
    Posts
    4,882

    Default

    You can use setName() on the value in 2.5 ... but it won't get you far: all of the rows have to have the same fields (same names, order, type).

    Regards,
    Sven

  8. #8
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    Looks like this is a job for the "Denormaliser" step.
    Key-value pair lookup should be fairly straightforward. There is no need for JavaScript to do this.

    Matt

  9. #9
    Join Date
    Mar 2007
    Posts
    216

    Smile

    Hi,

    Quote Originally Posted by sboden View Post
    You can use setName() on the value in 2.5 ... but it won't get you far: all of the rows have to have the same fields (same names, order, type).(...)
    Here is how I do, I think in all these case the rows have the same fields. :
    My input table structure :
    Code:
    Id|Name1|Name2|Value1|Value2
    01|colour|size|black|XL
    A first normalisation output : Name1|Name2 normalized in TypeforName|Name
    Code:
    Id|TypeForName|Name|Value1|Value2
    01|1|colour|black|XL
    01|2|size|black|XL
    A second normalisation output : value1 and value2 normalized in TypeForValue|value
    Code:
    Id|TypeForName|Name|TypeForValue|Value
    01|1|colour|1|black
    01|1|colour|2|XL
    01|2|size|1|black
    01|2|size|2|XL
    Then a filter TypeForName==TypeForValue output :
    Code:
    Id|TypeForName|Name|TypeForValue|Value
    01|1|colour|1|black
    01|2|size|2|XL
    Now a denormalizer step description :
    Code:
    Key Field = TypeForName
    Grouping fields : Id
    #|name of the target field|value for target field|key value|type
    1|colour|Value|1|String
    2|size|Value|2|String
    And it's output :
    Code:
    Id|colour|size
    01|black|XL
    What I would have need is a "name of the field which indicates the name of the target field" instead of the "name of the target field",
    like the "value for target field" does : reading the content of a field.
    Follows a picture from a Kettle's denormaliser step sample which shows what I mean in another way :

    Is there any way to put a field name (maybe using a variable?) instead of the string value ?

    a+, =)
    -=Clément=-

  10. #10
    Join Date
    Mar 2007
    Posts
    216

    Default

    Hi,

    Quote Originally Posted by MattCasters View Post
    Looks like this is a job for the "Denormaliser" step.
    Key-value pair lookup should be fairly straightforward. There is no need for JavaScript to do this.

    Matt
    Seems that we have cross-replied.

    a+, =)
    -=Clément=-

  11. #11
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    > Is there any way to put a field name (maybe using a variable?) instead of the string value ?

    I don't think so. We added variable support for the key-value (valeur clé) last.
    I suggest you add a feature request for it and we'll look at it in more detail.
    (post 3.0 / 2.5.2)

    All the best,

    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.