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

feat: Add ChangeMapping interface to relations #71

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

EpsilonPrime
Copy link
Member

@EpsilonPrime EpsilonPrime commented Nov 20, 2024

ChangeMapping is an alternative to the current Remap variants currently found on the Builder interface. It preserves the existing behavior including checking the proposed mapping for validity. It also modifies the relation instead of returning a copy. All of the existing Remap function variants have been marked as deprecated in favor of ChangeMapping.

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 96.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 59.56%. Comparing base (812f62c) to head (eeb3f91).

Files with missing lines Patch % Lines
plan/relations.go 96.15% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #71      +/-   ##
==========================================
+ Coverage   59.14%   59.56%   +0.41%     
==========================================
  Files          43       43              
  Lines        9221     9298      +77     
==========================================
+ Hits         5454     5538      +84     
+ Misses       3523     3516       -7     
  Partials      244      244              

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

plan/relations.go Outdated Show resolved Hide resolved
plan/plan.go Outdated
@@ -275,6 +275,7 @@ type Rel interface {
// record type from the output RecordType of the underlying Relation.
// If the output mapping is nil, then this just returns the input
// type.
// TODO - Rename this ApplyMap.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add api to interface.

Also, I think we should be copying, not overwriting. Overwriting/mutating nodes in a plan can be dangerous given the possibility of duplicated subplans, etc.

Maybe call CopyWithRemap() or similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Remap doesn't really make sense on write relations so I specifically created an alternative interface.

I'm less inclined to worry about copying as these are more of a build time artifact (i.e. not protos). If one wants to duplicate a subplan that should do the copying.

Copy link
Contributor

Choose a reason for hiding this comment

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

I specifically created an alternative interface.

I don't see the interface. What is it?

I'm less inclined to worry about copying

I think we should prefer immutability generally. Having worked on this type of pattern before, I think that will reduce future problems and mistakes.

plan/relations.go Outdated Show resolved Hide resolved
@EpsilonPrime EpsilonPrime marked this pull request as ready for review November 28, 2024 00:38
@@ -741,6 +776,12 @@ func (j *JoinRel) CopyWithExpressionRewrite(rewriteFunc RewriteFunc, newInputs .
return &join, nil
}

func (j *JoinRel) ChangeMapping(mapping []int32) error {
newMapping, err := ChangeMapping(j, mapping)
j.mapping = newMapping
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is an error, we lose the old mapping if I reading this right. If err, I would expect no change.

//
// If any column numbers specified are outside the currently available input
// range an error is returned and the mapping is left unchanged.
ChangeMapping(mapping []int32) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have this make a copy as opposed to an inplace edit?

I'm also more OverlayMapping or ApplyMapping as a name.

Also, would be good to use vararg.

@@ -271,6 +271,16 @@ type Rel interface {
// result should be 3 columns consisting of the 5th, 2nd and 1st
// output columns from the underlying relation.
OutputMapping() []int32
// ClearMapping resets the mapping for this relation.
ClearMapping()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should add this.

@@ -271,6 +271,16 @@ type Rel interface {
// result should be 3 columns consisting of the 5th, 2nd and 1st
// output columns from the underlying relation.
OutputMapping() []int32
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should deprecate this.

Copy link
Contributor

Choose a reason for hiding this comment

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

On second, thought, maybe not deprecate. Let's just update to be a defensive copy.

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

Successfully merging this pull request may close these issues.

2 participants