stackster
stackster

Reputation: 29

pig script to replace \ with - in date function

I am trying to write a pig script which has date in the format 04/15/2016. I want to convert it to 04-15-2016. I am getting when I do the below:

x=REPLACE(date,'\','-');
dump x;

I want to know the correct way of writing this.

Thanks, stacky

Upvotes: 0

Views: 316

Answers (2)

nobody
nobody

Reputation: 11080

Cast the field as chararray in REPLACE.

REPLACE(string, 'oldChar', 'newChar');

X = FOREACH A GENERATE REPLACE((chararray)date,'/','-');
dump X;

Upvotes: 0

prasmgr
prasmgr

Reputation: 123

This should work.

X = FOREACH A GENERATE REPLACE(date,'/','-');
DUMP X;

Upvotes: 0

Related Questions