Skip to content

HHH-18837 Oracle epoch extraction doesn't work with dates #10296

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peter1123581321
Copy link
Contributor

This PR fixes an error when using epoch with dates on Oracle.
I added an overload of extractPattern (which is overridden in OracleDialect) to handle different TemporalType.
This new method is only used in ExtractFunction in context of OracleDialect.

https://hibernate.atlassian.net/browse/HHH-18837


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


Copy link
Member

@mbellade mbellade left a comment

Choose a reason for hiding this comment

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

Thanks @peter1123581321, left a few comments.

})
@RequiresDialect(OracleDialect.class)
@JiraKey("HHH-18837")
public class OracleDateTypeTest {
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but how about trying to use an existing test (and not restrict it to Oracle only)? For example, a new method similar to org.hibernate.orm.test.query.hql.FunctionTests#testExtractFunctionEpoch in that class (or others).

new PatternRenderer( pattern ).render( sqlAppender, sqlAstArguments, walker );
final Expression expression = (Expression) sqlAstArguments.get( 1 );
final TemporalType temporalType;
if ( dialect instanceof OracleDialect && (temporalType = getSqlTemporalType(
Copy link
Member

Choose a reason for hiding this comment

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

This instanceof is not the best. We should rather have a custom OracleExtractFunction, that is registered in OracleDialect#initializeFunctionRegistry overriding the default implementation. That would also allow us to avoid having the new extractPattern with 2 parameters in Dialect, and keep this logic in oracle-specific implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thank you very much for that hint.
I was sure that you would not like the new method in Dialect.
I will let you know when the PR is ready for a new review.

@peter1123581321 peter1123581321 marked this pull request as draft June 10, 2025 12:19
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.

2 participants