cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group