2016-08-30 4 views
0

Ich versuche, einfachen Testcode in pyspark zum Drucken von Punkten mit Magellan-Bibliothek wie aus dem Github-Repository, aber ich habe ein Problem von undefined sc Kontext.Verwenden Magellan Geospatial-Bibliothek mit Apache Funke für eigenständige Anwendungen

Wenn ich es von der Kommandozeile mit den vorgeschlagenen Befehl $SPARK_HOME/bin/spark-submit --packages harsha2010:magellan:1.0.2-s_2.10 alles funktioniert, weil sc automatisch importiert wird, aber wenn ich es als eigenständige Anwendung von eclipse führen Sie es nicht sc nicht erkennt.

Ich habe alle Kombinationen für seine Initialisierung einschließlich dieses Stück Code versucht:

from pyspark import SparkConf,SparkContext 
from magellan.types import Point 
from pyspark.sql import Row, SQLContext 
#from magellan-master.python.magellan.context import sc 
sc = SparkContext(appName="MyGeoFencing") 
#sql = SQLContext(sc) 
#from magellan.context import sc 
#from magellan.context import sc 
#from magellan.context import SQLContext 
PointRecord = Row("id", "point") 
#sparkConf = SparkConf().setAppName("MyGeoFencing") 
#sc = SparkContext(conf=sparkConf) 
#sql = SQLContext(sc) 
sqlCont = SQLContext(sc) 


points = sqlCont.parallelize([ 
    (0, Point(-1.0, -1.0)), 
    (1, Point(-1.0, 1.0)), 
    (2, Point(1.0, -1.0))]).map(lambda x: PointRecord(*x)).toDF() 


points.show() 

ist hier das Problem, dass sqlCont nicht Methode parallelize hat. Ich habe sogar versucht, direkt sc von magellan.context zu importieren, funktioniert aber auch nicht. Das gleiche Problem tritt auf, wenn ich scala verwende!

Haben Sie eine Idee, wie das funktionieren soll?

Danke!

Antwort

0

Dies funktioniert für mich:

sc = spark.sparkContext 
from pyspark.sql import SQLContext 
from pyspark.sql.types import * 
sqlContext = SQLContext(sc) 
Verwandte Themen