Skip to content

Commit

Permalink
[go] Add blob support for MakeLiteralForType (flyteorg#131)
Browse files Browse the repository at this point in the history
The MakeLiteralForType client method currently doesn't support the blob type. This adds support for that.

Signed-off-by: Sam Lai <[email protected]>
  • Loading branch information
slai authored Mar 30, 2021
1 parent 243bee9 commit 0ebee65
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clients/go/coreutils/extract_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func ExtractFromLiteral(literal *core.Literal) (interface{}, error) {
case *core.Primitive_Duration:
scalarPrimitiveDuration := scalarPrimitive.Duration
return scalarPrimitiveDuration, nil
default:
return nil, fmt.Errorf("unsupported literal scalar primitive type %T", scalarValue)
}
case *core.Scalar_Blob:
return scalarValue.Blob.Uri, nil
default:
return nil, fmt.Errorf("unsupported literal scalar type %T", scalarValue)
}
case *core.Literal_Collection:
Expand Down
5 changes: 5 additions & 0 deletions clients/go/coreutils/literals.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ func MakeLiteralForType(t *core.LiteralType, v interface{}) (*core.Literal, erro
return nil, err
}
return lv, nil
case *core.LiteralType_Blob:
newT := t.Type.(*core.LiteralType_Blob)
isDir := newT.Blob.Dimensionality == core.BlobType_MULTIPART
lv := MakeLiteralForBlob(storage.DataReference(fmt.Sprintf("%v", v)), isDir, newT.Blob.Format)
return lv, nil
default:
return nil, fmt.Errorf("unsupported type %s", t.String())
}
Expand Down
56 changes: 56 additions & 0 deletions clients/go/coreutils/literals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,62 @@ func TestMakeLiteralForType(t *testing.T) {
assert.Equal(t, expectedVal, actualVal)
})

t.Run("Blob", func(t *testing.T) {
var literalType = &core.LiteralType{Type: &core.LiteralType_Blob{Blob: &core.BlobType{
Dimensionality: core.BlobType_SINGLE,
}}}
expectedLV := &core.Literal{Value: &core.Literal_Scalar{Scalar: &core.Scalar{
Value: &core.Scalar_Blob{
Blob: &core.Blob{
Uri: "s3://blah/blah/blah",
Metadata: &core.BlobMetadata{
Type: &core.BlobType{
Dimensionality: core.BlobType_SINGLE,
},
},
},
},
}}}
lv, err := MakeLiteralForType(literalType, "s3://blah/blah/blah")
assert.NoError(t, err)

assert.Equal(t, expectedLV, lv)

expectedVal, err := ExtractFromLiteral(expectedLV)
assert.NoError(t, err)
actualVal, err := ExtractFromLiteral(lv)
assert.NoError(t, err)
assert.Equal(t, expectedVal, actualVal)
})

t.Run("MultipartBlob", func(t *testing.T) {
var literalType = &core.LiteralType{Type: &core.LiteralType_Blob{Blob: &core.BlobType{
Dimensionality: core.BlobType_MULTIPART,
}}}
expectedLV := &core.Literal{Value: &core.Literal_Scalar{Scalar: &core.Scalar{
Value: &core.Scalar_Blob{
Blob: &core.Blob{
Uri: "s3://blah/blah/blah",
Metadata: &core.BlobMetadata{
Type: &core.BlobType{
Dimensionality: core.BlobType_MULTIPART,
},
},
},
},
}}}
lv, err := MakeLiteralForType(literalType, "s3://blah/blah/blah")
assert.NoError(t, err)

assert.Equal(t, expectedLV, lv)

expectedVal, err := ExtractFromLiteral(expectedLV)
assert.NoError(t, err)
actualVal, err := ExtractFromLiteral(lv)
assert.NoError(t, err)
assert.Equal(t, expectedVal, actualVal)
})

t.Run("UnsupportedType", func(t *testing.T) {
var literalType = &core.LiteralType{Type: &core.LiteralType_Schema{
Schema: &core.SchemaType{}}}
Expand Down

0 comments on commit 0ebee65

Please sign in to comment.