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: 

Unable to use SQL UDF

Avinash_Narala
Contributor
Hello,
 
I want to create an sql udf as follows:
%sql
CREATE or replace FUNCTION get_type(s STRING)
  RETURNS STRING
  LANGUAGE PYTHON
  AS $$
    def get_type(table_name):
      from pyspark.sql.functions import col
      from pyspark.sql import SparkSession

      spark = SparkSession.builder.getOrCreate()
      return spark.sql(f'describe extended  {table_name}').filter(col('col_name')=='Type').select('data_type').collect()[0]['data_type']
    return get_type(s) if s else None
  $$
 
I can verify that get_type function is created in my unity catalog. But while accessing it, it's throwing the error and not working as expected. I am attaching the error message as attachment. Can you please help me with this.
 
 
0 REPLIES 0

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