Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/clojure/sparkling/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
[org.apache.spark.api.java JavaSparkContext StorageLevels
JavaRDD JavaPairRDD JavaDoubleRDD]
[org.apache.spark HashPartitioner Partitioner]
[org.apache.spark.sql SparkSession]
[org.apache.spark.rdd PartitionwiseSampledRDD PartitionerAwareUnionRDD]
[scala.collection JavaConversions]
[scala.reflect ClassTag$]))
Expand Down Expand Up @@ -741,6 +742,10 @@ so that the wrapped function returns a tuple [f(v),v]"
(conf/app-name app-name))]
(spark-context conf))))

(defn spark-session
[^JavaSparkContext context]
(SparkSession. (.sc context)))

(defn local-spark-context
[app-name]
(let [conf (-> (conf/spark-conf)
Expand Down
14 changes: 14 additions & 0 deletions test/sparkling/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@
))


(deftest spark-session-test
(s/with-context
c
(-> (conf/spark-conf)
(conf/set-sparkling-registrator)
(conf/set "spark.kryo.registrationRequired" "true")
(conf/master "local[*]")
(conf/app-name "api-test"))
(let [spark-session (s/spark-session c)
df (.toDF (.range spark-session 10) (into-array String ["number"]))]
(testing "checking SparkSession instance"
(is (instance? org.apache.spark.sql.SparkSession spark-session)))

(testing "checking DF instance"
(instance? org.apache.spark.sql.Dataset df)))))

(deftest lookup
(s/with-context
Expand Down