Skip to content

ARROW-6266: [Java] Resolve the ambiguous method overload in RangeEqualsVisitor#5100

Closed
liyafan82 wants to merge 2 commits intoapache:masterfrom
liyafan82:fly_0816_visit
Closed

ARROW-6266: [Java] Resolve the ambiguous method overload in RangeEqualsVisitor#5100
liyafan82 wants to merge 2 commits intoapache:masterfrom
liyafan82:fly_0816_visit

Conversation

@liyafan82
Copy link
Copy Markdown
Contributor

In RangeEqualsVisitor, there are overload methods for both super class and sub class. This will lead to unexpected behavior.

For example, if we call RangeEqualsVisitor#visit(v), where v is a fixed width vector, the method actually called may be visit(ValueVector), which is unexpected.

In general, in the visitor pattern, it is not a good idea to support method overload for both super class and sub-class as parameters.

@liyafan82
Copy link
Copy Markdown
Contributor Author

cc @tianchen92

Copy link
Copy Markdown
Contributor

@tianchen92 tianchen92 left a comment

Choose a reason for hiding this comment

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

Thanks @liyafan82 , LGTM.

@Override
public boolean accept(RangeEqualsVisitor visitor) {
return visitor.visit(getUnderlyingVector());
return visitor.visitGeneral(getUnderlyingVector());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we instead do -

return getUnderlyingVector().accept(visitor)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is also ok, and then should remove RangeEqualsVisitor#visit(ValueVector left, Void value).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for correction, if we don't have visitGeneral I think the API below will throw exception

public boolean equals(ValueVector left) {
return this.visit(left, null);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The method suggested by @pravindra works. With the suggested change, method visit(ValueVector left) can be removed altogether.

@pravindra pravindra closed this in e994e9c Aug 19, 2019
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…lsVisitor

In RangeEqualsVisitor, there are overload methods for both super class and sub class. This will lead to unexpected behavior.

For example, if we call RangeEqualsVisitor#visit(v), where v is a fixed width vector, the method actually called may be visit(ValueVector), which is unexpected.

In general, in the visitor pattern, it is not a good idea to support method overload for both super class and sub-class as parameters.

Closes apache#5100 from liyafan82/fly_0816_visit and squashes the following commits:

6b5e5c5 <liyafan82>  Remove the general visit mothod
f7ed538 <liyafan82>  Resolve the ambiguous method overload in RangeEqualsVisitor

Authored-by: liyafan82 <fan_li_ya@foxmail.com>
Signed-off-by: Pindikura Ravindra <ravindra@dremio.com>
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.

3 participants