hi team, I have this PR to support Union type in f...
# contribute
y
hi team, I have this PR to support Union type in flyteidl. https://github.com/flyteorg/flyteidl/pull/401 However, i do have a few questions related to what I should generate when making the default value for Union types. Currently I am generating it as a Union Scalar with the first type available. However, I can also just generate the the literal for the type itself. Wondering if that make a difference when user creating the task using simple types but task is defined as Union type. An example:
Copy code
@task
def task(a: Union[Integer, Float]):
and then I am current generating default value as Union scalar literal:
Copy code
x:
        value:
            value:
                scalar:
                    value:
                        primitive:
                            value:
                                integer: 0
                            xxx_nounkeyedliteral: {}
                            xxx_unrecognized: []
                            xxx_sizecache: 0
                    xxx_nounkeyedliteral: {}
                    xxx_unrecognized: []
                    xxx_sizecache: 0
            hash: ""
            xxx_nounkeyedliteral: {}
            xxx_unrecognized: []
            xxx_sizecache: 0
        type:
            type:
                simple: 1
            metadata: null
            annotation: null
            structure:
                tag: int
                xxx_nounkeyedliteral: {}
                xxx_unrecognized: []
                xxx_sizecache: 0
            xxx_nounkeyedliteral: {}
            xxx_unrecognized: []
            xxx_sizecache: 0
        xxx_nounkeyedliteral: {}
        xxx_unrecognized: []
        xxx_sizecache: 0
or I can generate default as simple integer literal like this:
Copy code
"x": 0
@Dan Rammer (hamersaw) @Ketan (kumare3) @Kevin Su
so from my understanding is that the type extracted from literal will be different,
k
Currently I am generating it as a Union Scalar with the first type available
yes, I think it’s fine because
MakeDefaultLiteralForType
is only used in the tests.
```@task
def task(a: Union[Integer, Float]):```
flytekit always expects
a
is a Union scalar literal
y
cool, thanks, but why does the scalar contains so many other fields like
xxx_unrecognized: []
MakeDefaultLiteralForType is used by flytectl to create execFile right?
b
same q ^^
it think its auto generated by protobuf?
k
oh, sorry. I though it’s only used in idl. looking the code in flytectl. that’s auto generated by protobuf
y
so when I extract from a Union Literal, should I just get the actual value inside the union or the union type defined here https://github.com/flyteorg/flyteidl/blob/44b6bc64337cb40b08865ab6c1c8762f4d9619e4/protos/flyteidl/core/literals.proto#L56
because I see schema are extracted with URI
oh I think I figured it out
159 Views