-1

I'm using the python & hive UDF to unpivot data. 'python.py' unpivots the data but I want to run this on Hive. I'm not able to get a handle on items that contain space and period.

Is there a good way to get around it?

My starting table looks like:

  store        item           flavor    
 ------- ----------------- ------------ 
      1   cupcake           chocolate   
      1   cake pops         red velvet  
      1   ice cream         vanilla     
      1   cookies/candies   lemon       
      2   cupcake           red velvet  
      2   cake pops         vanilla     
      2   ice cream         chocolate   
      2   cookies/candies   chocolate   

I'm using inner code to obtain:

  store    cupcake     cake pops    ice cream   cookies/candies  
 ------- ------------ ------------ ----------- ----------------- 
      1   chocolate    red velvet   vanilla     lemon            
      2   red velvet   vanilla      chocolate   chocolate        

using:

SELECT TRANSFORM(store, item, flavor) USING ‘python.py’ 
AS (store, cupcake, cake pops, ice cream, cookies/candies) FROM mytable;

gives an error: "Error while compiling statement: FAILED: ParseException line 3:25 mismatched input 'pops' expecting ) near 'cake' in transform clause"

kiki
  • 15
  • 5

1 Answers1

0

Try to use backquote or single quote.

If your udf defined column name with space, I prefer backquote. But, in this case I guess you need to use single quote.

SELECT TRANSFORM(store, item, flavor) USING ‘python.py’ AS (store, cupcake, 'cake pops', ice cream, cookies/candies) FROM mytable;
hiropon
  • 1,675
  • 2
  • 18
  • 41
  • Thank you @hiropon. My 'python.py' actually does the unpivoting but I want to run this on Hive. I edited the question. – kiki Jun 02 '17 at 03:27