Skip to content
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

fix maptype doesn't use the frameless injection properly #421

Merged
merged 1 commit into from
Jan 28, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ trait FromCatalystHelpers {
input,
(in: Expression) => singleFieldValueFromCatalyst(mapEntryCmp, keyDesc, in),
(in: Expression) => singleFieldValueFromCatalyst(mapEntryCmp, valDesc, in),
ProtoSQL.dataTypeFor(fd).asInstanceOf[MapType],
protoSql.dataTypeFor(fd).asInstanceOf[MapType],
classOf[Vector[(Any, Any)]]
)
val objs = MyCatalystToExternalMap(urobjs)
Expand Down
4 changes: 4 additions & 0 deletions sparksql-scalapb/src/test/protobuf/customizations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ message BothTimestampTypes {
google.protobuf.Timestamp google_ts = 1;
google.protobuf.Timestamp google_ts_as_sql_ts = 2 [(scalapb.field).type = "java.sql.Timestamp"];
}

message TimestampTypesMap {
map<string, SQLTimestampFromGoogleTimestamp> map_field = 1;
}
4 changes: 2 additions & 2 deletions sparksql-scalapb/src/test/scala/PersonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class PersonSpec extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
}

"UDFs that returns protos" should "work when reading local files" in {
val df = spark.read.json("./sparksql-scalapb/src/test/assets/address.json")
val df = spark.read.json(getClass.getResource("/address.json").toURI.toString)

val returnAddress = ProtoSQL.udf { s: String => Address() }

Expand Down Expand Up @@ -349,7 +349,7 @@ class PersonSpec extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
"parsing null repeated from json" should "work" in {
spark.read
.schema(ProtoSQL.schemaFor[Person].asInstanceOf[types.StructType])
.json("./sparksql-scalapb/src/test/assets/person_null_repeated.json")
.json(getClass.getResource("/person_null_repeated.json").toURI.toString)
.as[Person]
.collect() must contain theSameElementsAs Seq(
Person().withTags(Seq("foo", "bar")),
Expand Down
18 changes: 17 additions & 1 deletion sparksql-scalapb/src/test/scala/TimestampSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import org.scalatest.matchers.must.Matchers
import scalapb.spark.test3.customizations.{
BothTimestampTypes,
SQLTimestampFromGoogleTimestamp,
StructFromGoogleTimestamp
StructFromGoogleTimestamp,
TimestampTypesMap
}

import java.sql.{Timestamp => SQLTimestamp}
Expand Down Expand Up @@ -158,6 +159,21 @@ class TimestampSpec extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
)
}

"spark.createDataset from proto messages with spark timestamp in map" should "be able to convert items with correct timestamp values" in {
import ProtoSQL.withSparkTimestamps.implicits._

val value = TimestampTypesMap(mapField =
Map(
"a" -> SQLTimestampFromGoogleTimestamp(googleTsAsSqlTs = Some(sqlTimestampMicrosPrecision))
)
)
val ds: Dataset[TimestampTypesMap] = spark.createDataset(Seq(value))

ds.collect() must contain theSameElementsAs Seq(
value
)
}

"df with case class timestamp as well as both types of google timestamp" should "not have StructType for timestamps" in {
import ProtoSQL.withSparkTimestamps.implicits._

Expand Down
Loading