SQM cast target #3889
SQM cast target
#3889
Replies: 5 comments 3 replies
-
So I have a PR that implements the simple approach here. Is that enough? Or do y'all feel like the registry and registration aspect is important? |
Beta Was this translation helpful? Give feedback.
1 reply
-
FTR we discussed this here: |
Beta Was this translation helpful? Give feedback.
2 replies
-
I applied the branch upstream and will lock this as "resolved" per consensus |
Beta Was this translation helpful? Give feedback.
0 replies
-
@sebersole is this discussion dead? Can we close it? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Re: https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/6.2E0.20-.20cast.20target
In re-enabling some of the older HQL tests I ran into some failures due to expectations for cast targets. At the moment, 6.0 has a discrete, hard-coded set of allowable cast targets based on an IDENT whereas we have historically been a little more dynamic. As an example, the test where I ran into this was attempting
... cast( x as java.lang.String ) ...
. So that breaks because (1) it attempts to use a DOT-IDENT sequence and (2) because (even if we accepted DOT-IDENT) it is not one of the hardcoded targets.Now granted, this is a trivial example and could easily be re-written as
... cast( x as string ) ...
,... cast( x as String ) ...
etc. But I think we need to consider what set of targets we want to allow as valid. Part of that is backwards compatibility, but a large part of it is flexibility/usefulness.As far as IDENT v. DOT-IDENT, we could also consider this like we do with the
dmlTarget
andentityName
rules which are defined in terms of DOT-IDENT, but which efficiently return the String representation - the DOT-IDENT aspect becomes completely transparent.I think the first thing to consider in terms of a solution is what we ultimately need to properly represent this target in the SQM / SQL trees.
In SQM,
SqmCastTarget
is just a node - all we really need to fully implement that contract is aJavaTypeDescriptor
(well technically aSqmExpressable
, but that only requires exposingJavaTypeDescriptor
). Probably we'd ideally have the JdbcTypeDescriptor here too; its not really needed for this part, but might help in the SQM->SQL step; devil's in the details and I guess we'll see as we implement this. The thing I am trying to avoid here is requiring a fullDomainType
/AllowableFunctionReturnType
. It will become apparent as we talk about the different ways to specify the cast-target.In the SQL AST, it depends on how fully we want to implement the
Expression
contract (whichCastTarget
implements. If we want a full implementation, we need aMappingModelExpressable
. Now theMappingModelExpressable
contract itself is easy enough to implement here. Its really nothing more that aJdbcMapping
and a bunch of "binding related" methods which we don't care about. At the moment,CastTarget
is defined with aBasicValuedMapping
. The "trickiest"part there is the need for aManagedType
, butJdbcMapping
already happens to implementManagedType
so that should be fine.I'd also suggest that we really want to resolve this early, maybe even as early as the SQM tree. The reasons being that (1) we have everything we need during SQM creation, and (2) we'd need some "type" info anyway to properly implement
SqmExpressable#getExpressableJavaTypeDescriptor
. If we consider... cast( x as string )
what I mean here is that we need to know, at the very least, that"string"
correlates to some form ofJavaTypeDescriptor<String>
. And to do that, we'd have to resolve that cast-target to something that gives us access to theJavaTypeDescriptor<String>
. So what I suggest is:We'd then resolve the
JdbcMapping
during SQM building. The one hiccup I see with this approach is "type inference" which would be based on the SQM nodes. I'd have to play with that to see if it is a real problem. And to be honest, should "type inference" really effect the "type" of the cast-target? Not sure.Then:
As for what kind of things to accept as cast targets, I suggest we should at least discuss the following.
== BasicType
We already have this in 5.x. Basically any name that is registered in the
BasicTypeRegistry
. This already covers most (all?) of the hard-coded cases.== JavaTypeDescriptor
This ties in with the new
@JavaType
/@JavaTypeRegistration
approach to defining handling for basic-values model parts. The big questions here are:JavaTypeDescriptor
entries in theJavaTypeDescriptorRegistry
? Or do we allowJavaTypeDescriptor
impls to optionally, additionally register themselves as cast targets?Functionally, this would rely on
JavaTypeDescriptor#getRecommendedJdbcType
to fill out theJdbcMapping
.== AttributeConverter
This one would almost certainly require changing to allow DOT-IDENT, unless we implement some form of optional registration for them.
For background, I bring this one up because it ties in nicely with another feature I want to implement Query parameter binding based on passing a converter as the type. This would really only be useful in cases where the type inference for the parameter is incorrect.
E.g. `query.setParameter( "p1", theValue, TheConverter.class );
Not saying I like this one, just for completeness.
== Others?
Beta Was this translation helpful? Give feedback.
All reactions