UDFs and Functions in Hive
How to Create UDFs and Mostly used  Functions in Hive :

UDF Creation in hive :

Three steps
 Sample function in Java for UDF :
public final class ProfanityRemover extends UDF {
 public Text evaluate(final Text s) {
  if (s == null) {
   return null;
  }
  String cleaned = Util.filterOutProfanity(s.toString());  
  return new Text(cleaned);
 }
}
Deploy the 
hive> add jar deprofaner-1.0-jar-with-dependencies.jar;

Create the function either Temporary and Permanent 
hive> CREATE TEMPORARY FUNCTION cleaner as 'com.dataflowdeveloper.deprofaner.ProfanityRemover';

select cleaner('clean this <curseword> up now') from sample_07 limit 1;
 OK

Functions in Hive :


Date Functions : 

  • select from unixtime(Unix_timestamp());
  • TO_DATE('2000-01-01 10:20:30');
                  2000-01-01
  • date_sub(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd') , 1).
  • SELECT DAY('2000-03-01 10:20:30')
               YEAR('2000-01-01 10:20:30');
                MONTH('2000-01-01 10:20:30');
              HOUR('2000-03-01 10:20:30');
             WEEKOFYEAR('2000-03-01 10:20:30');
            DATEDIFF('2000-03-01', '2000-01-10');
            DATE_ADD('2000-03-01', 5);
            DATE_SUB('2000-03-01', 5);

  •  select cast(substring(from_unixtime(unix_timestamp(dt, 'MMM dd, yyyy')),1,10) as date) from A;
                           OK
                            2014-10-16
                            2013-11-13
                            2012-09-14