-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Flyte][3][flytepropeller][Attribute Access][flytectl] Binary IDL With MessagePack #5763
Changes from 7 commits
c0bc45f
c9616ca
6e6d449
267852b
626f9c3
f68f75c
52a7595
548fdba
b306b4b
c8dd0a0
34914db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
package coreutils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math" | ||
"reflect" | ||
|
@@ -14,11 +13,14 @@ import ( | |
"github.com/golang/protobuf/ptypes" | ||
structpb "github.com/golang/protobuf/ptypes/struct" | ||
"github.com/pkg/errors" | ||
"github.com/shamaton/msgpack/v2" | ||
|
||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/flyteorg/flyte/flytestdlib/storage" | ||
) | ||
|
||
const messagepack = "msgpack" | ||
|
||
func MakePrimitive(v interface{}) (*core.Primitive, error) { | ||
switch p := v.(type) { | ||
case int: | ||
|
@@ -144,6 +146,7 @@ func MakeBinaryLiteral(v []byte) *core.Literal { | |
Value: &core.Scalar_Binary{ | ||
Binary: &core.Binary{ | ||
Value: v, | ||
Tag: messagepack, | ||
}, | ||
}, | ||
}, | ||
|
@@ -389,7 +392,7 @@ func MakeLiteralForSimpleType(t core.SimpleType, s string) (*core.Literal, error | |
scalar.Value = &core.Scalar_Binary{ | ||
Binary: &core.Binary{ | ||
Value: []byte(s), | ||
// TODO Tag not supported at the moment | ||
Tag: messagepack, | ||
}, | ||
} | ||
case core.SimpleType_ERROR: | ||
|
@@ -559,12 +562,35 @@ func MakeLiteralForType(t *core.LiteralType, v interface{}) (*core.Literal, erro | |
strValue = fmt.Sprintf("%.0f", math.Trunc(f)) | ||
} | ||
if newT.Simple == core.SimpleType_STRUCT { | ||
// If the type is a STRUCT, we expect the input to be a complex object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this not break if the clients or otherside have the old view of struct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will not break |
||
// like the following example: | ||
// inputs: | ||
// dc: | ||
// a: 1 | ||
// b: 3.14 | ||
// c: "example_string" | ||
// Instead of storing it directly as a structured value, we will serialize | ||
// the input object using MsgPack and return it as a binary IDL object. | ||
|
||
// If the value is not already a string (meaning it's not already serialized), | ||
// proceed with serialization. | ||
if _, isValueStringType := v.(string); !isValueStringType { | ||
byteValue, err := json.Marshal(v) | ||
byteValue, err := msgpack.Marshal(v) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to marshal to json string for struct value %v", v) | ||
} | ||
strValue = string(byteValue) | ||
return &core.Literal{ | ||
Value: &core.Literal_Scalar{ | ||
Scalar: &core.Scalar{ | ||
Value: &core.Scalar_Binary{ | ||
Binary: &core.Binary{ | ||
Value: byteValue, | ||
Tag: messagepack, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} | ||
} | ||
lv, err := MakeLiteralForSimpleType(newT.Simple, strValue) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tested here.
https://github.com/flyteorg/flyte/pull/5763/files#diff-288b2f7bad6b7d9d1e9540d1d0d2d33fd6fac4a3d461d5f0769f15e86a069050R458-R468