use of org.flyte.api.v1.Struct in project flytekit-java by flyteorg.
the class ProjectClosure method applyCustom.
private static TaskSpec applyCustom(TaskSpec taskSpec, JFlyteCustom custom) {
Struct rewrittenCustom = merge(custom.serializeToStruct(), taskSpec.taskTemplate().custom());
TaskTemplate rewrittenTaskTemplate = taskSpec.taskTemplate().toBuilder().custom(rewrittenCustom).build();
return TaskSpec.create(rewrittenTaskTemplate);
}
use of org.flyte.api.v1.Struct in project flytekit-java by flyteorg.
the class SdkStructTest method shouldConvertToStruct.
@Test
void shouldConvertToStruct() {
List<Struct.Value> values = new ArrayList<>();
values.add(Struct.Value.ofNumberValue(1.0));
values.add(Struct.Value.ofNumberValue(2.0));
values.add(Struct.Value.ofNumberValue(3.0));
Map<String, Struct.Value> inner = new HashMap<>();
inner.put("stringValue", Struct.Value.ofStringValue("string"));
Map<String, Struct.Value> fields = new HashMap<>();
fields.put("stringValue", Struct.Value.ofStringValue("string"));
fields.put("boolValue", Struct.Value.ofBoolValue(true));
fields.put("integerValue", Struct.Value.ofNumberValue(42));
fields.put("listValue", Struct.Value.ofListValue(values));
fields.put("nullValue", Struct.Value.ofNullValue());
fields.put("structValue", Struct.Value.ofStructValue(Struct.of(inner)));
Struct expected = Struct.of(fields);
SdkStruct sdkStruct = SdkStruct.builder().addStringField("stringValue", "string").addBooleanField("boolValue", true).addIntegerField("integerValue", 42L).addIntegerField("nullValue", null).addIntegerCollectionField("listValue", Arrays.asList(1L, 2L, 3L)).addStructField("structValue", SdkStruct.builder().addStringField("stringValue", "string").build()).build();
assertThat(sdkStruct.struct(), equalTo(expected));
}
use of org.flyte.api.v1.Struct in project flytekit-java by flyteorg.
the class SdkBindingDataTest method testOfStruct.
@Test
public void testOfStruct() {
Map<String, Struct.Value> structFields = new LinkedHashMap<>();
Map<String, Struct.Value> structFieldsNested = new LinkedHashMap<>();
structFields.put("a", Struct.Value.ofBoolValue(true));
structFields.put("b", Struct.Value.ofStructValue(Struct.of(structFieldsNested)));
structFieldsNested.put("b_nested", Struct.Value.ofNumberValue(42));
Struct expected = Struct.of(structFields);
SdkStruct input = SdkStruct.builder().addBooleanField("a", true).addStructField("b", SdkStruct.builder().addIntegerField("b_nested", 42L).build()).build();
SdkBindingData output = SdkBindingData.ofStruct(input);
assertThat(output, equalTo(SdkBindingData.create(BindingData.ofScalar(Scalar.ofGeneric(expected)), LiteralType.ofSimpleType(SimpleType.STRUCT))));
}
use of org.flyte.api.v1.Struct in project flytekit-java by flyteorg.
the class LiteralMapDeserializer method readValueAsStructValue.
private static Struct.Value readValueAsStructValue(JsonParser p) throws IOException {
switch(p.currentToken()) {
case START_ARRAY:
p.nextToken();
List<Struct.Value> valuesList = new ArrayList<>();
while (p.currentToken() != JsonToken.END_ARRAY) {
Struct.Value value = readValueAsStructValue(p);
p.nextToken();
valuesList.add(value);
}
return Struct.Value.ofListValue(unmodifiableList(valuesList));
case START_OBJECT:
Struct struct = readValueAsStruct(p);
return Struct.Value.ofStructValue(struct);
case VALUE_STRING:
String stringValue = p.readValueAs(String.class);
return Struct.Value.ofStringValue(stringValue);
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
Double doubleValue = p.readValueAs(Double.class);
return Struct.Value.ofNumberValue(doubleValue);
case VALUE_NULL:
return Struct.Value.ofNullValue();
case VALUE_FALSE:
return Struct.Value.ofBoolValue(false);
case VALUE_TRUE:
return Struct.Value.ofBoolValue(true);
case FIELD_NAME:
case NOT_AVAILABLE:
case VALUE_EMBEDDED_OBJECT:
case END_ARRAY:
case END_OBJECT:
throw new IllegalStateException("Unexpected token: " + p.currentToken());
}
throw new AssertionError("Unexpected token: " + p.currentToken());
}
use of org.flyte.api.v1.Struct in project flytekit-java by flyteorg.
the class SdkBindingData method ofStruct.
public static SdkBindingData ofStruct(SdkStruct struct) {
BindingData bindingData = BindingData.ofScalar(Scalar.ofGeneric(struct.struct()));
LiteralType literalType = LiteralType.ofSimpleType(SimpleType.STRUCT);
return create(bindingData, literalType);
}
Aggregations