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

Support Datetime function CURRENT_DATE & CURRENT_TIME #624

Merged
merged 7 commits into from
Feb 6, 2024

Conversation

meengi07
Copy link
Contributor

@meengi07 meengi07 commented Feb 2, 2024

Motivation

  • Support an currentDate & currentTime function.

Modifications

  • Add jpql model and serializer for currentDate
  • Add jpql model and serializer for currentTime

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

  • The Date function currentDate is added.
  • The Date function currentTime is added.

Closes

@CLAassistant
Copy link

CLAassistant commented Feb 2, 2024

CLA assistant check
All committers have signed the CLA.

@meengi07 meengi07 changed the base branch from main to develop February 2, 2024 17:17
@meengi07 meengi07 changed the title Feat/current date&time Support Datetime function CURRENT_DATE & CURRENT_TIME Feb 2, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2024

Codecov Report

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

Comparison is base (4219a32) 91.97% compared to head (a237af3) 66.40%.
Report is 89 commits behind head on develop.

Files Patch % Lines
...in/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt 50.00% 1 Missing and 1 partial ⚠️
.../jpql/serializer/impl/JpqlCurrentDateSerializer.kt 66.66% 1 Missing ⚠️
.../jpql/serializer/impl/JpqlCurrentTimeSerializer.kt 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop     #624       +/-   ##
============================================
- Coverage    91.97%   66.40%   -25.57%     
============================================
  Files          297      465      +168     
  Lines         3215     4748     +1533     
  Branches       195      277       +82     
============================================
+ Hits          2957     3153      +196     
- Misses         204     1538     +1334     
- Partials        54       57        +3     

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

@meengi07 meengi07 force-pushed the feat/currentDate&time branch from f436846 to c963cc7 Compare February 5, 2024 00:40
Comment on lines 497 to 499
fun currentDate(): Expression<LocalDate> {
return Expressions.currentDate()
}
Copy link
Member

Choose a reason for hiding this comment

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

In the Criteria API, the return type of currentDate() is the java.sql.Date.

image

The Jakarta specification also specifies that the return type is the java.sql.Date. Therefore, please change the return type to the java.sql.Date.

image

Copy link
Member

Choose a reason for hiding this comment

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

For the same reason as above, I would like to request that the return type of currentTime() be changed to the java.sql.Time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i got it, I'll change currentTime & currentDate


class CurrentTimeDslTest : WithAssertions {
@Test
fun `currentDate() with a property`() {
Copy link
Contributor

Choose a reason for hiding this comment

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

테스트 함수 이름이 테스트 대상(currentTime)과 일치하지 않습니다. 알맞게 변경해주시면 좋을것같습니다.

private val expression = currentDate()

@Test
fun handledType() { // when
Copy link
Contributor

Choose a reason for hiding this comment

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

코드 스타일을 맞추기위해 // when 주석의 줄내림이 필요해 보입니다.
JpqlCurrentTimeSerializerTest.kt 코드에도 동일한 부분이 있으니 같이 수정해주시면 좋을것같습니다.

Comment on lines 18 to 24
val delegate = context.getValue(JpqlRenderSerializer)

writer.write("CURRENT_DATE")

writer.writeParentheses {
delegate.serialize(part, writer, context)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

serializepart: JpqlCurrent.CurrentDate을 전달하면,
JpqlCurrent.CurrentDate 타입에 대해 serialize 재귀 호출이 일어나서 StackOverflowError가 발생합니다.

JpqlCurrentDateSerializer의 경우 괄호와 추가적인 serialize 호출이 필요가 없어보이므로
writer.write("CURRENT_DATE") 한줄만 있어도 충분해 보입니다.

JpqlCurrentTimeSerializer.kt도 마찬가지이므로 같이 수정해주시면 좋을것같습니다.

각 SerializerTest도 수정된 내용에 맞게 다시 봐주시면 좋을것같습니다!

@@ -486,6 +488,26 @@ open class Jpql : JpqlDsl {
return Expressions.times(this.toExpression(), value.toExpression())
}

/**
* Creates an expression that represents the current date.
Copy link
Contributor

Choose a reason for hiding this comment

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

representsthe 사이에 불필요한 whitespace가 하나 더 포함 되어있습니다.

currentTime()의 주석도 둥일하니 같이 수정해주시면 좋을것같습니다.

Comment on lines 26 to 39
@Test
fun `currentDate() with a expression`() {
// when
val expression = queryPart {
currentDate()
}.toExpression()

val actual: Expression<LocalDate> = expression // for type check

// then
val expected = Expressions.currentDate()

assertThat(actual).isEqualTo(expected)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

위 테스트와 중복된 내용이므로 제거해도 될것같아요.


class CurrentDateDslTest : WithAssertions {
@Test
fun `currentDate() with a property`() {
Copy link
Contributor

Choose a reason for hiding this comment

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

특정 property나 expression을 가지고 테스트하는 코드가 아니므로
테스트 함수 이름이 fun currentDate() 정도로 표현되도 좋을것같습니다.

CurrentTimeDslTest 쪽도 비슷하니 같이 수정해주시면 좋을것같습니다.

import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import java.sql.Date

object JpqlCurrentDate : Expression<Date>
Copy link
Member

Choose a reason for hiding this comment

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

Please add the Internal annotation because this class belongs to an implementation.

@Internal
object JpqlCurrentDate : Expression<Date>


class CurrentDateDslTest : WithAssertions {
@Test
fun `currentDate()`() {
Copy link
Member

Choose a reason for hiding this comment

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

If the name of the test exposes only the name of the method being tested, it is not parenthesized. Please modify it like this:

@Test
fun currentDate() {
  // ...test codes
}

@MockK
private lateinit var serializer: JpqlRenderSerializer

private val expression = currentDate()
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if you could use Expressions.currentDate() instead of static import.

@shouwn
Copy link
Member

shouwn commented Feb 6, 2024

And could you sign our Contributor License Agreement?

image

@shouwn
Copy link
Member

shouwn commented Feb 6, 2024

Some of the formatting is off, but I'll fix that! Thanks for your help. Finally, I'd like to ask you to sign the Contributor License Agreement.

@shouwn shouwn merged commit 6f48b77 into line:develop Feb 6, 2024
3 of 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