I have a binary column in a dataframe that I wish to cast as xml, I created a temp table using
sourceDf = spark.read.csv(sourceFilePath, sep=',', header=True, inferSchema=True).createOrReplaceTempView("sourceTable")
And want to run this sql query, which works perfectly in sql server but not in databricks
%sql
SELECT ID
,ORIGINATOR_ID
,INCIDENT_NUMBER
,ATTACHMENT_TYPE
,FORM_NAME
,FORM_DATA
,CAST( CAST( FORM_DATA as XML ).value('.','varbinary(max)') AS nvarchar(max) )
,START_DATE
,END_DATE
,OPERATOR_ID
FROM sourceTable
I get the following error:
Error in SQL statement: ParseException:
no viable alternative at input 'CAST( CAST( FORM_DATA as XML ).value('(line 7, pos 39)
Cany anyone help? If I go back to the source system I can run the same query in SQL server and it works perfectly, but I need to be able to cast to xml within a notebook to then allow me to parse the xml.