AttributeError:“SQLContext”对象没有属性“load”ApacheSpark+SparkSql mysq连接错误

2024-04-27 19:21:02 发布

您现在位置:Python中文网/ 问答频道 /正文

运行代码时出现错误:

错误:

AttributeError: 'SQLContext' object has no attribute 'load'

如果有人遇到过同样的问题,请告诉我

代码:

# required import modules
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext
from pyspark.sql.types import *

# creating a configuration for context. here "Spark-SQL" is the name of the application and we will create local spark context.
conf = SparkConf().setAppName("Spark-SQL").setMaster("local")

# create a spark context. It is the entry point into all relational functionality in Spark. 
sc = SparkContext(conf=conf)
sqlContext = SQLContext(sc)



# loading the contents from the MySql database table to the dataframe.
df = sqlContext.load(source="jdbc", url="jdbc:mysql://localhost:3306/test?user=root&password=",dbtable="members_indexed")

# display the schema of the dataframe.
df.show()

# display the schema of the dataframe.
df.printSchema()

Tags: ofthe代码fromimportdataframedfconf