Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4C248200B9D for ; Thu, 8 Sep 2016 02:42:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4AD78160AC1; Thu, 8 Sep 2016 00:42:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8F494160ACF for ; Thu, 8 Sep 2016 02:42:21 +0200 (CEST) Received: (qmail 48748 invoked by uid 500); 8 Sep 2016 00:42:20 -0000 Mailing-List: contact issues-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hive.apache.org Delivered-To: mailing list issues@hive.apache.org Received: (qmail 48583 invoked by uid 99); 8 Sep 2016 00:42:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Sep 2016 00:42:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 9CA022C1B7D for ; Thu, 8 Sep 2016 00:42:20 +0000 (UTC) Date: Thu, 8 Sep 2016 00:42:20 +0000 (UTC) From: "Lefty Leverenz (JIRA)" To: issues@hive.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (HIVE-14159) sorting of tuple array using multiple field[s] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 08 Sep 2016 00:42:22 -0000 [ https://issues.apache.org/jira/browse/HIVE-14159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Lefty Leverenz updated HIVE-14159: ---------------------------------- Labels: TODOC2.2 patch (was: patch) > sorting of tuple array using multiple field[s] > ---------------------------------------------- > > Key: HIVE-14159 > URL: https://issues.apache.org/jira/browse/HIVE-14159 > Project: Hive > Issue Type: Improvement > Components: UDF > Reporter: Simanchal Das > Assignee: Simanchal Das > Labels: TODOC2.2, patch > Fix For: 2.2.0 > > Attachments: HIVE-14159.1.patch, HIVE-14159.2.patch, HIVE-14159.3.patch, HIVE-14159.4.patch > > > Problem Statement: > When we are working with complex structure of data like avro. > Most of the times we are encountering array contains multiple tuples and each tuple have struct schema. > Suppose here struct schema is like below: > {noformat} > { > "name": "employee", > "type": [{ > "type": "record", > "name": "Employee", > "namespace": "com.company.Employee", > "fields": [{ > "name": "empId", > "type": "int" > }, { > "name": "empName", > "type": "string" > }, { > "name": "age", > "type": "int" > }, { > "name": "salary", > "type": "double" > }] > }] > } > {noformat} > Then while running our hive query complex array looks like array of employee objects. > {noformat} > Example: > //(array>) > Array[Employee(100,Foo,20,20990),Employee(500,Boo,30,50990),Employee(700,Harry,25,40990),Employee(100,Tom,35,70990)] > {noformat} > When we are implementing business use cases day to day life we are encountering problems like sorting a tuple array by specific field[s] like empId,name,salary,etc by ASC or DESC order. > Proposal: > I have developed a udf 'sort_array_by' which will sort a tuple array by one or more fields in ASC or DESC order provided by user ,default is ascending order . > {noformat} > Example: > 1.Select sort_array_field(array[struct(100,Foo,20,20990),struct(500,Boo,30,50990),struct(700,Harry,25,40990),struct(100,Tom,35,70990)],"Salary","ASC"); > output: array[struct(100,Foo,20,20990),struct(700,Harry,25,40990),struct(500,Boo,30,50990),struct(100,Tom,35,70990)] > > 2.Select sort_array_field(array[struct(100,Foo,20,20990),struct(500,Boo,30,80990),struct(500,Boo,30,50990),struct(700,Harry,25,40990),struct(100,Tom,35,70990)],"Name","Salary","ASC"); > output: array[struct(500,Boo,30,50990),struct(500,Boo,30,80990),struct(100,Foo,20,20990),struct(700,Harry,25,40990),struct(100,Tom,35,70990)] > 3.Select sort_array_field(array[struct(100,Foo,20,20990),struct(500,Boo,30,50990),struct(700,Harry,25,40990),struct(100,Tom,35,70990)],"Name","Salary","Age,"ASC"); > output: array[struct(500,Boo,30,50990),struct(500,Boo,30,80990),struct(100,Foo,20,20990),struct(700,Harry,25,40990),struct(100,Tom,35,70990)] > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332)