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

Implement power operator #651

Merged
merged 11 commits into from
Mar 12, 2024
Merged

Implement power operator #651

merged 11 commits into from
Mar 12, 2024

Conversation

progress0407
Copy link
Contributor

@progress0407 progress0407 commented Feb 21, 2024

Motivation

Modifications

  • Write power() in Jpql, Expressions
  • Create a JpqlPowerSerializer
  • Write the respective test code

Commit Convention Rule

Commit type Description
feat New Feature
fix Fix bug
docs Documentation only changed
ci Change CI configuration
refactor Not a bug fix or add feature, just refactoring code
test Add Test case or fix wrong test case
style Only change the code style(ex. white-space, formatting)
chore It refers to minor tasks such as library version upgrade, typo correction, etc.
  • If you want to add some more commit type please describe it on the Pull Request

Result

  • Now supports POWER.

Closes

@progress0407 progress0407 reopened this Feb 21, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (37a3bac) 67.05% compared to head (5369802) 67.15%.

Files Patch % Lines
...render/jpql/serializer/impl/JpqlPowerSerializer.kt 88.88% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #651      +/-   ##
===========================================
+ Coverage    67.05%   67.15%   +0.10%     
===========================================
  Files          479      481       +2     
  Lines         4863     4881      +18     
  Branches       277      277              
===========================================
+ Hits          3261     3278      +17     
- Misses        1545     1546       +1     
  Partials        57       57              

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

@progress0407
Copy link
Contributor Author

We see that there is missing test code.
I'll fill it in and post it.

@progress0407 progress0407 changed the title Implement power operator Implement power operator (to be open) Feb 21, 2024
@progress0407 progress0407 reopened this Feb 22, 2024
@progress0407
Copy link
Contributor Author

um...

I don't know why that one line of missed code is there.

image image

Because as you can see, when I run the test for that class, it definitely captures the debugger.

I guess I'll have to find out what the magic is...

image

@progress0407 progress0407 changed the title Implement power operator (to be open) Implement power operator Feb 22, 2024
* Creates an expression that represents the mod of values.
*/
@SinceJdsl("3.4.0")
fun <T : Any> mod(expr: KProperty1<T, Int>, value: Int): Expression<Int> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It appears that the mod has not been implemented, but the commit appears to have been distorted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Oops, I had them in the order they appear in the official documentation, which seems to have caused some confusion. I've now fixed them back to their original position.

@@ -247,6 +249,8 @@ ln(path(Book::price))

mod(path(Employee::age), 3)

power(path(Book::verticalLength), 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the Book::verticalLength property new?
It would be better to use an existing property (e.g. Employee::age)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right, I thought about adding that field, but it's not currently there.
I know someone added an age field recently haha I'll replace it with that.

* Create expression that calculates the powering of a numeric [base] to a specified [exponent].
*/
@SinceJdsl("3.4.0")
fun <T : Number> power(base: Expressionable<T>, exponent: Int): Expression<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

powerfunction

Could you please write a method based on the specification in jakarta specification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, I love doing reviews based on such solid knowledge. lol Thank you :)

I feel like this allows me to get up close and personal with the Hibernate spec.

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend following the jakarta spec unless you have a special use case. This is because if Hibernate and EclipseLink have different specifications, you may not be able to decide which one to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh... Thank you.
I gained a lot of knowledge while implementing this power.
I also understand now why the package was changed from javax to jakrta.

References

Comment on lines 12 to 14
private val baseExpression = Paths.path(Employee::age)
private val exponentExpression = Expressions.value(2)
private val exponentPrimitive = 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be done to make the semantics of the variables clearer, but it would be nice to have a consistent style with other existing test code (e.g. ModDslTest.kt)

Suggested change
private val baseExpression = Paths.path(Employee::age)
private val exponentExpression = Expressions.value(2)
private val exponentPrimitive = 2
private val intExpression1 = Paths.path(Employee::age)
private val intExpression2 = Expressions.value(2)
private val int1 = 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency rather than semantics, I see :)

@@ -370,6 +371,7 @@ private class DefaultModule : JpqlRenderModule {
JpqlPredicateParenthesesSerializer(),
JpqlRoundSerializer(),
JpqlSelectQuerySerializer(),
JpqlPowerSerializer(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please move the position of JpqlPowerSerializer() below JpqlPlusSerializer()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean alphabetical order! Got it :)

@waahhh
Copy link
Contributor

waahhh commented Feb 22, 2024

um...

I don't know why that one line of missed code is there.

image image
Because as you can see, when I run the test for that class, it definitely captures the debugger.

I guess I'll have to find out what the magic is...

image

You don't need to worry about this missing test code issue.

* Create expression that calculates the powering of a numeric [base] to a specified [exponent].
*/
@SinceJdsl("3.4.0")
fun <T : Any, V : Number> power(base: KProperty1<T, @Exact V>, exponent: Expression<Int>): Expression<V> {
Copy link
Contributor

Choose a reason for hiding this comment

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

When used as a parameter to a dsl method, it is more appropriate to write it with the Expressionable<> type instead of the Expression<> type

e.g.

Suggested change
fun <T : Any, V : Number> power(base: KProperty1<T, @Exact V>, exponent: Expression<Int>): Expression<V> {
fun <T : Any, V : Number> power(base: KProperty1<T, @Exact V>, exponent: Expressionable<Int>): Expression<V> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it to accept a wider range of material types?? reflected ! :)

Copy link
Member

Choose a reason for hiding this comment

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

I also see this in other code that I haven't checked. I'll fix it in one shot later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking it out.
I'm actually pretty much done with it, but I've had a little bit of a break, so I haven't had a chance to do a final review and PR.
I'll probably PR it really soon.
Thanks.

@progress0407
Copy link
Contributor Author

Thank you so much to everyone who reviewed my code! (I'm touched)
However, due to my work, I won't be able to implement them right away.
I've read everything you said, and I'll apply what I can to the PR after committing!
Thank you everyone! (especially waah)

}

/**
* Create expression that calculates the powering of a numeric [base] to a specified [exponent].
Copy link
Member

Choose a reason for hiding this comment

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

How about writing something like this?

Suggested change
* Create expression that calculates the powering of a numeric [base] to a specified [exponent].
* Create an expression that represents the power of [base] and [exponent].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you. The sentence below looks easier to read.

* Create expression that calculates the powering of a numeric [base] to a specified [exponent].
*/
@SinceJdsl("3.4.0")
fun <T : Number> power(base: Expressionable<T>, exponent: Int): Expression<T> {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend following the jakarta spec unless you have a special use case. This is because if Hibernate and EclipseLink have different specifications, you may not be able to decide which one to follow.

* Create expression that calculates the powering of a numeric [base] to a specified [exponent].
*/
@SinceJdsl("3.4.0")
fun <T : Any, V : Number> power(base: KProperty1<T, @Exact V>, exponent: Expression<Int>): Expression<V> {
Copy link
Member

Choose a reason for hiding this comment

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

I also see this in other code that I haven't checked. I'll fix it in one shot later.

@progress0407
Copy link
Contributor Author

I've been busy for a while... I'll PR it soon!

@progress0407 progress0407 requested review from cj848, waahhh and shouwn March 12, 2024 17:14
Copy link
Member

@shouwn shouwn left a comment

Choose a reason for hiding this comment

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

Thanks for your help. I will make some revisions, such as comments, after I merge it into the develop branch.

@shouwn shouwn merged commit 181aa4b into line:develop Mar 12, 2024
4 checks passed
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.

5 participants