Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Literal Transformations from a string or an interface based on literalTypes #120

Merged
merged 3 commits into from
Mar 17, 2021

Conversation

kumare3
Copy link
Contributor

@kumare3 kumare3 commented Mar 16, 2021

Signed-off-by: Ketan Umare [email protected]

TL;DR

Supports converting to flyte literal from string/interface based simple type or an [] interface for collection and map[string] interface for map type. This is useful for flytectl eg in creating executions where the task/workflow params /variables and there types are know with there definitions and the input is in form of string / yaml structure.

MakeLiteralForType(t *core.LiteralType, v interface{}) (*core.Literal, error)

The input value v can be converted to the flyte Literal using the type definition t. If the conversion is not possible it would throw an error.

Earlier code would support string to SimpleType conversion using
MakeLiteralForSimpleType(t core.SimpleType, s string) (*core.Literal, error)
The following PR wraps this to support LiteralType_MapValueType and LiteralType_CollectionType
Support for LiteralType_Blob and LiteralType_Schema would be added as a followup.

At the top level following value types are supported without type erasure.
interface{} -> SimpleType map[string]interface{} -> MapValueType []interface{} - CollectionType
An input value not adhering to these types would be rejected.
eg :
strArray := map[string][]interface{}{"hello1": {"world11", "world12"}, "hello2": {"world21", "world22"}}
wont be supported since map[string][]interface isn't a direct type supported for converting to literal.

Instead the same input can be given using type erasure to its supported type.

               createList1 := func() interface{} {
			return []interface{}{"world11", "world12"}
		}
		createList2 := func() interface{} {
			return []interface{}{"world21", "world22"}
		}
		strArray := map[string]interface{}{"hello1": createList1(), "hello2": createList2()}

This allows for complex type conversion

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

Complete description

How did you fix the bug, make the feature etc. Link to any design docs etc

Tracking Issue

flyteorg/flyte#316

Follow-up issue

flyteorg/flyte#316

kumare3 and others added 2 commits March 15, 2021 22:12
Signed-off-by: Ketan Umare <[email protected]>
…122)

Signed-off-by: pmahindrakar-oss <[email protected]>

Co-authored-by: pmahindrakar-oss <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
@kumare3 kumare3 force-pushed the more-literate-generator branch from 528d45e to 4f61bdf Compare March 17, 2021 04:00
@kumare3 kumare3 changed the title wip: more transformations Literal Transformations from a string or an interface based on literalTypes Mar 17, 2021
…124)

* Changed the String formatter from %s to %v and added more unit tests

Signed-off-by: pmahindrakar-oss <[email protected]>

* Added unsupported type default condition

Signed-off-by: pmahindrakar-oss <[email protected]>

Co-authored-by: pmahindrakar-oss <[email protected]>
Signed-off-by: pmahindrakar-oss <[email protected]>
@pmahindrakar-oss pmahindrakar-oss force-pushed the more-literate-generator branch from 334cd39 to f2ce9eb Compare March 17, 2021 06:00
@kumare3 kumare3 merged commit d514c56 into master Mar 17, 2021
eapolinario pushed a commit that referenced this pull request Sep 8, 2023
…lTypes (#120)

* wip: more transformations

Signed-off-by: Ketan Umare <[email protected]>

* Changed the String formatter from %s to %v and added more unit tests (#122)

Signed-off-by: pmahindrakar-oss <[email protected]>

Co-authored-by: pmahindrakar-oss <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>

* Added default condition for unsupported type while creating literal (#124)

* Changed the String formatter from %s to %v and added more unit tests

Signed-off-by: pmahindrakar-oss <[email protected]>

* Added unsupported type default condition

Signed-off-by: pmahindrakar-oss <[email protected]>

Co-authored-by: pmahindrakar-oss <[email protected]>
Signed-off-by: pmahindrakar-oss <[email protected]>

Co-authored-by: pmahindrakar-oss <[email protected]>
Co-authored-by: pmahindrakar-oss <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants