Question

Can pig scripts use double quotes? If not how to escape a single quote? I'm trying to parse a date time and I'm geting errors

Unexpected character '"'

And here is the script

logOutput = FOREACH parsedLog GENERATE uid, ToDate(timestamp,"YYYY-MM-DD'T'hh:mm ss:'00'") as theTime:datetime
Was it helpful?

Solution 2

Have a try escaping them using \ and using single quotes.

logOutput = FOREACH parsedLog GENERATE uid, ToDate(timestamp,'YYYY-MM-DD\'T\'hh:mm ss:00') as theTime:datetime

Not sure what you mean with '00'.

OTHER TIPS

You can escape a single quote using \\ (double backslash).

%declare CURRENT_TIME_ISO_FORMAT ToString($CURRENT_TIME,'yyyy-MM-dd\\'T\\'HH:mm:ss.SSSZ')

Just be aware that when you are using the escaping, you should not reuse the created String on another place of the script, but to everything on single call. For example, let's say you want to send the String to the ISOToDay function, this script will fail:

%declare CURRENT_TIME_ISO_FORMAT ToString($CURRENT_TIME,'yyyy-MM-dd\\'T\\'HH:mm:ss.SSSZ')
%declare TODAY_BEGINNING_OF_DAY_ISO_FORMAT ISOToDay($CURRENT_TIME_ISO_FORMAT)

Instead, you should do:

%declare TODAY_BEGINNING_OF_DAY_ISO_FORMAT ISOToDay(ToString($CURRENT_TIME,'yyyy-MM-dd\\'T\\'HH:mm:ss.SSSZ'))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top