py4j.security.Py4JSecurityException: Method public org.apache.spark.rdd.RDD org.apache.spark.api.java.JavaRDD.rdd() is not whitelisted on class

Shambhu Rai 1,411 Reputation points
2023-09-18T00:41:02.4333333+00:00

Hi Expert,

I am running below query getting error mesage

py4j.security.Py4JSecurityException: Method public org.apache.spark.rdd.RDD org.apache.spark.api.java.JavaRDD.rdd() is not whitelisted on class class org.apache.spark.api.java.JavaRDD

import json
result = spark.sql("SELECT  VERSION  FROM (DESCRIBE  HISTORY  delta.`/sampDelta/names/` LIMIT  1)").toJSON()
j_obj = json.loads(result.collect()[0])
print(j_obj['VERSION'])
dbutils.widgets.text('vers', str(j_obj['VERSION']))
Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,559 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,517 questions
Azure Database for PostgreSQL
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2023-09-18T12:04:32.1066667+00:00

    The error you're seeing is a Py4J security exception.The method org.apache.spark.api.java.JavaRDD.rdd() is not in the whitelist, so you're getting this error. This method converts a Java RDD to a Scala RDD, but it's not always necessary to call it explicitly.

    I assume you want to execute an SQL query on Delta tables, so you can convert the result to JSON, and extract the VERSION field. To achieve this, you might not need to convert the JavaRDD explicitly.

    Instead of converting the DataFrame result to JSON and then collecting it, you can directly collect the DataFrame result and extract the VERSION field.

    # Run SQL query
    
    result = spark.sql("SELECT VERSION FROM (DESCRIBE HISTORY delta.`/sampDelta/names/` LIMIT 1)")
    
    # Collect result and get the VERSION value
    
    version = result.collect()[0]["VERSION"]
    
    print(version)
    
    # Set the widget value
    
    dbutils.widgets.text('vers', str(version))
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.