-
Notifications
You must be signed in to change notification settings - Fork 92
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
Conversation
Codecov ReportAttention:
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. |
We see that there is missing test code. |
* 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> { |
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.
It appears that the mod has not been implemented, but the commit appears to have been distorted.
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.
@@ -247,6 +249,8 @@ ln(path(Book::price)) | |||
|
|||
mod(path(Employee::age), 3) | |||
|
|||
power(path(Book::verticalLength), 2) |
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.
Is the Book::verticalLength
property new?
It would be better to use an existing property (e.g. Employee::age)
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, 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> { |
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.
Could you please write a method based on the specification in jakarta specification?
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.
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.
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 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.
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... 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
private val baseExpression = Paths.path(Employee::age) | ||
private val exponentExpression = Expressions.value(2) | ||
private val exponentPrimitive = 2 |
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 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)
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 |
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.
Consistency rather than semantics, I see :)
@@ -370,6 +371,7 @@ private class DefaultModule : JpqlRenderModule { | |||
JpqlPredicateParenthesesSerializer(), | |||
JpqlRoundSerializer(), | |||
JpqlSelectQuerySerializer(), | |||
JpqlPowerSerializer(), |
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.
Could you please move the position of JpqlPowerSerializer()
below JpqlPlusSerializer()
?
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.
You mean alphabetical order! Got it :)
* 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> { |
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.
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.
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> { |
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.
Is it to accept a wider range of material types?? reflected ! :)
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 also see this in other code that I haven't checked. I'll fix it in one shot later.
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.
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.
Thank you so much to everyone who reviewed my code! (I'm touched) |
} | ||
|
||
/** | ||
* Create expression that calculates the powering of a numeric [base] to a specified [exponent]. |
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 writing something like this?
* 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]. |
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.
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> { |
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 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> { |
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 also see this in other code that I haven't checked. I'll fix it in one shot later.
I've been busy for a while... I'll PR it soon! |
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.
Thanks for your help. I will make some revisions, such as comments, after I merge it into the develop branch.
Motivation
Modifications
power()
inJpql
,Expressions
JpqlPowerSerializer
Commit Convention Rule
commit type
please describe it on the Pull RequestResult
POWER
.Closes