-
Notifications
You must be signed in to change notification settings - Fork 177
Introduce RelBuilder wrapper for dynamic fields #4688
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
Introduce RelBuilder wrapper for dynamic fields #4688
Conversation
74dd6b8 to
51d0e4e
Compare
Signed-off-by: Tomoyuki Morita <[email protected]>
51d0e4e to
20e61a1
Compare
Signed-off-by: Tomoyuki Morita <[email protected]>
Signed-off-by: Tomoyuki Morita <[email protected]>
| * direct field access methods to maintain consistency with dynamic fields handling. | ||
| */ | ||
| @RequiredArgsConstructor | ||
| public class RelBuilderWrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just leverage the OpenSearchRelBuilder directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want a derived class of RexBuilder, we can create one as well in OpenSearchPrepareImpl.perform()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I described in the PR description, inheritance didn't work well since there are some internal access within RelBuilder to the methods we want to prohibit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Override all fields of raw RelBuilder in OpenSearchRelBuilder cannot work?
In CalciteRelNodeVisitor, all calling to context.relBuilder.fields/field are interrupted in OpenSearchRelBuilder.fields/field.
But in calcite.RelBuilder, all fields/field will access its raw fields/field method. <=== do you want to prohibit this?
Delegation might not work either. For example, RelBuilder.sort() calls RelBuilder.field(). How to prohibit this calling with delegation class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CalciteRelNodeVisitor, all calling to context.relBuilder.fields/field are interrupted in OpenSearchRelBuilder.fields/field.
But in calcite.RelBuilder, all fields/field will access its raw fields/field method. <=== do you want to prohibit this?
No, inheritance won't work like that. If we override fields/field in a subclass, even the call from calcite.RelBuilder will call the method in subclass.
Delegation might not work either. For example, RelBuilder.sort() calls RelBuilder.field(). How to prohibit this calling with delegation class?
The idea is that, if the method won't work as we expect, customize or prohibit (and provide alternative way) the usage in RelBuilderWrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the simple approach is merging current RelFieldBuilder and OpenSearchRelBuilder. But It's okey that we keep the current RelBuilderWrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think we still need to use RelBuilder or its derived class OpenSearchRelBuilder because RelBuilder will be used in Calcite optimization rules. For example,
| final RelBuilder relBuilder = call.builder(); |
we do have opportunity to get the OpenSearchRelBuilder from call.builder() but no way to get the wrapper.
How about just add dynamic methods in OpenSearchRelBuilder and keep the original field and fields as static field methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Lantao,
Can you revisit my comment?
I think you haven't understood why inheritance won't work.
If we inherit and override method with throwing exception, internal call from other methods in RelBuilder will also fail. And I don't have good idea to workaround this other than reimplementing the method and call super.field instead, which duplicates the implementation from Calcite and not maintainable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, in inheritance, if the method calling chain is A() -> B() -> C(). The overridden method A'() will still call the overridden C'(): A'() -> B() -> C'() .
Can we just add @Deprecated and java doc on the override method to callout this method should not be used in the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion @ykmr1224 . I am okey on the current POC, we can postpone the problem about how to restrict the usage of RelBuilder in optimize rules (Calcite internal).
core/src/main/java/org/opensearch/sql/calcite/plan/PPLAggregateConvertRule.java
Show resolved
Hide resolved
| return relBuilder.peek(n).getRowType().getFieldNames(); | ||
| } | ||
|
|
||
| public RexInputRef staticField(String fieldName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about simplify all staticField to field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named it as staticField so it would be more explicit to access static field.
We want to avoid someone unintentionally omit the existence of dynamic fields.
| * direct field access methods to maintain consistency with dynamic fields handling. | ||
| */ | ||
| @RequiredArgsConstructor | ||
| public class RelBuilderWrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Override all fields of raw RelBuilder in OpenSearchRelBuilder cannot work?
In CalciteRelNodeVisitor, all calling to context.relBuilder.fields/field are interrupted in OpenSearchRelBuilder.fields/field.
But in calcite.RelBuilder, all fields/field will access its raw fields/field method. <=== do you want to prohibit this?
Delegation might not work either. For example, RelBuilder.sort() calls RelBuilder.field(). How to prohibit this calling with delegation class?
8fe17a0
into
opensearch-project:feature/permissive
This PR is for feature branch
feature/permissiveDescription
fieldorfieldsmethods and inheritance cannot prohibit access to some methods.Related Issues
Permissive mode RFC: #4349
Dynamic fields RFC: #4433
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.