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 nested list & map of structs using case classes #267

Merged
merged 3 commits into from
Nov 23, 2023
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 @@ -52,7 +52,9 @@ import org.flyte.flytekitscala.SdkLiteralTypes.{
case class ScalarNested(
foo: String,
bar: Option[String],
nestedNested: Option[ScalarNestedNested]
nestedNested: Option[ScalarNestedNested],
nestedNestedList: List[ScalarNestedNested],
nestedNestedMap: Map[String, ScalarNestedNested]
)
case class ScalarNestedNested(foo: String, bar: Option[String])

Expand Down Expand Up @@ -191,6 +193,32 @@ class SdkScalaTypeTest {
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
),
"nestedNestedList" -> Struct.Value.ofListValue(
List(
Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
),
"nestedNestedMap" -> Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
)
)
).asJava
)
Expand All @@ -212,7 +240,9 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
None,
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar"))),
Map("foo" -> ScalarNestedNested("foo", Some("bar")))
)
)
)
Expand All @@ -238,7 +268,9 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar"))),
Map("foo" -> ScalarNestedNested("foo", Some("bar")))
)
)
)
Expand Down Expand Up @@ -274,6 +306,32 @@ class SdkScalaTypeTest {
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
),
"nestedNestedList" -> Struct.Value.ofListValue(
List(
Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
),
"nestedNestedMap" -> Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
)
)
).asJava
)
Expand Down Expand Up @@ -317,7 +375,9 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar"))),
Map("foo" -> ScalarNestedNested("foo", Some("bar")))
)
)
)
Expand All @@ -337,7 +397,9 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar"))),
Map("foo" -> ScalarNestedNested("foo", Some("bar")))
)
)
).asJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ object SdkLiteralTypes {
value.asInstanceOf[Double].toLong
} else if (tpe =:= typeOf[Float]) {
value.asInstanceOf[Double].toFloat
} else if (tpe <:< typeOf[List[Any]]) {
value
.asInstanceOf[List[Any]]
.map(v => {
valueToParamValue(v, tpe.typeArgs.head)
})
} else if (tpe <:< typeOf[Map[String, Any]]) {
value
.asInstanceOf[Map[String, Any]]
.mapValues(v => {
valueToParamValue(v, tpe.typeArgs(1))
})
.toMap
} else if (tpe <:< typeOf[Option[Any]]) { // this has to be before Product check because Option is a Product
if (value == None) { // None is used to represent Struct.Value.Kind.NULL_VALUE when converting struct to map
None
Expand Down
Loading