10

How can I create a parameter with today date of the format :

yyyy-mm-dd

in oozie. I am passing this variable to hive script which is adding the partition for that date, I found the function to create timestamp using :

<param>DATE=${wf:timestamp()}</param>

which should return output in the form :

(YYYY-MM-DDThh:mm:ss.sZ). I.e.: 1997-07-16T19:20:30.45Z

but I am getting error :

No function is mapped to the name "wf:timestamp"

Also I only want YYYY-MM-DD from the timestamp and there is no substring function also which can give me first 10 chars of the string.

bigData
  • 1,318
  • 4
  • 16
  • 27

2 Answers2

8

For the basic EL function , you don't need to add wf so it should look like this

<param>DATE=${timestamp()}</param>

If you are using coordinator , than use can simple add new param to wf. it should look something like this

<action>
        <workflow>
            <app-path>${appPath}</app-path>
            <configuration>
                        <property>
                            <name>reportDate</name>
                            <value>${coord:formatTime(coord:dateOffset(coord:nominalTime(), -1,
                                'DAY'), "yyyy-MM-dd")}
                            </value>
                        </property>
              </configuration>
        </workflow>
</action>
Mzf
  • 5,210
  • 2
  • 24
  • 37
  • i tried from coordinator : ` DATE ${coord:formatTime(coord:dateOffset(coord:nominalTime(), -1, 'DAY'), "yyyy-MM-dd")} ` I am using this date to add a parition in hive table, it adds the partition value as : `dt=$%7BDATE}` this is my hive command : `ALTER TABLE oozietest ADD IF NOT EXISTS PARTITION (dt="${DATE}") LOCATION "/user/hello/${DATE}"` – Naveen Jun 08 '14 at 13:29
  • please add this to original question. have you tried my answer ? – Mzf Jun 10 '14 at 06:12
  • This should be accepted as the answer. I don't think you can even have a workflow without a coordinator. – javamonkey79 Dec 30 '14 at 01:49
  • 12
    You can definitely have a workflow without a coordinator – davideanastasia Apr 20 '15 at 15:32
  • i receive the below error while using coord:formatTime. `No function is mapped to the name “coord:formatTime”` http://stackoverflow.com/questions/38704255/no-function-is-mapped-to-the-name-coordformattime – Neethu Lalitha Aug 01 '16 at 17:55
  • 1
    I'm getting following error on using ${timestamp()} for oozie SLA nominal time : E0803: IO error, E1004: Expression language evaluation error, Validation error :No function is mapped to the name "timestamp" Any suggestions on how to fix this ? – abhishekmahawar Aug 30 '16 at 12:31
  • @abhishekmahawar according to doc' this EL function is supported on all versions – Mzf Aug 31 '16 at 20:57
  • that's what I saw, but for some reason it's not working – abhishekmahawar Sep 06 '16 at 07:34
  • You can extract the date part of the timestamp using a regex. See my provided answer. – racc May 09 '19 at 02:29
  • @Mzf maybe I'm misunderstanding something, but if providing -1 means it will be previous day, and per OP for today zero should be passed instead, right ? – marknorkin May 05 '20 at 14:08
2

You need to use a regex to extract the date from the timestamp() function:

replaceAll(timestamp(), "(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}Z", "$1")

For some reason timestamp() seemed to return date in the format YYYY-MM-DDThh:mmZ (not YYYY-MM-DDThh:mm:ss.sZ as described), so that's why the regex is as above.

This should work for you, and not require a coordinator to be used.

racc
  • 1,222
  • 10
  • 13