Hive UDF to DB UDF conversion and partition rewrite

I'm not sure the logic to find from date and todate will work for all queries.