Search in sources :

Example 1 with BlobMetadata

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

the class ProtoUtilTest method shouldSerializeBlob.

@Test
void shouldSerializeBlob() {
    BlobType type = BlobType.builder().dimensionality(BlobType.BlobDimensionality.MULTIPART).format("csv").build();
    BlobMetadata metadata = BlobMetadata.builder().type(type).build();
    Blob blob = Blob.builder().metadata(metadata).uri("file://uri").build();
    Literals.Blob proto = ProtoUtil.serialize(blob);
    assertThat(proto, equalTo(Literals.Blob.newBuilder().setMetadata(Literals.BlobMetadata.newBuilder().setType(Types.BlobType.newBuilder().setDimensionality(Types.BlobType.BlobDimensionality.MULTIPART).setFormat("csv").build())).setUri("file://uri").build()));
}
Also used : BlobType(org.flyte.api.v1.BlobType) Blob(org.flyte.api.v1.Blob) BlobMetadata(org.flyte.api.v1.BlobMetadata) Literals(flyteidl.core.Literals) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with BlobMetadata

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

the class StringUtilTest method shouldSerializeLiteralMap.

@Test
void shouldSerializeLiteralMap() {
    Map<String, Literal> input = new HashMap<>();
    Literal integer = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(1337L)));
    Literal map = Literal.ofMap(singletonMap("b", integer));
    Literal list = Literal.ofCollection(singletonList(integer));
    BlobType type = BlobType.builder().dimensionality(BlobType.BlobDimensionality.MULTIPART).format("csv").build();
    BlobMetadata metadata = BlobMetadata.builder().type(type).build();
    Blob blob = Blob.builder().metadata(metadata).uri("file://test").build();
    input.put("string", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("string"))));
    input.put("integer", integer);
    input.put("float", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofFloatValue(2.0))));
    input.put("boolean", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofBooleanValue(true))));
    input.put("datetime", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofDatetime(Instant.ofEpochSecond(60L)))));
    input.put("duration", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofDuration(Duration.ofSeconds(61)))));
    input.put("list", list);
    input.put("map", map);
    input.put("listOfList", Literal.ofCollection(ImmutableList.of(list, integer)));
    input.put("mapOfMap", Literal.ofMap(ImmutableMap.of("a", map, "c", integer)));
    input.put("struct", Literal.ofScalar(Scalar.ofGeneric(Struct.of(ImmutableMap.<String, Struct.Value>builder().put("bool", Struct.Value.ofBoolValue(true)).put("string", Struct.Value.ofStringValue("string")).put("list", Struct.Value.ofListValue(ImmutableList.of(Struct.Value.ofNumberValue(1)))).put("number", Struct.Value.ofNumberValue(2)).put("null", Struct.Value.ofNullValue()).put("struct", Struct.Value.ofStructValue(Struct.of(ImmutableMap.of()))).build()))));
    input.put("blob", Literal.ofScalar(Scalar.ofBlob(blob)));
    Map<String, String> expected = new HashMap<>();
    expected.put("string", "string");
    expected.put("integer", "1337");
    expected.put("float", "2.0");
    expected.put("boolean", "true");
    expected.put("datetime", "1970-01-01T00:01:00Z");
    expected.put("duration", "PT1M1S");
    expected.put("list", "[1337]");
    expected.put("listOfList", "[[1337], 1337]");
    expected.put("map", "{b=1337}");
    expected.put("mapOfMap", "{a={b=1337}, c=1337}");
    expected.put("struct", "{bool=true, string=string, list=[1.0], number=2.0, null=null, struct={}}");
    expected.put("blob", "{uri=file://test, metadata={type={dimensionality=MULTIPART, format=csv}}}");
    Map<String, String> output = StringUtil.serializeLiteralMap(input);
    assertEquals(expected, output);
}
Also used : BlobType(org.flyte.api.v1.BlobType) Blob(org.flyte.api.v1.Blob) HashMap(java.util.HashMap) BlobMetadata(org.flyte.api.v1.BlobMetadata) Literal(org.flyte.api.v1.Literal) Struct(org.flyte.api.v1.Struct) Test(org.junit.jupiter.api.Test)

Example 3 with BlobMetadata

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

the class ProtoUtil method deserialize.

static Blob deserialize(Literals.Blob blob) {
    BlobType type = BlobType.builder().format(blob.getMetadata().getType().getFormat()).dimensionality(deserialize(blob.getMetadata().getType().getDimensionality())).build();
    BlobMetadata metadata = BlobMetadata.builder().type(type).build();
    return Blob.builder().uri(blob.getUri()).metadata(metadata).build();
}
Also used : BlobType(org.flyte.api.v1.BlobType) BlobMetadata(org.flyte.api.v1.BlobMetadata)

Aggregations

BlobMetadata (org.flyte.api.v1.BlobMetadata)3 BlobType (org.flyte.api.v1.BlobType)3 Blob (org.flyte.api.v1.Blob)2 Test (org.junit.jupiter.api.Test)2 Literals (flyteidl.core.Literals)1 HashMap (java.util.HashMap)1 Literal (org.flyte.api.v1.Literal)1 Struct (org.flyte.api.v1.Struct)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1