Return-Path: X-Original-To: apmail-drill-issues-archive@minotaur.apache.org Delivered-To: apmail-drill-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 52F321040E for ; Mon, 17 Nov 2014 01:35:59 +0000 (UTC) Received: (qmail 12929 invoked by uid 500); 17 Nov 2014 01:35:59 -0000 Delivered-To: apmail-drill-issues-archive@drill.apache.org Received: (qmail 12900 invoked by uid 500); 17 Nov 2014 01:35:59 -0000 Mailing-List: contact issues-help@drill.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.incubator.apache.org Delivered-To: mailing list issues@drill.incubator.apache.org Received: (qmail 12891 invoked by uid 99); 17 Nov 2014 01:35:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Nov 2014 01:35:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 17 Nov 2014 01:35:58 +0000 Received: (qmail 11912 invoked by uid 99); 17 Nov 2014 01:35:38 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Nov 2014 01:35:38 +0000 Date: Mon, 17 Nov 2014 01:35:38 +0000 (UTC) From: "Jacques Nadeau (JIRA)" To: issues@drill.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (DRILL-1716) Nested Data : There should be an easy way to apply aggregate functions on repeated types MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DRILL-1716?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jacques Nadeau updated DRILL-1716: ---------------------------------- Fix Version/s: 0.9.0 > Nested Data : There should be an easy way to apply aggregate functions on repeated types > ---------------------------------------------------------------------------------------- > > Key: DRILL-1716 > URL: https://issues.apache.org/jira/browse/DRILL-1716 > Project: Apache Drill > Issue Type: New Feature > Components: Functions - Drill, Storage - JSON > Reporter: Rahul Challapalli > Fix For: 0.9.0 > > > {code} > { > "company_id": 1, > "evnts": [ > { > "evnt_id": 999, > "evnt_duration": 60 > }, > { > "evnt_id": 998, > "evnt_duration": 30 > }, > { > "evnt_id": 997, > "evnt_duration": 45 > } > ] > } > {code} > For the above dataset, if I want to find the longest duration for each company id, below is how I would do it now > {code} > select sub.company_id , max(sub.evnt.evnt_duration) max_duration > from ( > select company_id, flatten(evnts) evnt from `nested.json` > ) sub > group by sub.company_id; > +------------+--------------+ > | company_id | max_duration | > +------------+--------------+ > | 1 | 60 | > +------------+--------------+ > {code} > Now if I want the evnt_id associated with the longest duration then we need one more join > {code} > select a.company_id, b.evnt.evnt_id > from ( > select sub.company_id company_id, max(sub.evnt.evnt_duration) max_duration > from ( > select company_id, flatten(evnts) evnt from `nested.json` > ) sub > group by sub.company_id > ) a > join > ( > select flatten(evnts) evnt from `nested.json` > ) b > on a.max_duration = b.evnt.evnt_duration; > {code} > The above query currently fails (DRILL-1649). But that is how we have to do it currently. > It would be much simpler if I can do something like the below > {code} > select company_id, nested_agg('evnts', 'max', 'evnt_duration','evnt_id') as evnt_id from `nested.json`; > {code} > Apart from making the query much simpler to write this might enhance drill's performance as well. > Thoughts? -- This message was sent by Atlassian JIRA (v6.3.4#6332)