Handle Option correctly by honnix · Pull Request #266 · flyteorg/flytekit-java · GitHub
Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
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 @@ -73,14 +73,19 @@ class LaunchPlanRegistry extends SimpleSdkLaunchPlanRegistry {
6.toDouble,
"hello",
List("1", "2"),
List(NestedNested(7.toDouble, NestedNestedNested("world"))),
List(NestedNested(7.toDouble, Some(NestedNestedNested("world")))),
Map("1" -> "1", "2" -> "2"),
Map("foo" -> NestedNested(7.toDouble, NestedNestedNested("world"))),
Map(
"foo" -> NestedNested(
7.toDouble,
Some(NestedNestedNested("world"))
)
),
Some(false),
None,
Some(List("3", "4")),
Some(Map("3" -> "3", "4" -> "4")),
NestedNested(7.toDouble, NestedNestedNested("world"))
NestedNested(7.toDouble, Some(NestedNestedNested("world")))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.flyte.flytekitscala.{
}

case class NestedNestedNested(string: String)
case class NestedNested(double: Double, nested: NestedNestedNested)
case class NestedNested(double: Double, nested: Option[NestedNestedNested])
case class Nested(
boolean: Boolean,
byte: Byte,
Expand Down Expand Up @@ -57,9 +57,6 @@ case class NestedIOTaskOutput(
generic: SdkBindingData[Nested]
)

/** Example Flyte task that takes a name as the input and outputs a simple
* greeting message.
*/
class NestedIOTask
extends SdkRunnableTask[
NestedIOTaskInput,
Expand All @@ -69,17 +66,21 @@ class NestedIOTask
SdkScalaType[NestedIOTaskOutput]
) {

/** Defines task behavior. This task takes a name as the input, wraps it in a
* welcome message, and outputs the message.
*
* @param input
* the name of the person to be greeted
* @return
* the welcome message
*/
override def run(input: NestedIOTaskInput): NestedIOTaskOutput =
NestedIOTaskOutput(
input.name,
input.generic
)
}

class NestedIOTaskNoop
extends SdkRunnableTask[
NestedIOTaskOutput,
NestedIOTaskOutput
](
SdkScalaType[NestedIOTaskOutput],
SdkScalaType[NestedIOTaskOutput]
) {

override def run(input: NestedIOTaskOutput): NestedIOTaskOutput = input
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class NestedIOWorkflow
builder: SdkScalaWorkflowBuilder,
input: NestedIOTaskInput
): Unit = {
builder.apply(new NestedIOTask(), input)
val output = builder.apply(new NestedIOTask(), input)
builder.apply(new NestedIOTaskNoop(), output.getOutputs)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ import org.flyte.flytekitscala.SdkLiteralTypes.{
}

// The constructor is reflectedly invoked so it cannot be an inner class
case class ScalarNested(foo: String, bar: String)
case class ScalarNested(
foo: String,
bar: Option[String],
nestedNested: Option[ScalarNestedNested]
)
case class ScalarNestedNested(foo: String, bar: Option[String])

class SdkScalaTypeTest {

Expand Down Expand Up @@ -178,7 +183,15 @@ class SdkScalaTypeTest {
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
"bar" -> Struct.Value.ofNullValue(),
"nestedNested" -> Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
)
)
Expand All @@ -196,7 +209,11 @@ class SdkScalaTypeTest {
blob = SdkBindingDataFactory.of(blob),
generic = SdkBindingDataFactory.of(
SdkLiteralTypes.generics(),
ScalarNested("foo", "bar")
ScalarNested(
"foo",
None,
Some(ScalarNestedNested("foo", Some("bar")))
)
)
)

Expand All @@ -218,7 +235,11 @@ class SdkScalaTypeTest {
blob = SdkBindingDataFactory.of(blob),
generic = SdkBindingDataFactory.of(
SdkLiteralTypes.generics(),
ScalarNested("foo", "bar")
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
)
)
)

Expand All @@ -245,7 +266,15 @@ class SdkScalaTypeTest {
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
"bar" -> Struct.Value.ofStringValue("bar"),
"nestedNested" -> Struct.Value.ofStructValue(
Struct.of(
Map(
"foo" -> Struct.Value.ofStringValue("foo"),
"bar" -> Struct.Value.ofStringValue("bar")
).asJava
)
)
).asJava
)
)
Expand Down Expand Up @@ -285,7 +314,11 @@ class SdkScalaTypeTest {
blob = SdkBindingDataFactory.of(blob),
generic = SdkBindingDataFactory.of(
SdkLiteralTypes.generics(),
ScalarNested("foo", "bar")
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
)
)
)

Expand All @@ -301,7 +334,11 @@ class SdkScalaTypeTest {
"blob" -> SdkBindingDataFactory.of(blob),
"generic" -> SdkBindingDataFactory.of(
SdkLiteralTypes.generics[ScalarNested](),
ScalarNested("foo", "bar")
ScalarNested(
"foo",
Some("bar"),
Some(ScalarNestedNested("foo", Some("bar")))
)
)
).asJava

Expand Down