Skip to content

Commit

Permalink
SparkSession Creation fix for compatibility with pySpark (bigdatageno…
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalgosar committed Oct 25, 2017
1 parent 21df571 commit 06c233f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 3 additions & 3 deletions bin/pygnocchi
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ else
ASSEMBLY_DIR="$SCRIPT_DIR/gnocchi-assembly/target"
fi

num_jars="$(ls -1 "$ASSEMBLY_DIR" | grep "^gnocchi-assembly_[0-9A-Za-z\.-]*\.jar$" | grep -v javadoc | grep -v sources | wc -l)"
num_jars="$(ls -1 "$ASSEMBLY_DIR" | grep "^gnocchi[0-9A-Za-z\.\_\-]*\.jar$" | grep -v javadoc | grep -v sources | wc -l)"
if [ "$num_jars" -eq "0" ]; then
echo "Failed to find Gnocchi assembly in $ASSEMBLY_DIR." 1>&2
echo "Failed to find Gnocchi cli assembly in $ASSEMBLY_DIR." 1>&2
echo "You need to build Gnocchi before running this program." 1>&2
exit 1
fi

ASSEMBLY_JARS="$(ls -1 "$ASSEMBLY_DIR" | grep "^gnocchi-assembly_[0-9A-Za-z\.-]*\.jar$" | grep -v javadoc | grep -v sources || true)"
ASSEMBLY_JARS="$(ls -1 "$ASSEMBLY_DIR" | grep "^gnocchi[0-9A-Za-z\.\_\-]*\.jar$" | grep -v javadoc | grep -v sources || true)"
if [ "$num_jars" -gt "1" ]; then
echo "Found multiple Gnocchi cli assembly jars in $ASSEMBLY_DIR:" 1>&2
echo "$ASSEMBLY_JARS" 1>&2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,22 @@ import scala.collection.JavaConversions._
object GnocchiSession {

// Add GnocchiContext methods
implicit def sparkContextToGnocchiContext(sc: SparkContext): GnocchiSession =
implicit def sparkContextToGnocchiSession(sc: SparkContext): GnocchiSession =
new GnocchiSession(sc)

/**
* Creates a GnocchiSession from SparkSession. Sets the active session to the
* input session.
*
*
* @param ss SparkSession
* @return GnocchiSession
*/
def GnocchiSessionFromSession(ss: SparkSession): GnocchiSession = {
SparkSession.setActiveSession(ss)
new GnocchiSession(ss.sparkContext)
}

}

class GnocchiSession(@transient val sc: SparkContext) extends Serializable with Logging {
Expand Down Expand Up @@ -293,4 +306,4 @@ class GnocchiSession(@transient val sc: SparkContext) extends Serializable with

phenoCovarDF.withColumn("phenoName", lit(phenoName)).as[Phenotype].collect().map(x => (x.sampleId, x)).toMap
}
}
}
10 changes: 5 additions & 5 deletions gnocchi-python/bdgenomics/gnocchi/gnocchiSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class GnocchiSession(object):
"""
"""

def __init__(self, sc):
self._sc = sc
self._jvm = sc._jvm
session = sc._jvm.net.fnothaft.gnocchi.sql.GnocchiSession(sc._jsc.sc())
self.__jgs = sc._jvm.net.fnothaft.gnocchi.api.java.JavaGnocchiSession(session)
def __init__(self, ss):
self._sc = ss.sparkContext
self._jvm = self._sc._jvm
session = self._jvm.net.fnothaft.gnocchi.sql.GnocchiSession.GnocchiSessionFromSession(ss._jsparkSession)
self.__jgs = self._jvm.net.fnothaft.gnocchi.api.java.JavaGnocchiSession(session)

def filterSamples(self, genotypesDataset, mind, ploidy):
dataset = self.__jgs.filterSamples(genotypesDataset.get(), mind, ploidy)
Expand Down

0 comments on commit 06c233f

Please sign in to comment.