jeudi 22 mai 2014

Hadoop - création d'une requête de hiveQL qui utilise la fonction UDF qui peut retourner des noms de colonnes - Stack Overflow


I want to create a Hive UDF function that returns specific column names based on some value say retreivecol(age).If the age is 20 then return the list of column names to be used in select query like 'name,email,fbuserid,friend list ' etc and if the age is less than 20 return 'name' alone.So I want my HIVE QL query to look like


select retreivecol(age) from User_Data;


The above query just prints the name of the columns like 'name,email,fbuserid,friendslist' etc as opposed to treating them as column names and filtering based on the same.Any pointers are appreciated.




I'm not sure a UDF is the right place to do this, as UDF's simply see the value passed to them, they don't really have access to the whole table structure.


Instead, could you do this in a nested table?


select name,email,id FROM
(
select
name,
if(age < 20, email, NULL) as email,
if(age < 20, id, NULL) as id
FROM mytable

) a


I want to create a Hive UDF function that returns specific column names based on some value say retreivecol(age).If the age is 20 then return the list of column names to be used in select query like 'name,email,fbuserid,friend list ' etc and if the age is less than 20 return 'name' alone.So I want my HIVE QL query to look like


select retreivecol(age) from User_Data;


The above query just prints the name of the columns like 'name,email,fbuserid,friendslist' etc as opposed to treating them as column names and filtering based on the same.Any pointers are appreciated.



I'm not sure a UDF is the right place to do this, as UDF's simply see the value passed to them, they don't really have access to the whole table structure.


Instead, could you do this in a nested table?


select name,email,id FROM
(
select
name,
if(age < 20, email, NULL) as email,
if(age < 20, id, NULL) as id
FROM mytable

) a

0 commentaires:

Enregistrer un commentaire