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 32129200B57 for ; Sat, 23 Jul 2016 02:08:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 308A4160A8E; Sat, 23 Jul 2016 00:08:12 +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 78227160A6D for ; Sat, 23 Jul 2016 02:08:11 +0200 (CEST) Received: (qmail 28655 invoked by uid 500); 23 Jul 2016 00:08:10 -0000 Mailing-List: contact dev-help@madlib.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@madlib.incubator.apache.org Delivered-To: mailing list dev@madlib.incubator.apache.org Received: (qmail 28644 invoked by uid 99); 23 Jul 2016 00:08:10 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jul 2016 00:08:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id DF8F71876E2 for ; Sat, 23 Jul 2016 00:08:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.446 X-Spam-Level: X-Spam-Status: No, score=-5.446 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 7HKqUg5GQUy1 for ; Sat, 23 Jul 2016 00:08:07 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id E794360D27 for ; Sat, 23 Jul 2016 00:08:06 +0000 (UTC) Received: (qmail 28622 invoked by uid 99); 23 Jul 2016 00:08:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jul 2016 00:08:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B5513E058E; Sat, 23 Jul 2016 00:08:05 +0000 (UTC) From: orhankislal To: dev@madlib.incubator.apache.org Reply-To: dev@madlib.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-madlib pull request #54: Pivoting: Phase 2 Content-Type: text/plain Message-Id: <20160723000805.B5513E058E@git1-us-west.apache.org> Date: Sat, 23 Jul 2016 00:08:05 +0000 (UTC) archived-at: Sat, 23 Jul 2016 00:08:12 -0000 Github user orhankislal commented on a diff in the pull request: https://github.com/apache/incubator-madlib/pull/54#discussion_r71961520 --- Diff: src/ports/postgres/modules/utilities/pivot.py_in --- @@ -58,66 +61,255 @@ def pivot(schema_madlib, source_table, out_table, pivoted table @param aggregate_func The aggregate function to be applied to the values + @param fill_value If specified, determines how to fill NULL + values resulting from pivot operation + @param keep_null The flag for determining how to handle NULL + values in pivot columns """ - """ Assume we have the following table pivset( id INTEGER, piv FLOAT8, val FLOAT8 ) - where the piv column has 3 distinct values (10.0, 20.0 and 30.0). + where the piv column has 3 distinct values (10, 20 and 30). If the pivot function call is : SELECT madlib.pivot('pivset', 'pivout', 'id', 'piv', 'val'); We want to construct the following sql code to pivot the table. CREATE TABLE pivout AS (SELECT id, - sum(CASE WHEN "piv" = '10.0' THEN val ELSE NULL END ) as "piv_10.0", - sum(CASE WHEN "piv" = '20.0' THEN val ELSE NULL END ) as "piv_20.0", - sum(CASE WHEN "piv" = '30.0' THEN val ELSE NULL END ) as "piv_30.0" + avg(CASE WHEN "piv" = '10' THEN val ELSE NULL END ) as "val_avg_piv_10", + avg(CASE WHEN "piv" = '20' THEN val ELSE NULL END ) as "val_avg_piv_20", + avg(CASE WHEN "piv" = '30' THEN val ELSE NULL END ) as "val_avg_piv_30" FROM pivset GROUP BY id ORDER BY id) """ + indices = split_quoted_delimited_str(index) - pcol = split_quoted_delimited_str(pivot_cols) - pval = split_quoted_delimited_str(pivot_values) - validate_pivot_coding(source_table, out_table, indices, pcol, pval) - new_col_names =[] - sql_list = ["CREATE TABLE " + out_table + " AS (SELECT " + index] + pcols = split_quoted_delimited_str(pivot_cols) + pvals = split_quoted_delimited_str(pivot_values) + validate_pivot_coding(source_table, out_table, indices, pcols, pvals) - pcol_no_quotes = strip_end_quotes(pcol[0].strip()) - pval_no_quotes = strip_end_quotes(pval[0].strip()) + # Strip end quotes from pivot columns + pcols = [strip_end_quotes(pcol.strip()) for pcol in pcols] + pvals = [strip_end_quotes(pval.strip()) for pval in pvals] + + # Parse the aggregate_func as a dictionary + try: + param_types = dict.fromkeys(pvals, list) + param_types['__madlib_def_pval__'] = list --- End diff -- It can be removed. I moved the default aggregate but forgot to remove this line. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---