Hitachi Vantara Pentaho Community Forums
Results 1 to 9 of 9

Thread: Strings cut issue

  1. #1
    Join Date
    Nov 2017
    Posts
    11

    Default Strings cut issue

    Hi,

    I'm new to PDI and I'm having an issue using Strings cut.

    I'm parsing a date out of a file name, and the file names may be of different lengths. So for example myfilename20171128.pdf or someotherfilename20171128.pdf. I'm trying to grab the "20171128" part in these examples.

    If I use Strings cut with hard-coded values for Cut from and Cut to, works fine.

    I've defined some fields in my stream that determine the start and end point of the substring, based on the length of the file name. I've confirmed that these field values are in the stream and are getting calculated correctly. However, when I try to use these fields in Cut from and Cut to, Strings cut returns the entire file name in the output field.

    So, this:
    Name:  Capture.jpg
Views: 1181
Size:  20.3 KB

    Puts the value of short_filename into DATE.

    What am I not getting?

    Thanks,

    Burnie

  2. #2
    Join Date
    Aug 2011
    Posts
    236

    Default

    Hi Burnie,

    Are you defining and using the ${} variables in the same transformation? If so, you can't do this in Pentaho. You need a separate transformation to set the variable values and then you can use them in your current transformation.

    HTH.
    PDI 8.0.0
    MySQL - 5.6.27
    Redshift - 1.0.1485
    PostgreSQL 8.0.2
    OS - Ubuntu 10.04.2

  3. #3
    Join Date
    Nov 2017
    Posts
    11

    Default

    Yes, I was defining and using the variables in the same transformation.

    I've created a new transformation to create the variables I need. Do need to take any steps to make those variables available to subsequent transformations?

  4. #4
    Join Date
    Aug 2011
    Posts
    236

    Default

    Yes - I always use a Get Variables step to make sure they are available in the current transformation.
    PDI 8.0.0
    MySQL - 5.6.27
    Redshift - 1.0.1485
    PostgreSQL 8.0.2
    OS - Ubuntu 10.04.2

  5. #5
    Join Date
    Nov 2017
    Posts
    11

    Default

    OK, I think I'm getting closer!

    So I have two transformations:

    Trans A uses Get File Names and calculates the values I need to use in Strings cut. Those variables are CutFrom and CutTo.

    Trans B needs CutFrom and CutTo, as well as short_filename (from Get File Names) from Trans A.

    I have the a Get Variables in Trans B:
    Name:  Capture.jpg
Views: 1048
Size:  14.0 KB

    I dump the contents of the stream to a Text file output for testing purposes. All three fields (cutfrom, cutto, shortfilename) are all empty:
    Name:  Capture2.PNG
Views: 1009
Size:  2.7 KB

    Do I need to do something in particular in Trans A to make this work?

  6. #6
    Join Date
    Aug 2011
    Posts
    236

    Default

    Hi,

    I think that since you are reading all files from a directory, you should use the Copy rows to results scenario.

    You would three fields in your result rows - filename, cutfrom, cutto.

    The following gives you an example on how to use this and pass the results to successive transformations.

    https://anotherreeshu.wordpress.com/...a-integration/

    Give that a go.
    PDI 8.0.0
    MySQL - 5.6.27
    Redshift - 1.0.1485
    PostgreSQL 8.0.2
    OS - Ubuntu 10.04.2

  7. #7
    Join Date
    Jun 2012
    Posts
    5,534

    Default

    Wouldn't it be easier to extract the date via a regular expression?


    Name:  230549.png
Views: 1009
Size:  28.3 KB
    So long, and thanks for all the fish.

  8. #8
    Join Date
    Nov 2017
    Posts
    11

    Default

    Why, yes, yes it would. I didn't know Replace in String was a thing (there are lots of Steps)! That works perfectly.

    Thank you!

  9. #9
    Join Date
    Nov 2013
    Posts
    382

    Default

    Or even a Formula step ...

    mid([short_filename];find([short_filename];".")-8;8)

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.