I am getting this error [{ "resource": "/C:/Users/Anthony.DESKTOP-ES5HL78/AppData/Local/Programs/Python/Python310/Scripts/transaction_type.py", "owner": "_generated_diagnostic_collection_name_#1", "code": { "value": "reportMissingImports", "target": { "$mid": 1, "external": "https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingImports", "path": "/microsoft/pyright/blob/main/docs/configuration.md", "scheme": "https", "authority": "github.com", "fragment": "reportMissingImports" } }, "severity": 4, "message": "Import \"pyspark\" could not be resolved", "source": "Pylance", "startLineNumber": 5, "startColumn": 8, "endLineNumber": 5, "endColumn": 15 },{ "resource": "/C:/Users/Anthony.DESKTOP-ES5HL78/AppData/Local/Programs/Python/Python310/Scripts/transaction_type.py", "owner": "_generated_diagnostic_collection_name_#1", "code": { "value": "reportUndefinedVariable", "target": { "$mid": 1, "external": "https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUndefinedVariable", "path": "/microsoft/pyright/blob/main/docs/configuration.md", "scheme": "https", "authority": "github.com", "fragment": "reportUndefinedVariable" } }, "severity": 4, "message": "\"transaction_type\" is not defined", "source": "Pylance", "startLineNumber": 28, "startColumn": 7, "endLineNumber": 28, "endColumn": 23 }]
Using this code ‘’’
##import required libraries
import pyspark
##create spark session
spark = (pyspark.sql.SparkSession
.builder
.appName(“Python Spark SQL basic example”)
.config(‘spark.driver.extraClassPath’, r"C:\Users\Anthony.DESKTOP-ES5HL78\Downloads\sqljdbc_12.2.0.0_enu\sqljdbc_12.2\enu\mssql-jdbc-12.2.0.jre8.jar")
.getOrCreate()
)
##read table from db using spark jdbc
transaction_type_df = (spark.read
.format(“jdbc”)
.option(“url”, “jdbc:sqlserver://DESKTOP-ES5HL78/kazang”)
.option(“dbtable”, “transaction_type”)
.option(“user”, “anthony”)
.option(“password”, “Musicbook2023…”)
.option(“driver”, "com.microsoft.sqlserver.jdbc.SQLServerDriver’, Server ")
.load()
)
##print the movies_df
print(transaction_type.df.show())
‘’’