From c7c82ac70946cff2027411ba38e272ae48bb14c2 Mon Sep 17 00:00:00 2001 From: Future-Outlier Date: Thu, 8 Aug 2024 19:31:36 +0800 Subject: [PATCH] Create Execution Success, need to implement get Execution Signed-off-by: Future-Outlier --- flytectl/go.mod | 2 ++ flytectl/go.sum | 4 ++++ .../clients/go/coreutils/extract_literal.go | 2 +- flyteidl/clients/go/coreutils/literals.go | 22 +++++++++++++++---- flyteidl/go.mod | 2 ++ flyteidl/go.sum | 4 ++++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/flytectl/go.mod b/flytectl/go.mod index 9e4baeea63..f0bba9f2f8 100644 --- a/flytectl/go.mod +++ b/flytectl/go.mod @@ -150,6 +150,8 @@ require ( github.com/spf13/viper v1.11.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/subosito/gotenv v1.2.0 // indirect + github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect + github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect diff --git a/flytectl/go.sum b/flytectl/go.sum index 1e3b5d7ef8..5b76bf5814 100644 --- a/flytectl/go.sum +++ b/flytectl/go.sum @@ -457,6 +457,10 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/flyteidl/clients/go/coreutils/extract_literal.go b/flyteidl/clients/go/coreutils/extract_literal.go index d3b38816dc..3edb31d5a5 100644 --- a/flyteidl/clients/go/coreutils/extract_literal.go +++ b/flyteidl/clients/go/coreutils/extract_literal.go @@ -63,7 +63,7 @@ func ExtractFromLiteral(literal *core.Literal) (interface{}, error) { case *core.Scalar_StructuredDataset: return scalarValue.StructuredDataset.Uri, nil case *core.Scalar_Json: - return scalarValue.Json.Value, nil + return scalarValue.Json, nil case *core.Scalar_Union: // extract the value of the union but not the actual union object extractedVal, err := ExtractFromLiteral(scalarValue.Union.Value) diff --git a/flyteidl/clients/go/coreutils/literals.go b/flyteidl/clients/go/coreutils/literals.go index 65780fbea7..c2962d7cda 100644 --- a/flyteidl/clients/go/coreutils/literals.go +++ b/flyteidl/clients/go/coreutils/literals.go @@ -4,19 +4,19 @@ package coreutils import ( "encoding/json" "fmt" + "github.com/vmihailenco/msgpack/v5" "math" "reflect" "strconv" "strings" "time" + "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" + "github.com/flyteorg/flyte/flytestdlib/storage" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/ptypes" structpb "github.com/golang/protobuf/ptypes/struct" "github.com/pkg/errors" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" - "github.com/flyteorg/flyte/flytestdlib/storage" ) func MakePrimitive(v interface{}) (*core.Primitive, error) { @@ -256,7 +256,7 @@ func MakeDefaultLiteralForType(typ *core.LiteralType) (*core.Literal, error) { Scalar: &core.Scalar{ Value: &core.Scalar_Json{ Json: &core.Json{ - Value: []byte("{}"), + Value: []byte(""), }, }, }, @@ -398,6 +398,7 @@ func MakeLiteralForSimpleType(t core.SimpleType, s string) (*core.Literal, error Generic: st, } case core.SimpleType_JSON: + fmt.Println("@@@ JSON STRING: ", s) scalar.Value = &core.Scalar_Json{ Json: &core.Json{ Value: []byte(s), @@ -585,6 +586,19 @@ func MakeLiteralForType(t *core.LiteralType, v interface{}) (*core.Literal, erro strValue = string(byteValue) } } + if newT.Simple == core.SimpleType_JSON { + if _, isValueStringType := v.(string); !isValueStringType { + jsonBytes, err := json.Marshal(v) + if err != nil { + return nil, fmt.Errorf("unable to marshal to json string for json value %v", v) + } + jsonBytes, err = msgpack.Marshal(jsonBytes) + if err != nil { + return nil, fmt.Errorf("unable to marshal to msgpack bytes for json value %v", v) + } + strValue = string(jsonBytes) + } + } lv, err := MakeLiteralForSimpleType(newT.Simple, strValue) if err != nil { return nil, err diff --git a/flyteidl/go.mod b/flyteidl/go.mod index 55ec124554..65bf6dc392 100644 --- a/flyteidl/go.mod +++ b/flyteidl/go.mod @@ -83,6 +83,8 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/stretchr/objx v0.5.2 // indirect + github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect + github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect diff --git a/flyteidl/go.sum b/flyteidl/go.sum index 5d5cb7e9a2..25d4cc402d 100644 --- a/flyteidl/go.sum +++ b/flyteidl/go.sum @@ -241,6 +241,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=