PREHOOK: query: DESCRIBE FUNCTION case PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION case POSTHOOK: type: DESCFUNCTION CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END - When a = b, returns c; when a = d, return e; else return f PREHOOK: query: DESCRIBE FUNCTION EXTENDED case PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED case POSTHOOK: type: DESCFUNCTION CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END - When a = b, returns c; when a = d, return e; else return f Example: SELECT CASE deptno WHEN 1 THEN Engineering WHEN 2 THEN Finance ELSE admin END, CASE zone WHEN 7 THEN Americas ELSE Asia-Pac END FROM emp_details PREHOOK: query: EXPLAIN SELECT CASE 1 WHEN 1 THEN 2 WHEN 3 THEN 4 ELSE 5 END, CASE 2 WHEN 1 THEN 2 ELSE 5 END, CASE 14 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 16 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 17 WHEN 18 THEN NULL WHEN 17 THEN 20 END, CASE 21 WHEN 22 THEN 23 WHEN 21 THEN 24 END FROM src tablesample (1 rows) PREHOOK: type: QUERY POSTHOOK: query: EXPLAIN SELECT CASE 1 WHEN 1 THEN 2 WHEN 3 THEN 4 ELSE 5 END, CASE 2 WHEN 1 THEN 2 ELSE 5 END, CASE 14 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 16 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 17 WHEN 18 THEN NULL WHEN 17 THEN 20 END, CASE 21 WHEN 22 THEN 23 WHEN 21 THEN 24 END FROM src tablesample (1 rows) POSTHOOK: type: QUERY STAGE DEPENDENCIES: Stage-0 is a root stage STAGE PLANS: Stage: Stage-0 Fetch Operator limit: -1 Processor Tree: TableScan alias: src Row Limit Per Split: 1 Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: COMPLETE Select Operator expressions: 2 (type: int), 5 (type: int), 15 (type: int), null (type: int), 20 (type: int), 24 (type: int) outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5 Statistics: Num rows: 500 Data size: 10000 Basic stats: COMPLETE Column stats: COMPLETE ListSink PREHOOK: query: SELECT CASE 1 WHEN 1 THEN 2 WHEN 3 THEN 4 ELSE 5 END, CASE 2 WHEN 1 THEN 2 ELSE 5 END, CASE 14 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 16 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 17 WHEN 18 THEN NULL WHEN 17 THEN 20 END, CASE 21 WHEN 22 THEN 23 WHEN 21 THEN 24 END FROM src tablesample (1 rows) PREHOOK: type: QUERY PREHOOK: Input: default@src #### A masked pattern was here #### POSTHOOK: query: SELECT CASE 1 WHEN 1 THEN 2 WHEN 3 THEN 4 ELSE 5 END, CASE 2 WHEN 1 THEN 2 ELSE 5 END, CASE 14 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 16 WHEN 12 THEN 13 WHEN 14 THEN 15 END, CASE 17 WHEN 18 THEN NULL WHEN 17 THEN 20 END, CASE 21 WHEN 22 THEN 23 WHEN 21 THEN 24 END FROM src tablesample (1 rows) POSTHOOK: type: QUERY POSTHOOK: Input: default@src #### A masked pattern was here #### 2 5 15 NULL 20 24 PREHOOK: query: -- verify that short-circuiting is working correctly for CASE -- we should never get to the ELSE branch, which would raise an exception SELECT CASE 1 WHEN 1 THEN 'yo' ELSE reflect('java.lang.String', 'bogus', 1) END FROM src tablesample (1 rows) PREHOOK: type: QUERY PREHOOK: Input: default@src #### A masked pattern was here #### POSTHOOK: query: -- verify that short-circuiting is working correctly for CASE -- we should never get to the ELSE branch, which would raise an exception SELECT CASE 1 WHEN 1 THEN 'yo' ELSE reflect('java.lang.String', 'bogus', 1) END FROM src tablesample (1 rows) POSTHOOK: type: QUERY POSTHOOK: Input: default@src #### A masked pattern was here #### yo PREHOOK: query: -- Allow compatible types in when/return type SELECT CASE 1 WHEN 1 THEN 123.0BD ELSE 0.0BD END, CASE 1 WHEN 1.0 THEN 123 WHEN 2 THEN 1.0 ELSE 222.02BD END, CASE 'abc' WHEN cast('abc' as varchar(3)) THEN 'abcd' WHEN 'efg' THEN cast('efgh' as varchar(10)) ELSE cast('ijkl' as char(4)) END FROM src tablesample (1 rows) PREHOOK: type: QUERY PREHOOK: Input: default@src #### A masked pattern was here #### POSTHOOK: query: -- Allow compatible types in when/return type SELECT CASE 1 WHEN 1 THEN 123.0BD ELSE 0.0BD END, CASE 1 WHEN 1.0 THEN 123 WHEN 2 THEN 1.0 ELSE 222.02BD END, CASE 'abc' WHEN cast('abc' as varchar(3)) THEN 'abcd' WHEN 'efg' THEN cast('efgh' as varchar(10)) ELSE cast('ijkl' as char(4)) END FROM src tablesample (1 rows) POSTHOOK: type: QUERY POSTHOOK: Input: default@src #### A masked pattern was here #### 123 123.0 abcd