Oozie fs:exists with variables
Asked Answered
G

2

7

I'm struggeling on the following problem using variables in an Oozie workflow definition checking if a specific file was created. It is working with absolute path like the following, but I cannot use an absolute path:

${fs:exists('/mypath/file.hql')}

In my case, the nameNode and the workflow id has to be replaced but in the decision node this is not working. The variables are not replaced, what is the correct syntax to do this?

    <decision name="check-hql-file-created">
    <switch>
        <case to="hive-exec-il2rl-hql4baseentity">
            ${fs:exists(${nameNode}'/tmp/oozie_tmp/'${wf:id()}'.hql')}
        </case>
        <default to="il2rl-loop"/>
    </switch>
</decision>
Gregggreggory answered 28/7, 2016 at 8:32 Comment(0)
G
9

it is working with concatenation like the following:

        <switch>
        <case to="hive-exec-il2rl-hql4baseentity">
            ${fs:exists(concat(concat(concat(concat(concat(nameNode, '/tmp/oozie_tmp/'), wf:id()), '_'), replaceAll(asJson, "\\{\"|,.+$", "")), '.hql')) == "true"}
        </case>
        <default to="il2rl-loop"/>
    </switch>
Gregggreggory answered 28/7, 2016 at 9:56 Comment(2)
I have struggled with this problem as well. This will work for existing EL expressions but if you have configuration properties for a workflow, you can refer to them by name in the EL expression. Example, FILE_PATH cannot be ${FILE_PATH} in the EL expression, it must be FILE_PATH.Charland
if there are two variables to be passed then use this ${fs:exists(concat(varaible1,variable2))}Sundberg
L
1

Say you plan to use variables 'X' and 'Y', in some format such as /tmp/X/Y (let's call this 'PATH'), then:

  1. Define X, Y and 'PATH' as a variable like so

    PATH = /tmp/${X}/${Y}/

  2. Then use PATH as:

    ${fs:exists(PATH)}

this works.

However, if you want to run this workflow via coordinators, it is better to first assign each of those variables separately too. Like so:

  1. Define X, Y and 'PATH' as a variable like so

    X = value1

    Y = value2

    PATH = /tmp/${X}/${Y}/

  2. Then use PATH as:

    ${fs:exists(PATH)}

and do exactly the same in your coordinator.

Note: value1 and value2 can be Oozie expressions.

Liebman answered 14/2, 2017 at 2:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.