Skip to content
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

[WIP][DO NOT MERGE] Remove LiteralTypeForLiteral by creating IsInstance function #5909

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Mecoli1219
Copy link

@Mecoli1219 Mecoli1219 commented Oct 24, 2024

Tracking issue

#5908

Why are the changes needed?

The current Tuple IDL design is complicated by this function since if we want to guess the LiteralType from Literal, we have to store the name of the tuple and the name of each field inside the tuple in the Literal.

However, guessing the LiteralType is not necessary for Flyte since whenever we create a new literal, there must be a target type (maybe inputs or outputs, but they will always have a defined type). Also, almost all use cases of LiteralTypeForLiteral are followed by a function AreTypesCastable, we could simply combine these two functions into a function determining whether a Literal could be instantiated by a LiteralType. It is really similar to isinstance() function in Python.

What changes were proposed in this pull request?

  • I created an IsInstance() for the flytepropeller to check whether a Literal could be represented by a LiteralType.
  • Remove LiteralTypeForLiteral and update all necessary code in FlyteAdmin & FlytePropeller.
  • Update the unit tests
    • Change unit tests for LiteralTypeForLiteral to IsInstance
    • Update the error message for other cases.

How was this patch tested?

  • Unit testing
  • Built and run some Flytekit test

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Additional Concerns

Someone suggested that we shouldn't merge this PR before the release

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 22.23%. Comparing base (f20b8aa) to head (715d830).
Report is 1 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (f20b8aa) and HEAD (715d830). Click for more details.

HEAD has 7 uploads less than BASE
Flag BASE (f20b8aa) HEAD (715d830)
unittests-flyteidl 1 0
unittests-datacatalog 1 0
unittests-flytectl 1 0
unittests-flytestdlib 1 0
unittests-flyteplugins 1 0
unittests-flytepropeller 1 0
unittests-flyteadmin 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5909       +/-   ##
===========================================
- Coverage   36.95%   22.23%   -14.73%     
===========================================
  Files        1310        8     -1302     
  Lines      131464      796   -130668     
===========================================
- Hits        48587      177    -48410     
+ Misses      78656      591    -78065     
+ Partials     4221       28     -4193     
Flag Coverage Δ
unittests-datacatalog ?
unittests-flyteadmin ?
unittests-flytecopilot 22.23% <ø> (ø)
unittests-flytectl ?
unittests-flyteidl ?
unittests-flyteplugins ?
unittests-flytepropeller ?
unittests-flytestdlib ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Future-Outlier Future-Outlier changed the title [DO NOT MERGE] Remove LiteralTypeForLiteral by creating IsInstance function [WIP][DO NOT MERGE] Remove LiteralTypeForLiteral by creating IsInstance function Oct 24, 2024
Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test every test case be affected in flytekit remote?
and provide screenshot?
I think this function is not well tested by unit test and integration test.

if _, ok := lit.GetValue().(*core.Literal_Collection); !ok {
return false
}
for _, x := range lit.GetCollection().Literals {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add the tuple literal type but still represent the literal as a collection, how do we check if this collection is a tuple or not

Copy link
Author

@Mecoli1219 Mecoli1219 Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of Literal for tuple will be Literal_Collection, but the LiteralType won't. We'll have to create another new InstanceChecker (perhaps tupleInstanceChecker) to deal with that.

func IsInstance(lit *core.Literal, t *core.LiteralType) bool {
instanceChecker := getInstanceChecker(t)

if lit.GetOffloadedMetadata() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd add a condition here to make sure the field is actually present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry incomplete review... will get back to this later.

Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
@Mecoli1219
Copy link
Author

@Future-Outlier I tested the IsInstance with the flytekit's unit tests and integration tests. I couldn't run eager in my environment, and it is not related to this update. Besides that, all test works successfully.
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

4 participants