cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue withpassing parameters to the queries in spark sql temporary function

Raghu1216
New Contributor II

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

3 REPLIES 3

daniel_sahal
Esteemed Contributor

@Raghu Dandu​ 

Try using your function name as an alias for the column,

ex.

job_role = test.designation

Raghu1216
New Contributor II

@Daniel Sahal​  That one also tried Daniel, getting the same error

Anonymous
Not applicable

@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.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.