Skip to content

[SNAP-3165] Instantiating snappy session only when catalogImplementation #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions python/pyspark/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import py4j

import pyspark

from pyspark import SparkConf
from pyspark.context import SparkContext
from pyspark.sql import SparkSession, SQLContext
from pyspark.sql.snappy import SnappySession
Expand All @@ -57,25 +59,36 @@

SparkContext._ensure_initialized()

conf = SparkConf()
catalogImplementation = conf.get('spark.sql.catalogImplementation', 'hive').lower()
try:
# Try to access HiveConf, it will raise exception if Hive is not added
SparkContext._jvm.org.apache.hadoop.hive.conf.HiveConf()
spark = SparkSession.builder\
.enableHiveSupport()\
.getOrCreate()
if catalogImplementation == 'hive':
# Try to access HiveConf, it will raise exception if Hive is not added
SparkContext._jvm.org.apache.hadoop.hive.conf.HiveConf()
spark = SparkSession.builder\
.enableHiveSupport()\
.getOrCreate()
else:
spark = SparkSession.builder.getOrCreate()
except py4j.protocol.Py4JError:
spark = SparkSession.builder.getOrCreate()
except TypeError:
spark = SparkSession.builder.getOrCreate()


sc = spark.sparkContext
snappy = SnappySession(sc)
sql = snappy.sql
if catalogImplementation == 'in-memory':
snappy = SnappySession(sc)
sql = snappy.sql
else:
sql = spark.sql
atexit.register(lambda: sc.stop())

# for compatibility
sqlContext = snappy._wrapped
if catalogImplementation == 'in-memory':
sqlContext = snappy._wrapped
else:
sqlContext = spark._wrapped
sqlCtx = sqlContext

print("""Welcome to
Expand All @@ -90,7 +103,8 @@
platform.python_build()[0],
platform.python_build()[1]))
print("SparkSession available as 'spark'.")
print("SnappySession available as 'snappy'.")
if catalogImplementation == 'in-memory':
print("SnappySession available as 'snappy'.")

# The ./bin/pyspark script stores the old PYTHONSTARTUP value in OLD_PYTHONSTARTUP,
# which allows us to execute the user's PYTHONSTARTUP file:
Expand Down