From c0f581027256284ba45b1d6e143e0f725e5a232e Mon Sep 17 00:00:00 2001 From: Andres Gomez Ferrer Date: Thu, 23 Nov 2023 16:22:10 +0100 Subject: [PATCH] Fix nested list of structs --- .../flytekitscala/SdkScalaTypeTest.scala | 39 ++++++++++++++++--- .../flyte/flytekitscala/SdkLiteralTypes.scala | 6 +++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/flytekit-scala-tests/src/test/scala/org/flyte/flytekitscala/SdkScalaTypeTest.scala b/flytekit-scala-tests/src/test/scala/org/flyte/flytekitscala/SdkScalaTypeTest.scala index 2424c823..93effcbf 100644 --- a/flytekit-scala-tests/src/test/scala/org/flyte/flytekitscala/SdkScalaTypeTest.scala +++ b/flytekit-scala-tests/src/test/scala/org/flyte/flytekitscala/SdkScalaTypeTest.scala @@ -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]) @@ -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 ) @@ -212,7 +225,8 @@ class SdkScalaTypeTest { ScalarNested( "foo", None, - Some(ScalarNestedNested("foo", Some("bar"))) + Some(ScalarNestedNested("foo", Some("bar"))), + List(ScalarNestedNested("foo", Some("bar"))) ) ) ) @@ -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"))) ) ) ) @@ -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 ) @@ -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"))) ) ) ) @@ -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 diff --git a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkLiteralTypes.scala b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkLiteralTypes.scala index 517ec24d..88a7c3f8 100644 --- a/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkLiteralTypes.scala +++ b/flytekit-scala_2.13/src/main/scala/org/flyte/flytekitscala/SdkLiteralTypes.scala @@ -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