-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7122] Eliminate nested calls for idempotent unary functions UPPER/LOWER/ABS/INITCAP #4577
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
Conversation
|
This is not a ready PR, just a suggestion. |
|
Could be a valid approach. It's aligned with already existing aspects like "deterministic" and "dynamic". |
Yes, I think we can continue to integrate or refactor this later. The current PR is mainly intended to share an initial idea. If you'd like me to further improve it, please let me know — I'm not sure if the original author has time to continue working on their PR. |
9e521ca to
16f3f6f
Compare
|
I updated the test case and forced submission. It is currently in the ready state. If the original author continues his work, I will close this PR. |
I have filed a jira CALCITE-7224 to record it. |
16f3f6f to
b9bde4f
Compare
| getReturnTypeInference(), getOperandTypeInference(), operandHandler, | ||
| getOperandTypeChecker(), callValidator, | ||
| getFunctionType(), monotonicityInference, dynamic); | ||
| getFunctionType(), monotonicityInference, dynamic, idempotent); |
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 keep the constructor version with a default value of 'false' for this argument?
One alternative is to define a new enum { IDEMPOTENT, NONIDEMPOTENT } instead of using boolean.
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 didn't quite understand your comment. Here, a similar function to "copy" requires ensuring idempotency with previously set values.
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 have several comments.
you have changed lots of constructor invocations.
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 added a new constructor and restored the previously modified create method. Is this the modification you meant?
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
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.
IMO a (new) boolean flag makes more sense considering the already existing flag (deterministic, dynamic). Modifying the constructors is the way to ensure backwards compatibility and avoid breaking consumers.
Whenever we tackle CALCITE-7224, we could deprecate all the constructors using the several flags (with the classic "to be removed before 2.0" comment), and create a single one with a unified flag 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.
@rubenada Indeed, using a boolean type aligns with the current design, which is why I used a boolean type in the first version. Using an enum type does break this pattern, but it more clearly indicates whether it is idempotent or non-idempotent. Since I have created a Jira ticket to refactor this boolean value, both approaches seem less critical at this point. I have two solutions: one is to complete the refactoring work in that Jira ticket first and then finish this PR. The other is, if @mihaibudiu agrees to revert to using a boolean type, I can also roll back the code and complete this PR first.
mihaibudiu
left a comment
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.
This is fine, but many Boolean flags will be hard to manage.
I think having them separate is still necessary, because they are independent.
The only thing I can think of is to give them different artificial enum types.
@mihaibudiu I have filed a jira CALCITE-7224, and can be processed together with existing deterministic and dynamic follow-ups. The current implementation retains the same style for now. |
|
Yes, I saw that, but that may require changing signatures for these functions... |
I'd like to confirm whether you're suggesting that using an enum containing two attributes, IDEMPOTENT and NONIDEMPOTENT, is a better approach in the current implementation, without having to worry about the original implementation style for now? Are you considering refactoring in the future? |
|
Yes, I think that once you make them Boolean, you can't change them to something else. |
I agree with your suggestion. Since refactoring may not happen immediately, we can first implement the new feature to an ideal state. I will later change it to an enum type. |
|
I have changed my mind, I don't think this is an ideal design for two reasons:
|
I don't entirely agree with your perspective. On the contrary, I believe adding possible function properties to |
|
Hi @mihaibudiu, do you also think the function property of idempotency is too niche and not suitable for inclusion as a common property? If that is your point, I agree with your perspective. However, if we set aside its limited applicability, properties like determinism, dynamism, and monotonicity are already maintained as common attributes in this manner, so I believe this approach is reasonable. |
|
It's not really about niche and non-niche, in general the number of algebraic properties you may look for when optimizing is unbounded. It is not sustainable to modify all objects to represent such properties; that's exactly what the visitor pattern is designed to solve. |
I think we might be discussing how to refactor the function attribute system, which seems unrelated to the purpose of this PR. Since using boolean types as attribute identifiers is already an existing practice, should we accept extending it in the same way? If our final conclusion is not to agree, this PR could be temporarily closed, and the discussion on refactoring function attributes could continue in the new Jira ticket. What do you think? |
|
You can leave the PR open and move the discussion to JIRA. |
…UPPER/LOWER/ABS/INITCAP
d25a942 to
099d15b
Compare
|
I have rolled back the code to the boolean-based implementation. If it gains approval, it can be merged. If it doesn’t receive consensus, I will still keep the PR open here, as it aligns with my design. |
|
|
This proposed solution was not accepted, so I am closing this issue for now. |



See: CALCITE-7122
I've implemented a rough draft for this JIRA ticket based on my understanding. The actual implementation for idempotent elimination is referenced from the original author. The logic I refactored is as follows:
FLOORandCEILfrom consideration.I haven't modified the test cases from the original PR #4488 , as I want to use them to verify the functional equivalence of the current code. If this implementation approach is approved, we can establish more specific requirements for test cases in the future.
This is just an idea for your reference.