Skip to content

Commit

Permalink
Fix nested list of structs
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgomezfrr committed Nov 23, 2023
1 parent 1760eff commit c0f5810
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ import org.flyte.flytekitscala.SdkLiteralTypes.{
case class ScalarNested(
foo: String,
bar: Option[String],
nestedNested: Option[ScalarNestedNested]
nestedNested: Option[ScalarNestedNested],
nestedList: List[ScalarNestedNested]
)
case class ScalarNestedNested(foo: String, bar: Option[String])

Expand Down Expand Up @@ -191,6 +192,18 @@ class SdkScalaTypeTest {
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
),
"nestedList" -> Struct.Value.ofListValue(
List(
Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
)
).asJava
)
Expand All @@ -212,7 +225,8 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
None,
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar")))
)
)
)
Expand All @@ -238,7 +252,8 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar")))
)
)
)
Expand Down Expand Up @@ -274,6 +289,18 @@ class SdkScalaTypeTest {
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
),
"nestedList" -> Struct.Value.ofListValue(
List(
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 +344,8 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar")))
)
)
)
Expand All @@ -337,7 +365,8 @@ class SdkScalaTypeTest {
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
Some(ScalarNestedNested("foo", Some("bar"))),
List(ScalarNestedNested("foo", Some("bar")))
)
)
).asJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ 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(value => {
valueToParamValue(value, tpe.typeArgs.head)
})
} 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

0 comments on commit c0f5810

Please sign in to comment.