Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether a variable exists or not in EL Expression inside Oozie Hive action

I am trying to create a common template for Oozie workflow to be used for running different hive scripts. Each hive script has its own parameters.

On the Hive Action in Oozie, while setting parameters using PARAM tag, I need to check if a variable exists or not and if it does not exist, I need to default it to " ".

I tried,

<param>my_parameter_var=${empty my_parameter?" ":my_parameter}</param>  

this works to only check if my_parameter is a null or empty string. This check fails if the variable doesn't exist at all; with the below error:

Error Code        : EL_ERROR  
Error Message     : variable [my_parameter] cannot be resolved  

Can someone please assist me on how to achieve this?

like image 490
Shankar S Avatar asked Jan 29 '26 12:01

Shankar S


1 Answers

I am not sure if this is still needed but just in case, there is a way with combination of firstNotNull and wf:conf EL functions as below. Remove white spaces in param element from start and end.

< param>my_parameter_var=${firstNotNull(wf:conf('my_parameter'),' ')}< /param >

wf:conf shall return my_parameter's value if NOT empty/null/undefined or return empty string. Ref: https://oozie.apache.org/docs/3.2.0-incubating/WorkflowFunctionalSpec.html#a4.2.3_Workflow_EL_Functions

firstNotNull shall return first argument value if it is NOT empty/null or return second argument value. Ref: https://oozie.apache.org/docs/3.2.0-incubating/WorkflowFunctionalSpec.html#a4.2.1_Basic_EL_Constants

Thanks.

like image 124
smb Avatar answered Feb 01 '26 23:02

smb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!