Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 499E81835C for ; Wed, 5 Aug 2015 10:09:36 +0000 (UTC) Received: (qmail 79661 invoked by uid 500); 5 Aug 2015 10:09:33 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 79624 invoked by uid 500); 5 Aug 2015 10:09:33 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 79613 invoked by uid 99); 5 Aug 2015 10:09:33 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Aug 2015 10:09:33 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 182A31A10E1 for ; Wed, 5 Aug 2015 10:09:33 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.001 X-Spam-Level: **** X-Spam-Status: No, score=4.001 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=3, KAM_LAZY_DOMAIN_SECURITY=1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id VBV86Rm5g4yN for ; Wed, 5 Aug 2015 10:09:23 +0000 (UTC) Received: from mail-yk0-f170.google.com (mail-yk0-f170.google.com [209.85.160.170]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id D6A8A2104D for ; Wed, 5 Aug 2015 10:09:22 +0000 (UTC) Received: by ykeo23 with SMTP id o23so30982509yke.3 for ; Wed, 05 Aug 2015 03:09:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=E02oeBi6e9gI15yGZhRjhdzLersvFLd4+esWRAwh+XY=; b=fg+xwR5f+xfW9q+pNTSMBfjGyQOg3ofFY9+YNZSo4XjOP4QbEErPygjbQsb436SGKN rd+5XSucbBLk9e2UZ/tK4ke8Vp/YgFpIzsJVWABUfBh/tVgVJ4oTiQYBk+ctKzdDha0h hsVQAmEPWfMuLanumXfjpH+/6otrRaxrYVlT3xqv0jCYvcZPY8Ad3UfqxFJtAx2xrcIY F83lGSjv/1ZCHinNiAMwLmGxCRwPo0aEXdvXErnb603gD9QKkflWvdHMaQopT193WLoW 0oo3Qh6EiX2dKg8PTuWPZyJ9RHvYdQei3s5yKRPQLV6XE723hAP2d08L94TaqOFOAjhW NTmg== X-Gm-Message-State: ALoCoQn8JBhFcgkD8BM9snM1nTeWPx6pcWhSQUbiCwLnEkMzXjjWGWoGDg+BI9CDOWEsx03CaOiz MIME-Version: 1.0 X-Received: by 10.13.219.132 with SMTP id d126mr8778332ywe.22.1438769356540; Wed, 05 Aug 2015 03:09:16 -0700 (PDT) Received: by 10.37.8.194 with HTTP; Wed, 5 Aug 2015 03:09:16 -0700 (PDT) X-Originating-IP: [117.198.142.155] Date: Wed, 5 Aug 2015 15:39:16 +0530 Message-ID: Subject: Cassandra: UDF From: Suresh Mahawar To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=001a114faf8a698e05051c8d9835 --001a114faf8a698e05051c8d9835 Content-Type: text/plain; charset=UTF-8 Hi, I need your help. I have a query which get top 5 records group by date (not date + time) and sum of amount. I wrote the following but it returns all the records not just top 5 records CREATE OR REPLACE FUNCTION state_groupbyandsum( state map, datetime text, amount text ) CALLED ON NULL INPUT RETURNS map LANGUAGE java AS 'String date = datetime.substring(0,10); Double count = (Double) state.get(date); if (count == null) count = Double.parseDouble(amount); else count = count + Double.parseDouble(amount); state.put(date, count); return state;' ; CREATE OR REPLACE AGGREGATE groupbyandsum(text, text) SFUNC state_groupbyandsum STYPE map INITCOND {}; select groupbyandsum(datetime, amout) from warehouse; Could you please help out to get just 5 records. Thanks & Regards, Suresh Mahawar TechnoCube Find Me on Linkedin --001a114faf8a698e05051c8d9835 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,
=

I need your help. I have a query which get top 5 record= s group by date (not date + time) and sum of amount.

I wrote the following but it returns all the records not just top 5 reco= rds

CREATE OR REPLACE FUNCTION state_groupbyandsum( state map<text, doub= le>, datetime text, amount text )
CALLED ON NULL INPUT
RETURNS map<text, double>
LANGUAGE = java=C2=A0
AS 'String date =3D datetime.substring(0,10); Double count =3D (Doub= le) state.get(date); =C2=A0if (count =3D=3D null) count =3D Double.parseDou= ble(amount); else count =3D count + =C2=A0Double.parseDouble(amount); state= .put(date, count); return state;' ;

CREATE OR REP= LACE AGGREGATE groupbyandsum(text, text)=C2=A0
SFUNC state_groupbyandsum
STYPE map<text,= double>
INITCOND {};

select groupbyandsum(datetime, amout) from= warehouse;
Could you please help ou= t to get just 5 records.


Thanks & Re= gards,
Suresh Mahawar
TechnoCube
Find Me on=C2=A0Linkedin
--001a114faf8a698e05051c8d9835--