Thursday, May 28, 2015

Cassandra Aggregates - min, max, avg, group by

This blog has moved to batey.info and won't be updated here.

Disclaimer: all this was against 2.2-beta so the syntax may have changed.

Cassandra 2.2 introduced user defined functions and user defined aggregates. We can now do things like min, max and average on the server rather than having to bring all the data back to your application. Max and min are built in but we'll see how you could have implemented them your self.

Max/Min


Here's an example table for us to try and implement max/min against.


User defined aggregates work by calling your user defined function on every row returned from your query, they differ from a function because the first value to the function is state that is passed between rows, much like a fold.

Creating an aggregate is a two or three step process:
  1. Create a function that takes in state (any Cassandra type including collections) as the first parameter and any number of additional parameters
  2. (Optionally) Create a final function that is called after the state function has been called on every row
  3. Refer to these in an aggregate
For max we don't need a final function but we will for average later.


Here we're using Java for the language (you can also use JavaScript) and just using Math.max. For our aggregate definition we start with (INITCOND) null (so it will return null for an empty table) and then set the state to be the max of the current state and the value passed in. We can our new aggregate like:


GroupBy


So there's no group by keyword in Cassandra but you can get similar behaviour with a custom user defined aggregate. Imagine you had a table that kept track of everything your customers did e.g



We can write a UDA to get a count of a particular column:


And we keep track of the counts in a map. Example use for counting both the event_type and the origin of the event:


More often than not when you use group by in other databases you are totalling another field. For example imagine we were keeping track of customer purchases and wanted a total amount each customer has spent:



We can create a generate aggregate for that called group_and_total:


And an example usage:


As you can see Haddad spends way too much.

Average


The Cassandra docs have an example of how to use a user defined aggregate to calculate aggregates: http://cassandra.apache.org/doc/cql3/CQL-2.2.html#udas

Small print


If you've ever heard me rant about distributed databases you've probably heard me talk about scalable queries, ones that work on a 3 node cluster as well as a 1000 node cluster. User defined functions and aggregates are executed on the coordinator. So if you don't include a partition key in your query all the results are brought back to the coordinator for your function to be executed, if you do a full table scan for your UDF/A don't expect it to be fast if your table is huge.

This functionality is in beta for a very good reason, it is user defined code running in your database! Proper sandboxing e.g with a SecurityManager will be added before this goes mainstream.




490 comments:

«Oldest   ‹Older   401 – 490 of 490
seo magic said...

This is a great blog posting and very useful. I really appreciate the research you put into it...
Our only on one motive to provide a satisfactory studies.....
microsoft refund request

peterwell said...

IVA Facts
It’s really a great post..I would like to appreciate your work and I am going to recommend it to my friends.
Thanks for sharing

IVA Facts




joeypeterson786 said...

BPO Collections
I also wish him good luck to defend his gold medal. I definitely enjoyed every little bit of it I have you bookmarked to check out new stuff you post.

debt problems said...


grants to pay off debt uk
Your site always offer some really interesting information. Thank you for sharing it with us.

nylaa said...

We all heard about the importance of passwords. Undoubtedly, the importance of a password is a must for every email account. But, having a password has its own problem. The problem is that users forget their password due to which they lose access to their email account. If you are a Yahoo user, you are in luck because the Yahoo password recovery process is simple and straightforward. All you need to have just access to your registered phone number or alternative email id. Click on the forgotten password and follow the online instruction. For more information,How Can I Sign Out of Yahoo Email On All Devices.
How to recover forgotten yahoo password

zarkazijar said...

jabu cut  off mark
This an amazing blog and I really appreciate you for sharing this excellent and informative blog, fell in love with your beautiful design and unique contents, thanks for sharing.

joeypeterson786 said...

Your site always offer some really interesting information. Thank you for sharing it with us.
Hiding Money from IVA

Connect Helpline said...

Thanks for the info. If you need any help regarding aol mail just contact us.Read more for: migrate verizon email to aol | aol not working with outlook | aol mail not working on windows 10

Rylyn Smith said...

Quickbooks is a program to manage all your transactions. if you can adding deposits for your customer. some times user add wrong details such as wrong amount in the deposit or add a deposit to the wrong customer. if you want to know how to delete a deposit in quickbooks online .Get support to all your queries regarding quick payments solutions.

ben said...


integrated payroll systems
leave management system

cloud based payroll software
best payroll software

catherine williams said...

Yandex mail is an email service provider that allow registered users to send and receive email messages. You can send emails on the Yandex platform. If you are looking for an email service provider . Yandex mail is the right option. Users can send and receive email messages at any time on their Yandex mailbox. If you want to know to create a Yandex mail account on Yandex mail platform. you can follow all these guidelines in this article. You can access to all service on this platform including email service. You can also contact Yandex customer service.

Babakery said...

nice blog, Multigrain Carrot Cake by BA bakery it offer ayurveda-inspired spiced cake balances kapha and pitta doshas, and has cooling properties. Multigrain Carrot Cake online in Delhi Ncr , an all-time favourite because loaded with vitamin A and dietary fibers, this cake is good for the eyes and helps improve digestion.

Unknown said...

I enjoy the variety of topics you present here. Thank you for providing us with knowledge that is genuinely useful.
jc international acquisition llc

john nicholas said...

Nice article given by u thanks for it. Epson is a world wide leading company for its printers and its Quality and performance is very good. Epson is making Inkjet and Laser both type of printers for home and business purposes. But few days before while using this printer i found an error in it epson error code 0x97 but now the problem is resolved so u can go through and check it.

Butterfly Ayurveda said...

Nice Blog. Pyrexofly- Ayurvedic medicine for fever and weakness by Butterfly Ayurveda is formulated with special herbs to help curb the fever and treat weakness and soreness in muscles. Get yours today! to read more ,click on the link below:- https://bit.ly/35c4ZXl

Valluva said...

mobile app development company in california

Unknown said...

nice blog . How to treat indigestion and constipation with herbs? .

Benjamin Jones said...

1
2
3
4
5
6

Zoe Saldana. said...

crypto.com login||
Metamask login||
coinbase pro login||
coinbase pro login||
coinbase pro login||

Babakery said...

NICE BLOG. Ba Bakery Hazelnut Chocolate Cake

McHenkzEminence said...

I'm satisfied that you shared this helpful information with us. Checkout search for company registration number

Babakery said...

Diabe Choice Cookies to Control Diabetes

thomie joy said...

This blog helped me a lot as I was stuck because my Canon Printer was not working with an error message. The step has given here I followed and I am happy now HP Printer Phone Number UK

Krishna Jaiswal said...

Trend Micro Inc. is an American-Japanese worldwide network programming organization and its headquarters is based in Tokyo, Japan, and Irving, Texas, United States. Trend Micro have their R&D centers in Asia, Europe, and North America. The company was founded in 1988 in Los Angeles. In 1992, Trend Micro assumed control over a Japanese programming firm to frame Trend Micro Devices and set up central command in Japan. Since then, Trend Micro is providing the best antivirus solutions to home and business users and one of the best Trend Micro Service UK

Unknown said...

payroll system software singapore
integrated payroll and hr software
best payroll software singapore
integrated payroll systems
payroll software

zarkazijar said...

I really enjoy reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. ikcoed cut off mark for political science

Krishna Jaiswal said...

If you want the lightest and fastest antivirus on the market, WebrootSecureAnywhere Antivirus is the best choice. This antivirus

software does not make use of traditional signature databases to find computer threats. Instead, metadata and behavior patterns are

applied to fix any unwanted computer threats.

Read more - Webroot antivirus

protects your device

Anita Frantz said...

This is the first time I have visited here. I discovered such a significant number of engaging stuff in your blog, particularly its talk. From the huge amounts of remarks on your articles. I also share my Kohi Minecraft profile here. Visit and share a comment.

tripnomadic said...

Nice Blog. Manipur is a most beautiful place where Nature has been extra generous in her bounty. If You are making a plan to visit Manipur. Tripnomadic provides you Ultimate Manipur Travel Guide. There is endless enjoyment and pleasure with its blue lakes, and undulating hills.

Unknown said...

ij.start.canon and find out the best way to download Canon printer drivers.
Ij.start.canon | ij.start.cannon

Trendingtales said...

I love your blog very much. Thanks for sharing it know and how apple defeats netflix to become the first streaming service to win hollywood's most desirable film awards

jaushphine said...

The Best Total War Game series is without a doubt one of the most legendary in the history of video games. With the recent releases of Total War: Rome Remastered and Warhammer 3, now is an excellent opportunity to consider the finest and worst strategy games ever. The most interesting and entertaining Total War game to date is Rome Total War. Because of its faultless political narrative and tactics, it is one of the top Total War Games ranked here. When it was first released, the game featured significant flaws, crashes, and even installation issues, yet it quickly soared to the top of the Total War Games list. Its assets include heavy artillery, cavalry, and well-trained riffling teams.

Best Total War Game

Neeraj kumar said...

eAstroHelp is India's leading website for Astrology-based resources. The Company aims at promoting ancient occult science from India across the globe. Leo virgo cusp

Antivirus License Key said...

Buy Standard Licence Antivirus and Security Software and get at the best price. You can get any license key either in whatsapp or email.

Visit our official website - Antivirus License Key

tour2review said...

Natural beauties and tourist attractions abound in Telangana. We've compiled a selection of Tourist places in Telangana that will leave you breathless in their absolute splendor, whether you're looking for natural beauty, architecture, or historical information. Historical attractions and religious sanctuaries abound in the state, which was originally part of Andhra Pradesh. On June 2, 2014, Telangana, on the other hand, became India's 29th state. If you're interested in history and holy locations, look into old architecture. Hyderabad, Medak, and Adilabad are three of Telangana's most popular tourism sites. Because of its unique blend of culture, history, and architecture, Nizamabad is a well-known tourist destination.
Tourist places in Telangana

TheBEGlobal said...

Nice Blog, Thanks for sharing. Are you looking for Web Development Services in Dubai?
Then you are right place. BE Global provides the best Web Development services. We have an expert and dedicated team of it.

BEGlobal(US)LLC said...

Nice Blog, Thanks for sharing, BE Global is one of the leading SEM Company in Michigan. We have a professional and highly skilled team of SEM.

jaushphine said...

We all know how difficult it is to download a new Bollywood or Hollywood film from the internet. This is no longer the case, due to moviescouch, an unlawful website that sells pirated films. MoviesCouch is an excellent tool for this. On our site, you may watch and download your favourite movies and television series. It is a free service that allows anyone to watch the most recent movies and television episodes, despite the fact that it is unlawful. MoviesCouch offers a variety of exciting, but illegal, free options to its consumers. It's an unofficial free movie download website where you may watch movies without spending any money. Adult, children's, family, and even classic films are available through this service.
MoviesCouch

Sean Perez said...

Are you one of those Cash App users who are unable to Check Balance On Cash App Card due to the lack of information? In such a case, you need to have a word with the Cash App professionals who will make you aware of the right process to check the balance of your Cash App card in a proper manner.

kendrajohn said...
This comment has been removed by the author.
Cclothing shop said...

Bape Hoodie is the official Bape Clothing shop for real Bape Hoodie fans. Get amazing A BATHING APE Store, Sweatshirts and jacket. Fast shipping with big discount.
Bape Clothing
Bape Shirt
Bape Hoodie
Bape Jacket
Bape Sweatshirt
Bape Sweatpants
Bape Shorts

Divya Ayurveda said...

Great information. Thanks for sharing it and I love to read more information like this. Deevyaayurveda provides the best moustache hairloss treatment ayurvedic at affordable cost.

Cclothing shop said...

Bape Hoodie is the official Bape Clothing shop for real Bape Hoodie fans. Get amazing A BATHING APE Store, Sweatshirts and jacket. Fast shipping with big discount.
Bape Clothing
Bape Shirt
Bape Hoodie
Bape Jacket
Bape Sweatshirt
Bape Sweatpants
Bape Shorts
bape jumper

tripnomadic said...

Nice Blog, Thanks for Sharing. Here you can find the list of Best Places to Visit in Kotagiri at tripnomadic

zarkazijar said...

Thanks for sharing such great information with us. Very nice and well-explained article. Very fantastic piece of content I see here on your blog, you have put out very vital tips and information for your readers. Thanks for sharing. bmu approved school fees and acceptance fee

BEGlobal(US)LLC said...

Nice Blog, Thanks for Sharing. BE Global LLC is a leading SEO Company in Michigan. It will help to increase our number of leads, and sales

Cclothing shop said...

Bape Hoodie is the official Bape Clothing shop for real Bape Hoodie fans. Get amazing A BATHING APE Store, Sweatshirts and jacket. Fast shipping with big discount.
Bape Clothing

TheBEGlobal said...

Nice Blog, Thanks for Sharing. BE global presents Digital Marketing services in Dubai at the best price. We offer SEO, PPC, Web designing, and More.

BEGlobal(US)LLC said...

Nice Blog, Thanks for Sharing. BE Global LLC is a leading social media marketing company in Michigan. We have an expert and highly skilled team of social media.

draftncraft21 said...

Nice blog thanks for sharing it. Do you know Why is it necessary to have law firm support in florida?

tripnomadic said...

Nice Blog, Thanks for Sharing. Explore the Beautiful visiting places in Daman and Diu at Tripnomadic.

ROBIN said...

I really like following your blog as the articles are so simple to read and follow. Excellent. Please keep up the good work. Thankshttps://theluxia.com/

BEGlobal(US)LLC said...

Nice Blog, Thanks for Sharing. BE Global offers Web Development Services in Michigan to create magnificent and engaging websites for all industries.

Trendingtales said...

Nice blog thanks for sharing this blog it really help me do you know when Black Mirror Season 6 is coming to netflix?

Antivirus License Key said...

Avast One Essential License Key

How does Avast one essential work?
Avast’s one essential detects and removes unnecessary files, allowing you to enhance electronic properties. You can also execute the Optimization Scan separately. This analysis discovers programs that are operating in the foreground and recommends closing them, in conjunction with almost the same trash document discovery.

Read more - Avast One Essential License Key

Antivirus License Key said...

Avira Mobile Security Pro License Key
How does Avira Mobile Security work?
Mobile phones are much vulnerable to online risks because most people carry out their browsing and internet surfing. Avira Security is a better option to keep your mobile safe and secure from worms, malware, and other internet threats. Avira mobile security experts in protecting your devices from certain device problems with regular software analysis.

Read more - Avira Mobile Security Pro License Key

Romero said...
This comment has been removed by the author.
Romero said...

I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. Do you knoew about what Jitter Clicking is. Most popular games need to click quickly. To improve your clicking speed, you need to study this article on jitter clicking.

Priyanka Rai said...

WE ARE PROTECTING YOUR PRIVACY, Whether it is protecting personal identity or protecting against online threats. Our mission is to make a digital world free from all threats. We work to make it better.

Read more - Avast Antivirus License Key

printerrepaiidubai said...
This comment has been removed by the author.
printerrepaiidubai said...

printer repair dubai
hp printer repair dubai
printer repair near me
HP printer repair sharjah.
printer repair sharjah
printer repair sharjah
hp printer repair dubai
printer repair dubai
hp printer repair dubai
printer repair dubai

sifon said...

Excellent for this specific beneficial blog post. I am surprisingly happy to seek out this form of relevant information. lautech past questions and answers pdf download

Handyman services said...

Your site always offer some really interesting information. Thank you for sharing it with us.
professional tile flooring services

devidwarner said...

I really appreciate the kind of topics you post here. Thanks for sharing information that is actually helpful. Thank you

iphone 8 plus repair services in dubai

Printer repair service in Dubai

Data Recovery Dubai

data recovery said...

We appreciate you sharing your informative and simple-to-read blog with us. This post is excellent. You are one of the best bloggers I have read, I must say. I appreciate you publishing this useful article.
oneplus repair service in Dubai

BEglobal said...

Thanks for sharing. BEglobalza offers Digital Marketing Services in Cape Town. Your online marketing strategy and planning will be created in accordance with international best practices thanks to our committed team of digital marketing professionals.

Canada Payment Processing said...

Argentpaytech is a Canadian company that provides online payment processing solutions. We understand your business objective for payment processing and provide a secure and reliable payment gateway. We are committed to providing payment solutions for Canadian businesses with the best service possible to our clients.

Technical Blogs Dubai said...

I found your blog really really useful. This is very informative and genuine blog.cheers for writing this blog.
Best data recovery dubai

Trendingtales said...

FANS CAN’T WAIT SINCE NETFLIX ANNOUNCES SEASON 4 OF SEX EDUCATION TO ARRIVE IN 2023

Real Eatate said...

Nice Blog. If You find luxury residential properties in gurgaon then Check Bestech Altura. Bestch Altura is a luxury property in gurgaon. .

fawadkhan654 said...

Great articles and a great layout. Your blog post deserves all of the positive feedback it’s been getting.


hard disk recovery dubai

data recovery said...


Your website always provides truly interesting details. Thanks for sharing this information with us.

full time maids in dubai

Ofin Legal said...
This comment has been removed by the author.
Priyanka Rai said...

How to request a refund for an AVG subscription?

AVG offers members a 30-day money-back guarantee. If you are not satisfied with your VPN and want to cancel AVG VPN within 30 days of purchase, you can cancel. You can get an AVG refund if you buy it through AVG’s official website or through the Google Play Store.

Get professional help, dial – 8000903202

Read more - AVG Refund

Priyanka Rai said...

Request a refund for your Avira order

Suppose you use Avira antivirus on your computer or other devices. You need to know how Avira protects your device. It is a very lightweight software that hardly affects the speed or performance of your computer. Avira Security has some extra features to keep you completely safe from online threats.

How to cancel a subscription?

You will need to make a refund request to cancel Avira subscription.

For quick query dial – 0800-090-3222

Read more - cancel Avira subscription

Krishna Jaiswal said...

How to cancel a PC Protect subscription and get a refund?
How to stop auto-renewal?

You can opt out of using the automatic renewal service by following the instructions below or by calling Customer Service and canceling the automatic renewal.

Log in to your PC protect the account. You will receive an account email and password.
Choose a subscription
Select Disable auto-renewal.

Read more - How to cancel a PC Protect subscription and get a refund

Quick Techy said...

How to cancel the subscription?

Follow the instructions below to cancel trend micro subscription.

You need to go to the official page of your Trend account.
Then go to the help center page. Then click on the option I need help
After that, select Cancel Auto-Renewal and select the name of the product you purchased.
State the reason for cancellation. Then the form will open.
Fill out all required information, including first and last name, email address, and country.
Enter your order number and tap Save.
Then send the captcha and click on the send request button.
Finally, within 24 – 48 hours, you will receive an email from the company’s staff regarding the successful cancellation.

Read more - How to cancel the Trend Micro subscription

zarkazijar said...

As a result, promotion and upkeep will be lot easier...........adamu adamu college of nursing sciences form out . Visit Best Rated Educational Update Portal in the World; Examination and Academic Guide, High Paying Jobs & Scholarship Websites.

Anonymous said...

Great! This blog is really providing nice information. Thanks for sharing this blog. Blue Moonstone

Priyanka Rai said...

Virgin Media Email

Virgin Media Email is a web-based email service available to customers of Virgin Media, a telecommunications company based in the United Kingdom.

For Instant Help, Dial 0800-090-3202 (for the UK only)

Read more - Virgin Media Email UK

Priyanka Rai said...

AVG Antivirus License Key

Buy AVG Antivirus License Key for computers, tablets, and smartphones and get up to an 80% discount. Also, get free installation by an expert.

Read more - AVG Antivirus License Key

Krishna Jaiswal said...



Q. How to contact Avira Customer Service?
A. Please follow the below steps to contact Avira Customer Service
• Open Avira Software Dashboard
• Click on the menu section
• Click the contact us tab to contact Avira support
• If you still need expert help, call 0800-090-3202

Read more - https://quicktechy.co.uk/avira-support/

Krishna Jaiswal said...

PC Protect Premium License Key
You may improve device security by using the PC Protect premium service. It provides antivirus protection, a privacy firewall, system optimization, disc cleaning, online security, a password vault, and ID protection. For PC, Macs, mobile phones, and tablets, PC Protect delivers total device and identity security. This PC Protect Premium is an advanced version of PC Protect tool that is compatible with the most widely used operating systems.

Read more - https://antiviruslicensekey.co.uk/product/pc-protect-premium-license-key/

Airlines Point said...


Alaska Airlines Office USA

Washing machine repair Dubai said...

This is a great website to visit. I recently came across your blog's content and wanted to let you know that I have been enjoying the blog entries. I'll be a frequent visitor absolutely certain.

handyman abu dhabi

Uaetechnician said...

I'm so eating up this stuff is pondering the web, and your post really convinced me. You should get the bearing you gave at home. Perhaps the visitor presence will be a boggling one.

microsoft surface repair dubai
microsoft surface repair dubai


Taha alsayed said...

https://blogger-yemen.blogspot.com

Alsaa beauty said...

I can't agree more. That a wonderful post. Visit our website to see more post like this.

Vifabizzone said...

Business Formation, Govt. Approvals & Bank Account
Comprehensive UAE Business Setup Services, Including Residency, Banking, Visa and More, Visit our website to know more

BEdigitech said...

Thank you for sharing. Unlock unparalleled growth opportunities with our expert Affiliate Marketing Company. Harness the power of strategic partnerships and targeted campaigns to drive traffic, increase conversions, and maximize revenue. With our proven track record and tailored approach, elevate your brand's online presence and achieve sustainable success in the digital landscape.

«Oldest ‹Older   401 – 490 of 490   Newer› Newest»