Skip to content

Commit b67599e

Browse files
feat(spark): make SparkSession optional (#385)
The ToLogicalPlan class constructor takes a SparkSession argument which must be supplied by the caller. We can simplify the API by making this parameter optional, and defaulting to `SparkSession.builder().getOrCreate()`. The `LocalFiles.scala` test has been modified so that both usages get tested. The need for this was triggered by invoking this API from Python code (pyspark). Passing the SparkSession object from python involves accessing internal handles, which doesn’t make for a good user experience.
1 parent 7b520a7 commit b67599e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

spark/src/main/scala/io/substrait/spark/logical/ToLogicalPlan.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ import scala.collection.mutable.ArrayBuffer
5353
* RelVisitor to convert Substrait Rel plan to [[LogicalPlan]]. Unsupported Rel node will call
5454
* visitFallback and throw UnsupportedOperationException.
5555
*/
56-
class ToLogicalPlan(spark: SparkSession) extends DefaultRelVisitor[LogicalPlan] {
56+
class ToLogicalPlan(spark: SparkSession = SparkSession.builder().getOrCreate())
57+
extends DefaultRelVisitor[LogicalPlan] {
5758

5859
private val expressionConverter =
5960
new ToSparkExpression(ToScalarFunction(SparkExtension.SparkScalarFunctions), Some(this))

spark/src/test/scala/io/substrait/spark/LocalFiles.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class LocalFiles extends SharedSparkSession {
5353
.parseFrom(bytes)
5454
val substraitPlan2 = new ProtoPlanConverter().from(protoPlan)
5555

56-
val sparkPlan2 = new ToLogicalPlan(spark).convert(substraitPlan2)
56+
val sparkPlan2 = new ToLogicalPlan().convert(substraitPlan2)
5757
val result = DatasetUtil.fromLogicalPlan(spark, sparkPlan2)
5858

5959
assertResult(data.columns)(result.columns)

0 commit comments

Comments
 (0)