I have written SQL code that I'm going to use in Spark. The code works fine when applied in T-SQL on MS Server, however when I run apply the code to Spark platform I get the error: Undefined function: 'EOMONTH'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.
I believe the problem is that I need to register the T-SQL function EOMONTH, however, I'm not sure how to do that.
I have tried registering the function with the following;
sqlContext.sql("""CREATE TEMPORARY FUNCTION function_name AS 'EOMONTH'"""),
but I get the error:
Can not load class 'EOMONTH' when registering the function 'function_name', please make sure it is on the classpath;
The full code is as follows:
SELECT MakeName, SUM(Cost) AS TotalCost
FROM Make AS MK INNER JOIN Model AS MD
ON MK.MakeID = MD.MakeID
INNER JOIN Stock AS ST ON ST.ModelID = MD.ModelID
WHERE DateBought BETWEEN
CAST(YEAR(DATE_ADD(m, -1, CURRENT_DATE())) AS CHAR(4))
+ RIGHT('0' + CAST(MONTH(DATE_ADD(m, -1, CURRENT_DATE()))
AS VARCHAR(2)),2) + '01'
AND EOMONTH(DATE_ADD(m, -1, CURRENT_DATE()))
GROUP BY MakeName
I should just get the result from the query