Skip to Content
Mastering Apache Cassandra 3.x - Third Edition
book

Mastering Apache Cassandra 3.x - Third Edition

by Aaron Ploetz, Tejaswi Malepati
October 2018
Beginner to intermediate content levelBeginner to intermediate
348 pages
10h
English
Packt Publishing
Content preview from Mastering Apache Cassandra 3.x - Third Edition

User-defined functions

As of version 3.0, Apache Cassandra allows users to create user-defined functions (UDFs). As CQL does not supply much in the way of extra tools and string utilities found in SQL, some of that function can be recreated with a UDF. Let's say that we want to query the current year from a date column. The date column will return the complete year, month, and day:

SELECT todate(now()) FROM system.local; system.todate(system.now())-----------------------------                  2018-08-03(1 rows)

To just get the year back, we could handle that in the application code, or, after enabling user-defined functions in the cassandra.yaml file, we could write a small UDF using the Java language:

CREATE OR REPLACE FUNCTION year (input DATE) RETURNS ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Apache Cassandra - Second Edition

Mastering Apache Cassandra - Second Edition

Nishant Neeraj

Publisher Resources

ISBN: 9781789131499Supplemental Content