Search in sources :

Example 16 with Literal

use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.

the class ExecuteLocalArgsParser method parseInputs.

public Map<String, Literal> parseInputs(String synopsis, Map<String, Variable> variableMap, List<String> inputArgs) {
    CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create();
    spec.usageMessage().customSynopsis(synopsis);
    variableMap.forEach((name, variable) -> spec.addOption(getOption(name, variable)));
    CommandLine.ParseResult result = new CommandLine(spec).parseArgs(inputArgs.toArray(new String[0]));
    return variableMap.entrySet().stream().map(kv -> {
        String name = kv.getKey();
        Literal defaultValue = getDefaultValueAsLiteral(name, kv.getValue());
        return Maps.immutableEntry(name, result.matchedOptionValue(name, defaultValue));
    }).collect(toUnmodifiableMap());
}
Also used : List(java.util.List) LiteralType(org.flyte.api.v1.LiteralType) Map(java.util.Map) Literal(org.flyte.api.v1.Literal) Variable(org.flyte.api.v1.Variable) MoreCollectors.toUnmodifiableMap(org.flyte.jflyte.MoreCollectors.toUnmodifiableMap) Maps(com.google.common.collect.Maps) Nullable(javax.annotation.Nullable) CommandLine(picocli.CommandLine) CommandLine(picocli.CommandLine) Literal(org.flyte.api.v1.Literal)

Example 17 with Literal

use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.

the class ProtoWriterTest method shouldWriteOutput.

@Test
void shouldWriteOutput() throws IOException {
    ProtoWriter protoWriter = new ProtoWriter("/home/test/prefix", new InMemoryFileSystem(extension.getFileSystem()));
    Map<String, Literal> outputs = singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("bar"))));
    protoWriter.writeOutputs(outputs);
    Path outputPath = extension.getFileSystem().getPath("/home/test/prefix/outputs.pb");
    Literals.LiteralMap actualOutputs = Literals.LiteralMap.parseFrom(Files.newInputStream(outputPath));
    assertThat(actualOutputs, equalTo(Literals.LiteralMap.newBuilder().putLiterals("foo", Literals.Literal.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("bar").build()).build()).build()).build()));
}
Also used : Path(java.nio.file.Path) Literal(org.flyte.api.v1.Literal) Literals(flyteidl.core.Literals) Test(org.junit.jupiter.api.Test)

Example 18 with Literal

use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.

the class ProtoWriterTest method shouldThrowExceptionWhenNotAbleToWrite.

@Test
void shouldThrowExceptionWhenNotAbleToWrite() {
    ProtoWriter protoWriter = new ProtoWriter("/home/test/prefix", new BrokenFileSystem());
    Map<String, Literal> outputs = singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("bar"))));
    UncheckedIOException exception = assertThrows(UncheckedIOException.class, () -> protoWriter.writeOutputs(outputs));
    assertThat(exception.getMessage(), equalTo("cannot write"));
}
Also used : Literal(org.flyte.api.v1.Literal) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test)

Example 19 with Literal

use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.

the class ProtoReaderTest method shouldReadInputs.

@Test
void shouldReadInputs() throws IOException {
    Literals.LiteralMap input = Literals.LiteralMap.newBuilder().putLiterals("foo", Literals.Literal.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("bar").build()).build()).build()).build();
    Path inputPath = extension.getFileSystem().getPath("/test/input.pb");
    writeProto(input, inputPath);
    ProtoReader protoReader = new ProtoReader(new InMemoryFileSystem(extension.getFileSystem()));
    Map<String, Literal> actual = protoReader.getInput("/test/input.pb");
    assertThat(actual, equalTo(singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("bar"))))));
}
Also used : Path(java.nio.file.Path) Literal(org.flyte.api.v1.Literal) Literals(flyteidl.core.Literals) Test(org.junit.jupiter.api.Test)

Example 20 with Literal

use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.

the class ExecuteLocalArgsParserTest method testParseInputs_dateTime_epochZonedDate.

@Test
public void testParseInputs_dateTime_epochZonedDate() {
    Map<String, Literal> inputs = parseInputs(ImmutableMap.of("datetime", createVar(SimpleType.DATETIME)), new String[] { "--datetime=1970-01-02+01:00" });
    Instant expected = Instant.EPOCH.plus(Duration.ofHours(23));
    assertEquals(ImmutableMap.of("datetime", literalOf(Primitive.ofDatetime(expected))), inputs);
}
Also used : Literal(org.flyte.api.v1.Literal) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Literal (org.flyte.api.v1.Literal)28 Test (org.junit.jupiter.api.Test)16 HashMap (java.util.HashMap)9 Instant (java.time.Instant)7 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)7 LiteralType (org.flyte.api.v1.LiteralType)6 RunnableTask (org.flyte.api.v1.RunnableTask)6 Map (java.util.Map)5 Duration (java.time.Duration)4 List (java.util.List)4 Blob (org.flyte.api.v1.Blob)4 Variable (org.flyte.api.v1.Variable)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Literals (flyteidl.core.Literals)3 Struct (org.flyte.api.v1.Struct)3 Var (com.google.errorprone.annotations.Var)2 UncheckedIOException (java.io.UncheckedIOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Collections.emptyMap (java.util.Collections.emptyMap)2