Skip to content

Commit e9f5b8d

Browse files
committed
adding tests
1 parent 906d180 commit e9f5b8d

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

python/pyspark/context.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,49 @@ def sparkUser(self):
464464
return self._jsc.sc().sparkUser()
465465

466466
class SQLContext:
467+
"""
468+
Main entry point for SparkSQL functionality. A SQLContext can be used create L{SchemaRDD}s,
469+
register L{SchemaRDD}s as tables, execute sql over tables, cache tables, and read parquet files.
470+
"""
467471

468472
def __init__(self, sparkContext):
473+
"""
474+
Create a new SQLContext.
475+
476+
@param sparkContext: The SparkContext to wrap.
477+
478+
>>> from pyspark.context import SQLContext
479+
>>> sqlCtx = SQLContext(sc)
480+
"""
469481
self._sc = sparkContext
470482
self._jsc = self._sc._jsc
471483
self._jvm = self._sc._jvm
472484
self._ssql_ctx = self._jvm.SQLContext(self._jsc.sc())
473485

486+
def parquetFile(path):
487+
jschema_rdd = self._ssql_ctx.parquetFile(path)
488+
return SchemaRDD(jschema_rdd, self)
489+
490+
def registerRDDAsTable(rdd, tableName):
491+
jschema_rdd = rdd._jschema_rdd
492+
self._ssql_ctx.registerRDDAsTable(jschema_rdd, tableName)
493+
474494
def sql(self, sqlQuery):
475495
return SchemaRDD(self._ssql_ctx.sql(sqlQuery), self)
476496

497+
def table(tableName):
498+
return SchemaRDD(self._ssql_ctx.table(tableName), self)
499+
500+
def cacheTable(tableName):
501+
self._ssql_ctx.cacheTable(tableName)
502+
503+
def uncacheTable(tableName):
504+
self._ssql_ctx.uncacheTable(tableName)
505+
477506
def applySchema(self, rdd):
478507
if (rdd.__class__ is SchemaRDD):
479508
raise Exception("Cannot apply schema to %s" % SchemaRDD.__name__)
480-
elif type(rdd.first()) is not dict:
509+
elif isinstance(rdd.first(), dict) is not dict:
481510
raise Exception("Only RDDs with dictionaries can be converted to %s" % SchemaRDD.__name__)
482511

483512
jrdd = self._sc._pythonToJavaMap(rdd._jrdd)

0 commit comments

Comments
 (0)