Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oozie fs:exists with variables

Tags:

oozie

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>
like image 317
Gerd Avatar asked Jul 28 '16 08:07

Gerd


2 Answers

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>
like image 53
Gerd Avatar answered Sep 24 '22 19:09

Gerd


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.

like image 42
Ravindranath Akila Avatar answered Sep 25 '22 19:09

Ravindranath Akila