1

I have the following question. I want to pass the value of a variable (string) from scala to python in databricks. I know I can transfer dataframe information between the two languages ​​using this command:

%scala
scalaDF.registerTempTable("some_table")

%python
spark.table("some_table")

But I can't transfer a string this way, any ideas?

1
  • You can't really. Either save it to a new dataframe/rdd or if operating on master node to a file. Yuck. Commented Jan 26, 2021 at 12:08

2 Answers 2

2

Create one broadcast variable in scala spark context and get it's value in pyspark context.

Sign up to request clarification or add additional context in comments.

Comments

2

You can run a Spark SQL command to save a variable:

%scala

spark.sql("set var1 = 'abc'")

And in Python you can get it back using

%python

spark.sql("select ${var1}").head()[0]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.