Using Hive UDF/UDAF/UDTF with SparkSQL
Sharing the steps to make Hive UDF/UDAF/UDTF to work natively with SparkSQL
1- Open spark-shell with hive udf jar as parameter:
spark-shell --jars path-to-your-hive-udf.jar
2- From spark-shell, open declare hive context and create functions
val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc);
sqlContext.sql("""create temporary function balance as 'com.github.gbraccialli.hive.udf.BalanceFromRechargesAndOrders'""");
3- From spark-shell, use your UDFs directly in SparkSQL:
sqlContext.sql("""
create table recharges_with_balance_array as
select
reseller_id,
phone_number,
phone_credit_id,
date_recharge,
phone_credit_value,
balance(orders,'date_order', 'order_value', reseller_id, date_recharge, phone_credit_value) as balance
from orders
""");
PS: I found some issues using UDTFs with spark 1.3, which was fixed on spark 1.4.1. I tested all, UDF, UDAF and UDTF, all of them worked properly, same sql statements and same results.

