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

Hibernate type resolution for EQL expressions is incomplete #2243

Open
homedirectory opened this issue Apr 22, 2024 · 0 comments
Open

Hibernate type resolution for EQL expressions is incomplete #2243

homedirectory opened this issue Apr 22, 2024 · 0 comments
Assignees

Comments

@homedirectory
Copy link
Contributor

homedirectory commented Apr 22, 2024

Description

During compilation of EQL queries, each expression is assigned a type through the process of type
inference. The domain of inferrable types, however, has been observed to be incomplete, i.e.,
there exist some types that aren't recognised by the type inference algorithm.

When a type of an expression is unrecognised, it is up to the JDBC driver to resolve its type. And
if the driver cannot resolve it either, then it's the responsibility of the database engine.

This characteristic of the current state of the type inference algorithm has been identified solely
due to the changes introduced in #2213. Specifically, due to
explicit type casts inserted at the SQL level, which rely on correctness of type inference.

For example, the following expression is resolved to be of an integer type, while its expected type
is a floating-point numeric (double/float).

// property n has type Integer
// Compiles to Expression of type Integer
expr().prop("n").mult().val(0.5)

// Compiles to Expression of type Integer
expr().val(9).mult().val(0.5).model()

With PostgreSQL, the above expressions, if used in a subquery, compile to:

CAST ((n * 0.5) AS integer)
CAST ((9 * 0.5) AS integer)

This results in the loss of the number's fractional part.

The type inference algorithm needs to be improved so that all data types accepted by EQL are taken into account.

The following locations should be of interest:

  • ua.com.fielden.platform.eql.retrieval.EntityResultTreeBuilder#hibTypeFromJavaType
  • ua.com.fielden.platform.eql.meta.EqlEntityMetadataGenerator#getHibernateType
  • ua.com.fielden.platform.eql.stage2.operands.AbstractSingleOperand2#getTypeHighestPrecedence

It should be understood that this issue affects not only PostgreSQL, but anything relying on
correctness of type inference, hence it is more of a fundamental problem.

Expected outcome

Hibernate type resolution algorithm in EQL covers all possible data types.

Notes

One hypothesis is that some data types, such as Double and Float, simply "slipped" by because
they aren't in the set of supported types of entity properties. Nevertheless, they are perfectly valid,
and actually required, for intermediate values of expressions (results of which are, ultimately,
assigned to entity properties).

@homedirectory homedirectory self-assigned this Apr 22, 2024
@homedirectory homedirectory changed the title Hibernate type resolution for EQL operands is incomplete Hibernate type resolution for EQL expressions is incomplete Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant