Skip to content

Commit

Permalink
Merge branch 'typed-inputs' of github.com:flyteorg/flytekit-java into…
Browse files Browse the repository at this point in the history
… typed-inputs
  • Loading branch information
andresgomezfrr committed Jan 23, 2023
2 parents 51e07ef + 817dfb2 commit c73703c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
12 changes: 8 additions & 4 deletions flytekit-java/src/main/java/org/flyte/flytekit/SdkTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
*/
package org.flyte.flytekit;

import java.util.Collections;
import java.util.Map;
import org.flyte.api.v1.Literal;
import org.flyte.api.v1.Variable;

/** An utility class for creating {@link SdkType} objects for different types. */
/** A utility class for creating {@link SdkType} objects for different types. */
public class SdkTypes {
private SdkTypes() {}

Expand All @@ -33,7 +32,7 @@ private static class VoidSdkType extends SdkType<Void> {

@Override
public Map<String, Literal> toLiteralMap(Void value) {
return Collections.emptyMap();
return Map.of();
}

@Override
Expand All @@ -48,7 +47,12 @@ public Void promiseFor(String nodeId) {

@Override
public Map<String, Variable> getVariableMap() {
return Collections.emptyMap();
return Map.of();
}

@Override
public Map<String, SdkBindingData<?>> toSdkBindingMap(Void value) {
return Map.of();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ public Map<String, Variable> getVariableMap() {
Map.entry(A, Variable.builder().literalType(LiteralTypes.INTEGER).build()),
Map.entry(B, Variable.builder().literalType(LiteralTypes.INTEGER).build()));
}

@Override
public Map<String, SdkBindingData<?>> toSdkBindingMap(TestWorkflowInput value) {
return Map.ofEntries(
Map.entry(INTEGER, value.integer()),
Map.entry(FLOAT, value._float()),
Map.entry(STRING, value.string()),
Map.entry(BOOLEAN, value._boolean()),
Map.entry(DATETIME, value.datetime()),
Map.entry(DURATION, value.duration()),
Map.entry(A, value.a()),
Map.entry(B, value.b()));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,40 @@ public static TestPairIntegerInput create(SdkBindingData<Long> a, SdkBindingData

public static class SdkType extends org.flyte.flytekit.SdkType<TestPairIntegerInput> {

private static final String A = "a";
private static final String B = "b";

@Override
public Map<String, Literal> toLiteralMap(TestPairIntegerInput value) {
return Map.of(
"a", Literals.ofInteger(value.a().get()),
"b", Literals.ofInteger(value.b().get()));
A, Literals.ofInteger(value.a().get()),
B, Literals.ofInteger(value.b().get()));
}

@Override
public TestPairIntegerInput fromLiteralMap(Map<String, Literal> value) {
return create(
SdkBindingData.ofInteger(value.get("a").scalar().primitive().integerValue()),
SdkBindingData.ofInteger(value.get("b").scalar().primitive().integerValue()));
SdkBindingData.ofInteger(value.get(A).scalar().primitive().integerValue()),
SdkBindingData.ofInteger(value.get(B).scalar().primitive().integerValue()));
}

@Override
public TestPairIntegerInput promiseFor(String nodeId) {
return create(
SdkBindingData.ofOutputReference(nodeId, "a", LiteralTypes.INTEGER),
SdkBindingData.ofOutputReference(nodeId, "b", LiteralTypes.INTEGER));
SdkBindingData.ofOutputReference(nodeId, A, LiteralTypes.INTEGER),
SdkBindingData.ofOutputReference(nodeId, B, LiteralTypes.INTEGER));
}

@Override
public Map<String, Variable> getVariableMap() {
return Map.of(
"a", Variable.builder().literalType(LiteralTypes.INTEGER).build(),
"b", Variable.builder().literalType(LiteralTypes.INTEGER).build());
A, Variable.builder().literalType(LiteralTypes.INTEGER).build(),
B, Variable.builder().literalType(LiteralTypes.INTEGER).build());
}

@Override
public Map<String, SdkBindingData<?>> toSdkBindingMap(TestPairIntegerInput value) {
return Map.of(A, value.a(), B, value.b());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ public TestUnaryBooleanOutput promiseFor(String nodeId) {
public Map<String, Variable> getVariableMap() {
return Map.of(VAR, Variable.builder().literalType(LITERAL_TYPE).build());
}

@Override
public Map<String, SdkBindingData<?>> toSdkBindingMap(TestUnaryBooleanOutput value) {
return Map.of(VAR, value.o());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ public TestUnaryIntegerInput promiseFor(String nodeId) {
public Map<String, Variable> getVariableMap() {
return Map.of(VAR, Variable.builder().literalType(LITERAL_TYPE).build());
}

@Override
public Map<String, SdkBindingData<?>> toSdkBindingMap(TestUnaryIntegerInput value) {
return Map.of(VAR, value.in());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ public TestUnaryIntegerOutput promiseFor(String nodeId) {
public Map<String, Variable> getVariableMap() {
return Map.of(VAR, Variable.builder().literalType(LITERAL_TYPE).build());
}

@Override
public Map<String, SdkBindingData<?>> toSdkBindingMap(TestUnaryIntegerOutput value) {
return Map.of(VAR, value.o());
}
}
}

0 comments on commit c73703c

Please sign in to comment.