我是 Apache 的新手 Spark 尝试处理大查询,当我尝试运行我在下面共享的代码时,它会给我错误
文件 "/****/***/spark-1.1.0/examples/src/main/python/testSql.py",第 25 行,在 schemaEvents = sqlContext.createDataFrame(events) 属性错误:SQLContext 实例没有属性"createDataFrame"
我正在关注以下链接进行练习。https://spark.apache.org/docs/latest/sql-programming-guide.html#dataframes
代码在下面共享。
from pyspark.sql import *
from pyspark import *
#File = "/home/shafee/spark-1.1.0/results-20160315-075804.csv" # Should be some file on your system
File = "" # Should be some file on your system
sc = SparkContext()
sqlContext = SQLContext(sc)
Line = sc.textFile("results-20160315-075804.csv")
parts = Line.map(lambda l: l.split(","))
events = parts.map(lambda p: Row(Actor1Name=p[6], SourceUrl=int(p[56])))
schemaEvents = sqlContext.createDataFrame(events)
schemaPeople.registerTempTable("events")
df = sqlContext.sql("SELECT * FROM ").collect()
worldcount = df.count()
print("Totel words counts in csv file: %i" % (worldcount))
您使用的是 Spark 1.1,并且 Spark 1.3 中引入了SQLContext.createDataFrame
。如果要使用,则应按照当前的编程指南更新Spark版本。