2016-06-28 16 views
0

で提供されている基本的な例を実行しようとしています。Apache SPARKドキュメントのReflectセグメントを使用しています。Apache SPARK with SQLContext :: IndexError

私は私が実行しようとしている例は以下の通りです::

# sc is an existing SparkContext. 
from pyspark.sql import SQLContext, Row 
sqlContext = SQLContext(sc) 

# Load a text file and convert each line to a Row. 
lines = sc.textFile("/user/cloudera/analytics/book6_sample.csv") 
parts = lines.map(lambda l: l.split(",")) 
people = parts.map(lambda p: Row(name=p[0], age=int(p[1]))) 

# Infer the schema, and register the DataFrame as a table. 
schemaPeople = sqlContext.createDataFrame(people) 
schemaPeople.registerTempTable("people") 

# SQL can be run over DataFrames that have been registered as a table. 
teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19") 

# The results of SQL queries are RDDs and support all the normal RDD operations. 
teenNames = teenagers.map(lambda p: "Name: " + p.name) 
for teenName in teenNames.collect(): 
    print(teenName) 

が、上記のように示したように、私は正確にコードを実行したClouderaのクイックスタートVM(CDH5)

上でこれをやっています最後のコマンド(forループ)を実行すると、エラー「IndexError:リストインデックスが範囲外」になります。

入力ファイルbook6_sampleは book6_sample.csvにあります。

私は最後のコマンド(forループ)を実行すると、上記のようにコードを実行しましたが、常に "IndexError:リストインデックスが範囲外です"というエラーが発生しました。

私が間違っている箇所を指摘してください。

ありがとうございます。

よろしく、 スリ

答えて

0

あなたのファイルをテキストエディタでこのerror.Openあなたのファイルを引き起こし、それが

+1

サチンねえ、やった仕事を働くことを願って、その行を削除された最後の1つの空行を持っています提案された変更を行った後。 – Sri

関連する問題