Issue withpassing parameters to the queries in spark sql temporary function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 05:26 AM
I have created a function like below
create function test(location STRING, designation STRING, name STRING)
RETURNS TABLE (cnt INT)
RETURN(
SELECT
CASE WHEN location = 'INDIA' THEN
(SELECT COUNT(*) FROM tbl_customers where job_role = designation)
ELSE (SELECT COUNT(*) FROM tbl_customers where job_role = designation AND c_name = name)
END as cnt
When I'm trying to run this function in adb notebook, I'm getting the error like:- Column designation does not exist. Did you mean one of the following?
Can anyone plz suggest me how to get rid of this error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 10:09 PM
@Raghu Dandu
Try using your function name as an alias for the column,
ex.
job_role = test.designation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 04:27 AM
@Daniel Sahal That one also tried Daniel, getting the same error
![](/skins/images/1C7D039E274DA4E433FB1B1A3EAE173A/responsive_peak/images/icon_anonymous_profile.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 03:03 AM
@Raghu Dandu :
The error message suggests that the column "designation" does not exist in the table "tbl_customers". There could be several reasons for this error, such as a typo in the column name, a missing or deleted column, or a difference in the table schema.
To resolve this error, you should check the schema of the "tbl_customers" table and make sure that the column "designation" exists in the table. You can also try to qualify the column name with the table name or alias to avoid any ambiguity in the column name, like "tbl_customers.job_role" instead of just "job_role".
If the column "designation" is missing or renamed, you may need to modify your function accordingly or update the table schema.
![](/skins/images/B38AF44D4BD6CE643D2A527BE673CCF6/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/B38AF44D4BD6CE643D2A527BE673CCF6/responsive_peak/images/icon_anonymous_message.png)