Skip to content

Commit

Permalink
Display message if hive is not built into spark
Browse files Browse the repository at this point in the history
  • Loading branch information
ahirreddy committed Apr 15, 2014
1 parent 227a0be commit e4da06c
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions python/pyspark/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from pyspark.rdd import RDD, SchemaRDD

from py4j.java_collections import ListConverter
from py4j.protocol import Py4JError


class SparkContext(object):
Expand Down Expand Up @@ -621,31 +622,38 @@ class HiveContext(SQLContext):

@property
def _ssql_ctx(self):
if not hasattr(self, '_scala_HiveContext'):
self._scala_HiveContext = self._jvm.HiveContext(self._jsc.sc())
return self._scala_HiveContext
try:
if not hasattr(self, '_scala_HiveContext'):
self._scala_HiveContext = self._get_hive_ctx()
return self._scala_HiveContext
except Py4JError as e:
raise Exception("You must build Spark with Hive. Export 'SPARK_HIVE=true' and run " \
"sbt/sbt assembly" , e)

def _get_hive_ctx(self):
return self._jvm.HiveContext(self._jsc.sc())

def hiveql(self, hqlQuery):
"""
Runs a query expressed in HiveQL, returning the result as a L{SchemaRDD}.
"""
return SchemaRDD(self._ssql_ctx.hiveql(hqlQuery), self)

def hql(self, hqlQuery):
"""
Runs a query expressed in HiveQL, returning the result as a L{SchemaRDD}.
"""
return self.hiveql(hqlQuery)

class LocalHiveContext(HiveContext):

@property
def _ssql_ctx(self):
if not hasattr(self, '_scala_LocalHiveContext'):
self._scala_LocalHiveContext = self._jvm.LocalHiveContext(self._jsc.sc())
return self._scala_LocalHiveContext
def _get_hive_ctx(self):
return self._jvm.LocalHiveContext(self._jsc.sc())

class TestHiveContext(HiveContext):

@property
def _ssql_ctx(self):
if not hasattr(self, '_scala_TestHiveContext'):
self._scala_TestHiveContext = self._jvm.TestHiveContext(self._jsc.sc())
return self._scala_TestHiveContext
def _get_hive_ctx(self):
return self._jvm.TestHiveContext(self._jsc.sc())

def _test():
import atexit
Expand Down

0 comments on commit e4da06c

Please sign in to comment.