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: 

SQL expr undefined function 'LEN'

PhillT
New Contributor

Getting this error message on our production cluster when I run a notebook that uses the SQL expr function that call the LEN() funciton 

example code:

df = df.withColumn("POL", expr("CASE WHEN SRC_SYSTEM = 'X' THEN CONCAT('08' , SUBSTRING(POL, 3, LEN(POL) -2)) ELSE POL END"))

Below is the error message.  The notebook runs with out issue on my machine on our dev cluster, issue happend on our prod cluster.  Any one has any ideas? 

Exception happened for incremental load. Exception-> Undefined function: 'LEN'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 87. 

I have the following module import...

 

from pyspark.sql.functions import *
from pyspark.sql.types import *
from pyspark.sql import functions as F, Window
from pyspark.sql.functions import col, create_map, lit, expr
from itertools import chain
from pyspark import StorageLevel
from pyspark.sql.functions import coalesce
1 REPLY 1

daniel_sahal
Esteemed Contributor

@PhillT 
There's no "LEN" function. You should use "LENGTH" instead.

https://spark.apache.org/docs/2.3.0/api/sql/index.html#length

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