Skip to content

Commit

Permalink
more working
Browse files Browse the repository at this point in the history
  • Loading branch information
ahirreddy committed Apr 15, 2014
1 parent 043ca85 commit c0fb1c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
19 changes: 18 additions & 1 deletion python/pyspark/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
PairDeserializer
from pyspark.storagelevel import StorageLevel
from pyspark import rdd
from pyspark.rdd import RDD
from pyspark.rdd import RDD, SchemaRDD

from py4j.java_collections import ListConverter

Expand Down Expand Up @@ -462,6 +462,23 @@ def sparkUser(self):
"""
return self._jsc.sc().sparkUser()

class SQLContext:

def __init__(self, sparkContext):
self._sc = sparkContext
self._jsc = self._sc._jsc
self._jvm = self._sc._jvm
self._jsql_ctx = self._jvm.JavaSQLContext(self._jsc)

def sql(self, sqlQuery):
return SchemaRDD(self._jsql_ctx.sql(sqlQuery), self)

def applySchema(self, rdd):
jrdd = self._sc._pythonToJava(rdd._jrdd)
srdd = self._jsql_ctx.applySchema(jrdd)
return SchemaRDD(srdd, self)


def _test():
import atexit
import doctest
Expand Down
16 changes: 10 additions & 6 deletions python/pyspark/rdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,13 +1389,17 @@ def _is_pipelinable(self):

class SchemaRDD:

def __init__(self, pyRDD):
self._pyRDD = pyRDD
self.ctx = pyRDD.ctx
self.sql_ctx = self.ctx._jvm.JavaSQLContext(self.ctx._jsc)
self._jrdd = self.ctx._pythonToJava(pyRDD._jrdd)
self._srdd = self.sql_ctx.applySchema(self._jrdd)
def __init__(self, jschema_rdd, sql_ctx):
self.sql_ctx = sql_ctx
self._sc = sql_ctx._sc
self._jschema_rdd = jschema_rdd

def registerAsTable(self, name):
self._jschema_rdd.registerAsTable(name)

def toPython(self):
jrdd = self._sc._javaToPython(self._jschema_rdd)
return RDD(jrdd, self._sc, self._sc.serializer)

def _test():
import doctest
Expand Down

0 comments on commit c0fb1c6

Please sign in to comment.