How to enable the %sql Magic string
on jupyter notebook and how to use %sql magic string on a cell with the below line of code.
spark.sql('select * from test').show()
Try
%%sparksql
select * from test
Before trying install
pip install sparksql-magic
You don't need the %sql magic string to work with Spark SQL. You need to first create a Spark DataFrame as described in the SparkSession API docs, like by using df = createDataFrame(data)
. Then you would create a global view, calling df.createOrReplaceTempView("test")
. Then your above query would work.
before using %%sparksql (in case you've installed sparksql-magic), you need to load the extension using below command in a separate cell.
%load_ext sparksql_magic
© 2022 - 2025 — McMap. All rights reserved.