AttributeError:'SQLContext'对象没有属性'load'-与MySQL的ApacheSpark + SparkSql连接错误

时间:2019-02-21 19:18:01

标签: python mysql apache-spark-sql

运行代码时出现错误:

错误:

  

AttributeError:“ SQLContext”对象没有属性“ 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()

0 个答案:

没有答案