Sylvain Lebresne created CASSANDRA-11938:
--------------------------------------------
Summary: Clarify difference between cast and cast in CQL
Key: CASSANDRA-11938
URL: https://issues.apache.org/jira/browse/CASSANDRA-11938
Project: Cassandra
Issue Type: Improvement
Reporter: Sylvain Lebresne
We have, in CQL, 2 notons of casts:
* {{(int)?}}
* (CAST c as int)
which is pretty confusing, especially in the code where both are called "cast".
Turns out both have somewhat different behavior (whether that justifies having
the 2 is debatable, but it's the way it is now):
* {{(int)?}} is really just a type hint for the type system. It will never
"convert" value. In particular, doing {{(int)x}} where {{x}} is explicitly a
{{bigint}} is invalid because {{bigint}} is 8 bytes while {{int}} is only 4
bytes. Meaning that this type of "cast" is useful when the type system needs
help,for instance when you have a bind marker and the type system can't infer
it's type from context.
* {{(CAST c as int)}} is actually about conversions and you can do it even if
{{c}} is a {{bigint}}.
Now, even if both notions are useful, we can't call both "casts" or that's
really confusing. As we can't really rename the 2nd form since it explicitly
use {{CAST}} in the syntax, I suggest calling the first form a "type hint"
(which is kind of what it is).
That ticket is about reflecting that naming change in the code as well as where
appropriate in the doc (we can use the occasion to improve the doc on the
difference while at it).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)