[ https://issues.apache.org/jira/browse/CASSANDRA-11935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15673778#comment-15673778 ]
Benjamin Lerer commented on CASSANDRA-11935: -------------------------------------------- {quote} That said, I "think" CASSANDRA-11946 also help here, assuming we restrict functions overloads by return type first. In that case, we'd create overloads with same argument types but different return type (so {{tinyint add(tinyint, tinyint)}}, {{int add(tinyint, tinyint)}}, {{bigint add(tinyint, tinyint)}}, etc...) and {{i = 100 + 50}} would use the proper one. {quote} It would work for {{i = 100 + 50}} but not for {{SELECT 100 + 50}} where we will get an error like: {{Ambiguous '+' operation: use type casts to disambiguate}}. If we do not overload functions with different return types but still use the return type to eliminates some of the functions, in the case of {{c = 1 + 1}}, where c is a {{smallint}}, we end up with 3 possible functions: {{smallint add(tinyint, smallint)}}, {{smallint add(tinyint, smallint)}} and {{smallint add(smallint, smallint)}}. In such a case, I believe that we should just pick the operation with the same argument types than the return type. The only corner case (if I did not miss anything) would be with bind markers. For something like: {{c = 1 + ?}} I believe that we should force the user to use a {{type hint}} as the fact that a {{smallint}} is expected is not obvious. For the {{preferedType}} I still believe that we should stop at {{int}} for integer to minimize the risk of overflow issues in the selection part. > Add support for arithmetic operators > ------------------------------------ > > Key: CASSANDRA-11935 > URL: https://issues.apache.org/jira/browse/CASSANDRA-11935 > Project: Cassandra > Issue Type: Sub-task > Components: CQL > Reporter: Benjamin Lerer > Assignee: Benjamin Lerer > Fix For: 3.x > > > The goal of this ticket is to add support for arithmetic operators: > * {{-}}: Change the sign of the argument > * {{+}}: Addition operator > * {{-}}: Minus operator > * {{*}}: Multiplication operator > * {{/}}: Division operator > * {{%}}: Modulo operator > This ticket we should focus on adding operator only for numeric types to keep > the scope as small as possible. Dates and string operations will be adressed > in follow up tickets. > The operation precedence should be: > # {{*}}, {{/}}, {{%}} > # {{+}}, {{-}} > Some implicit data conversion should be performed when operations are > performed on different types (e.g. double + int). -- This message was sent by Atlassian JIRA (v6.3.4#6332)