0

I am new to databricks,please help me on this.

def Test(name,rule):
      df = spark.table("databasename.tablename").select("Status").where(col('rule')==rule)
        filterstatus=df.head()[0]
      if name is not None : 
      if filterstatus.startswith("P"):
         genstatus='Invalid'
         return genstatus
      else:
         genstatus='Valid'
         return genstatus
    GENFILTER = udf(Test,StringType())
    columns = ["Name","rule"]
    data = [["abcdef", "completed"],["xyz", "incompleted"]]
    df = spark.createDataFrame(data=data,schema=columns)
    df=df.withColumn("genstatus", GENFILTER (col("Name"),col("rule")))

Error: Could not serialize object: Exception: It appears that you are attempting to reference SparkContext from a broadcast variable, action, or transformation. SparkContext can only be used on the driver, not in code that it run on workers. For more information, see SPARK-5063.

  • Does this answer your question? [ERROR:SparkContext can only be used on the driver, not in code that it run on workers. For more information, see SPARK-5063](https://stackoverflow.com/questions/44289962/errorsparkcontext-can-only-be-used-on-the-driver-not-in-code-that-it-run-on-wo) – doctorlove May 05 '22 at 12:55
  • Anyone can you please help me on above query.. – penchalaiah narakatla May 07 '22 at 06:50

0 Answers0