oozie create a parameter with today date
Asked Answered
P

2

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.

Parameter answered 26/5, 2014 at 20:46 Comment(0)
H
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>
Halonna answered 2/6, 2014 at 20:13 Comment(10)
i tried from coordinator : <configuration> <property> <name>DATE</name> <value>${coord:formatTime(coord:dateOffset(coord:nominalTime(), -1, &#39;DAY&#39;), &quot;yyyy-MM-dd&quot;)}</value> </property> </configuration> 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}"Postboy
please add this to original question. have you tried my answer ?Halonna
This should be accepted as the answer. I don't think you can even have a workflow without a coordinator.Thermolysis
You can definitely have a workflow without a coordinatorGanoid
i receive the below error while using coord:formatTime. No function is mapped to the name “coord:formatTime” #38704755Laidlaw
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 ?Brag
@Brag according to doc' this EL function is supported on all versionsHalonna
that's what I saw, but for some reason it's not workingBrag
You can extract the date part of the timestamp using a regex. See my provided answer.Toledo
@Halonna 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 ?Shishko
T
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.

Toledo answered 9/5, 2019 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.