In Cassandra Lunch #99, Arpan Patel will discuss the CQL Arithmetic Operators that are now supported in Cassandra 4.0!
Accompanying Blog: Coming Soon!
Accompanying YouTube: https://youtu.be/SJfkoIE1scw
Sign Up For Our Newsletter: http://eepurl.com/grdMkn
Join Cassandra Lunch Weekly at 12 PM EST Every Wednesday: https://www.meetup.com/Cassandra-DataStax-DC/events/
Cassandra.Link:
https://cassandra.link/
Follow Us and Reach Us At:
Anant:
https://www.anant.us/
Awesome Cassandra:
https://github.com/Anant/awesome-cassandra
Cassandra.Lunch:
https://github.com/Anant/Cassandra.Lunch
Email:
solutions@anant.us
LinkedIn:
https://www.linkedin.com/company/anant/
Twitter:
https://twitter.com/anantcorp
Eventbrite:
https://www.eventbrite.com/o/anant-1072927283
Facebook:
https://www.facebook.com/AnantCorp/
Join The Anant Team:
https://www.careers.anant.us
1. Version 1.0
CQL Arithmetic Operators
In Cassandra Lunch #99, Arpan Patel will discuss the CQL
Arithmetic Operators that are now supported in Cassandra 4.0!
Arpan Patel
Engineer @ Anant
2. Arithmetic Operators in Cassandra 4.0
● Cassandra supports five arithmetic
operators on numbers:
○ +
○ -
○ *
○ /
○ %
● Operators can be used in the SELECT
INSERT, UPDATE, and DELETE
statements to perform some
computations
● Works on DataStax Astra as well
3. Return Types
● An important thing to take into account when using operators is the return type of the operation
4. Type Inference
● Cassandra will try to infer the type of the literals to
determine how the operation must be performed
● If the literal is an integer, C* will look at it and consider it as
an int, a bigint or a varint if the type can hold this value
● For floats, C* will consider them as either doubles or
decimals
● Now, in some cases, Cassandra knows the return type of the
expression and can use it to infer the type of the literals
5. Hints / Casting
● A type hint is a way to explicitly tell Cassandra what will be
the type of the parameter
● Type hints can also be used to control the type of a literal
● Can also cast into type of literal
6. Operator Precedence
● *, /, and % operators have a higher precedence level than +
and - operator
● If two operators in an expression have the same precedence
level, they will be evaluated left to right based on their
positions in the expression
● Parentheses can be used to modify the order in which the
operations must be performed within an expression
● Everything within parentheses will be evaluated first to yield
a single value before that value can be used by any operator
outside the parentheses
7. Operations on Timestamps and Dates
● Addition or subtraction of durations from timestamps and
dates is supported
● As UTC does not change with a change of seasons arithmetic
operations on timestamps and dates are safe and will always
return the expected results
● However, be aware that the Java libraries used internally by
Cassandra, ignore leap seconds.