madlib-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iyerr3 <...@git.apache.org>
Subject [GitHub] incubator-madlib pull request #65: Pivoting
Date Tue, 23 Aug 2016 00:27:47 GMT
Github user iyerr3 commented on a diff in the pull request:

    https://github.com/apache/incubator-madlib/pull/65#discussion_r75784656
  
    --- Diff: src/ports/postgres/modules/utilities/pivot.py_in ---
    @@ -234,30 +235,46 @@ def pivot(schema_madlib, source_table, out_table, index, pivot_cols,
                         dict_counter += 1
                     # Collecting the whole sql query
                     # Please refer to the earlier comment for a sample output
    -                pivot_str = ("{fill_str_begin}"
    -                             "{agg} (CASE WHEN {pivot_begin} THEN {pval} END) "
    -                             "{fill_str_end} AS {pivot_end}".
    -                             format(fill_str_begin=fill_str_begin,
    +
    +                # Create the masked set
    +                pivot_str_from = ("(CASE WHEN {pivot_begin} THEN {pval} END) "
    +                            "AS {pivot_end}".
    +                            format(fill_str_begin=fill_str_begin,
    +                                    fill_str_end=fill_str_end,
    +                                    pval=pval, agg=agg,
    +                                    pivot_begin=' AND '.join(pivot_str_begin),
    +                                    pivot_end=''.join(pivot_str_end)))
    +                pivot_str_from_list.append("," + pivot_str_from)
    +                # Apply the aggregate and filtering
    +                pivot_str_sel = ("{fill_str_begin}"
    +                            "{agg} ({pivot_end}) FILTER ("
    +                            "WHERE {pivot_end} IS NOT NULL) "
    +                            "{fill_str_end} AS {pivot_end}".
    +                            format(fill_str_begin=fill_str_begin,
                                         fill_str_end=fill_str_end,
                                         pval=pval, agg=agg,
                                         pivot_begin=' AND '.join(pivot_str_begin),
                                         pivot_end=''.join(pivot_str_end)))
    -                pivot_out_list.append("," + pivot_str)
    +                pivot_str_sel_list.append("," + pivot_str_sel)
    --- End diff --
    
    Would be nicer to only add `pivot_str_sel` in the list and let `join` take care of adding
the commas. 


---
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.
---

Mime
View raw message