How to get source file's name into a transformer?

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
mmartin
Participant
Posts: 16
Joined: Mon Dec 18, 2006 3:16 am

How to get source file's name into a transformer?

Post by mmartin »

Hi,
I have a sequential file in source, which name is like FILENAME_YYYYMMDD.
I want to get the "YYYYMMDD" part of the filename in order to load it in a table.
Do you have any idea please?

Thanks in advance.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Been discussed a number of times, here is one example.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Do it at the OS level. Do a

Code: Select all

ls <dir path>| grep "FILENAME" | awk -F"\_" '{print $2}' > result.txt
Now you have that name in a file. Read it in your job and load it in the table. You can run this command in the before job subroutine 'ExecSH'
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Easiest way to do this is on initialization of a Stage Variable in a Transformer. Write a DS Function to do a CALL DSExecute and run the command to get the filename and format the results. This will only be done once when the stage starts. Set the derivation of the stage variable to itself (FRED = FRED). Now just use the stage variable where desired.


:wink:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

kcbland wrote:Set the derivation of the stage variable to itself (FRED = FRED).
Actually, just leave it blank. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
trobinson
Participant
Posts: 208
Joined: Thu Apr 11, 2002 6:02 am
Location: Saint Louis
Contact:

Post by trobinson »

I get the impression Mr. Bland is referring to a Server job. Seems like overkill to get the filename in a EE job. Why not add the property File Name Column in the Sequential stage?
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

trobinson wrote:I get the impression Mr. Bland is referring to a Server job.
Did I give a Server answer to a PX question again? :oops:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Doh! :lol:
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

You know, you just sit and read thru about 20 Server posts, then a PX one comes thru and you don't mentally switch gears. It's not like I'm switching between here and other work at the same time :cry:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

PX Sequential stage can put the name of the file(s) into a column you specify. You'll have to trim off the unwanted bits to keep just the date portion and then cast it into a properly typed column.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
mmartin
Participant
Posts: 16
Joined: Mon Dec 18, 2006 3:16 am

Post by mmartin »

I tried to use File Name Column option in the sequential stage with a Read Method set to File Pattern and using a wildcard for my filename as FILENAME* (where my real file name is still FILENAME_YYYYMMDD).

Then I get this result in the output column "FILENAME*". I wonder why it returns me the wildcard, because I want to catch the date instead of the wildcard!!!!

Thank you all.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Did you read the post I linked to? Did you try everything noted there, including setting APT_IMPORT_PATTERN_USES_FILESET to TRUE? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
mmartin
Participant
Posts: 16
Joined: Mon Dec 18, 2006 3:16 am

Post by mmartin »

chulett wrote:Did you read the post I linked to? Did you try everything noted there, including setting APT_IMPORT_PATTERN_USES_FILESET to TRUE? :? ...
You're right, it works fine!!!!

Thank you very much.
Post Reply