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>
Gerd
  • 777
  • 1
  • 7
  • 12

2 Answers2

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>
Gerd
  • 777
  • 1
  • 7
  • 12
  • 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`. – pjames Oct 21 '16 at 20:41
  • if there are two variables to be passed then use this `${fs:exists(concat(varaible1,variable2))}` – Alex Raj Kaliamoorthy Feb 13 '18 at 19:36
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.

Ravindranath Akila
  • 209
  • 3
  • 35
  • 45