Search in sources :

Example 6 with Struct

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);
}
Also used : TaskTemplate(org.flyte.api.v1.TaskTemplate) Struct(org.flyte.api.v1.Struct)

Example 7 with Struct

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Struct(org.flyte.api.v1.Struct) Test(org.junit.jupiter.api.Test)

Example 8 with Struct

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))));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Struct(org.flyte.api.v1.Struct) Test(org.junit.jupiter.api.Test)

Example 9 with 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());
}
Also used : ArrayList(java.util.ArrayList) Struct(org.flyte.api.v1.Struct)

Example 10 with Struct

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);
}
Also used : LiteralType(org.flyte.api.v1.LiteralType) BindingData(org.flyte.api.v1.BindingData)

Aggregations

Struct (org.flyte.api.v1.Struct)10 Test (org.junit.jupiter.api.Test)4 Literal (org.flyte.api.v1.Literal)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TaskTemplate (org.flyte.api.v1.TaskTemplate)2 ListValue (com.google.protobuf.ListValue)1 NullValue (com.google.protobuf.NullValue)1 Value (com.google.protobuf.Value)1 Literals (flyteidl.core.Literals)1 LinkedHashMap (java.util.LinkedHashMap)1 BindingData (org.flyte.api.v1.BindingData)1 Blob (org.flyte.api.v1.Blob)1 BlobMetadata (org.flyte.api.v1.BlobMetadata)1 BlobType (org.flyte.api.v1.BlobType)1 ContainerError (org.flyte.api.v1.ContainerError)1 DynamicJobSpec (org.flyte.api.v1.DynamicJobSpec)1 DynamicWorkflowTask (org.flyte.api.v1.DynamicWorkflowTask)1 DynamicWorkflowTaskRegistrar (org.flyte.api.v1.DynamicWorkflowTaskRegistrar)1 LiteralType (org.flyte.api.v1.LiteralType)1