mardi 21 août 2018

How to use conditional statements to execute (or bypass) chunks of code in Hive/SQL?

I know how to use conditional statements in Hive to assign values to variables, for example

CASE WHEN expression = condition1 THEN result1
     WHEN expression = condition2 THEN result2
     ...
     ELSE result
END;

Now I would like to use conditional statements to decide whether to execute a chunk of code. When I try to apply the above, it fails. For example,

CASE WHEN (expression = condition1 or expression = condition2) 
     THEN
          CREATE TABLE table1;
          CREATE TABLE table2;
          CREATE TABLE table3;
     END;

I get an error message FAILED: ParseException line 5:0 cannot recognize input near 'CASE' 'WHEN' '('.

Is it possible to use conditional statements to execute/bypass chunks of code? Thanks!

Aucun commentaire:

Enregistrer un commentaire