Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,240 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I would like to pass variables values from one cell executing Python (%%pyspark) in one cell to another cell executing R (%%sparkr). In the same notebook.
Is it possible?
My code looks like this :
#cell 1: executes pyspark (python code)
%%pyspark
var = 'A'
#cel2: executes sparkr (R code)
%%sparkr
print(paste0("value of var=",var))
Thanks in advance for the help.
One of the easiest ways to pass data between %%pyspark
and %%sparkr
cells is by creating a Spark DataFrame in Python and then accessing it in R.
%%pyspark
var = 'A'
# Create a Spark DataFrame
df = spark.createDataFrame([(var,)], ["var"])
df.createOrReplaceTempView("var_df")
In your R (%%sparkr) cell:
%%sparkr
# Access the DataFrame
df <- sql("SELECT * FROM var_df")
var_value <- collect(df)$var[1]
print(paste0("value of var=", var_value))