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
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,23 @@ lazy val `sparksql-scalapb` = (projectMatrix in file("sparksql-scalapb"))
.customRow(
scalaVersions = Seq(Scala212, Scala213),
axisValues = Seq(Spark32, ScalaPB0_10, VirtualAxis.jvm),
settings = Seq()
_.settings(
Test / testOptions += Tests.Filter(_ != "scalapb.spark.ExtensionsSpec")
)
)
.customRow(
scalaVersions = Seq(Scala212),
axisValues = Seq(Spark31, ScalaPB0_10, VirtualAxis.jvm),
settings = Seq()
_.settings(
Test / testOptions += Tests.Filter(_ != "scalapb.spark.ExtensionsSpec")
)
)
.customRow(
scalaVersions = Seq(Scala212),
axisValues = Seq(Spark30, ScalaPB0_10, VirtualAxis.jvm),
settings = Seq()
_.settings(
Test / testOptions += Tests.Filter(_ != "scalapb.spark.ExtensionsSpec")
)
)

ThisBuild / publishTo := sonatypePublishToBundle.value
Expand Down
17 changes: 17 additions & 0 deletions sparksql-scalapb/src/test/protobuf/extensions.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto2";

option java_package = "com.example.protos";

message Foo {
optional string name = 1;

extensions 100 to 199;
}

message Baz {
extend Foo {
optional int32 bar = 126;
}

optional int32 id = 1;
}
31 changes: 31 additions & 0 deletions sparksql-scalapb/src/test/scala/ExtensionsSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package scalapb.spark

import com.example.protos.extensions._
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.col
import org.scalatest.BeforeAndAfterAll
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import scalapb.spark.Implicits._

class ExtensionsSpec extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
val spark: SparkSession = SparkSession
.builder()
.appName("ScalaPB Demo")
.master("local[2]")
.getOrCreate()

"Creating Dataset from message with nested extension" should "work" in {
val data = Seq(
Baz(id = Some(1)),
Baz(id = Some(2)),
Baz(id = Some(3))
)

val binaryDS = spark.createDataset(data.map(_.toByteArray))
binaryDS.show()

val protosDS = binaryDS.map(Baz.parseFrom(_))
protosDS.show()
}
}