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());
}
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()));
}
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"));
}
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"))))));
}
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);
}
Aggregations