Reputation: 1
There is a Cassandra table as follows.
Student(eName text, eId int PRIMARY KEY, m1 int, m2 int, average float)
How can the average value be autocalculated on inserting values for other fields of the row? That is, we need to insert only eName, eId, m1 and m2; average has to be autocalculated and entered in the tuple.
Thanks.
Upvotes: 0
Views: 21
Reputation: 16293
Cassandra has built-in CQL aggregate functions such as AVG()
which computes the average of all values returned by a query, that is, the aggregation takes place at read time (as opposed to write time).
You can also write your own user-defined aggregates (UDAs).
It is possible to implement your own CQL TRIGGER
which executes Java code when data is written to a table but it has been considered as experimental for a long time and I don't recommend using it.
The general recommendation is to perform the aggregation within your application prior to writing the data to the table. Cheers!
Upvotes: 1