You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@madlib.apache.org by orhankislal <gi...@git.apache.org> on 2016/08/22 22:02:59 UTC
[GitHub] incubator-madlib pull request #65: Pivoting
GitHub user orhankislal opened a pull request:
https://github.com/apache/incubator-madlib/pull/65
Pivoting
Adds filter for removing nulls from the aggregated results.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/orhankislal/incubator-madlib feature/pivoting_take6
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-madlib/pull/65.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #65
----
commit e9b1d3a7922504b6633a6a71dfd46da860c1d10f
Author: Orhan Kislal <ok...@pivotal.io>
Date: 2016-08-22T17:24:54Z
Pivoting
Adds filter for removing nulls from the aggregated results.
----
---
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.
---
[GitHub] incubator-madlib pull request #65: Pivoting
Posted by orhankislal <gi...@git.apache.org>.
Github user orhankislal commented on a diff in the pull request:
https://github.com/apache/incubator-madlib/pull/65#discussion_r75954265
--- Diff: src/ports/postgres/modules/utilities/test/pivot.sql_in ---
@@ -152,15 +152,19 @@ SELECT assert(__p_7__ = 1.5,
'Wrong output in pivoting: Output dictionary') FROM pivout
WHERE id = 0 AND id2 = 0;
-DROP AGGREGATE IF EXISTS array_accum (anyelement);
-CREATE AGGREGATE array_accum (anyelement)
-(
- sfunc = array_append,
+DROP FUNCTION IF EXISTS array_add1(ANYARRAY, ANYELEMENT);
+DROP AGGREGATE IF EXISTS array_accum1 (anyelement);
+CREATE FUNCTION array_add1(ANYARRAY, ANYELEMENT) RETURNS ANYARRAY AS $$
+ SELECT $1 || $2
+$$ LANGUAGE sql STRICT;
--- End diff --
I still appreciate the pointer. This test exists to ensure user defined aggregates work with pivoting in addition to the built-in ones.
---
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.
---
[GitHub] incubator-madlib pull request #65: Pivoting
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-madlib/pull/65
---
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.
---
[GitHub] incubator-madlib pull request #65: Pivoting
Posted by iyerr3 <gi...@git.apache.org>.
Github user iyerr3 commented on a diff in the pull request:
https://github.com/apache/incubator-madlib/pull/65#discussion_r75784595
--- 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,
--- End diff --
We don't need the additional format specifiers
---
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.
---
[GitHub] incubator-madlib issue #65: Pivoting
Posted by orhankislal <gi...@git.apache.org>.
Github user orhankislal commented on the issue:
https://github.com/apache/incubator-madlib/pull/65
Thanks for the comments @iyerr3. I made the changes to clean up the code.
---
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.
---
[GitHub] incubator-madlib pull request #65: Pivoting
Posted by decibel <gi...@git.apache.org>.
Github user decibel commented on a diff in the pull request:
https://github.com/apache/incubator-madlib/pull/65#discussion_r75951816
--- Diff: src/ports/postgres/modules/utilities/test/pivot.sql_in ---
@@ -152,15 +152,19 @@ SELECT assert(__p_7__ = 1.5,
'Wrong output in pivoting: Output dictionary') FROM pivout
WHERE id = 0 AND id2 = 0;
-DROP AGGREGATE IF EXISTS array_accum (anyelement);
-CREATE AGGREGATE array_accum (anyelement)
-(
- sfunc = array_append,
+DROP FUNCTION IF EXISTS array_add1(ANYARRAY, ANYELEMENT);
+DROP AGGREGATE IF EXISTS array_accum1 (anyelement);
+CREATE FUNCTION array_add1(ANYARRAY, ANYELEMENT) RETURNS ANYARRAY AS $$
+ SELECT $1 || $2
+$$ LANGUAGE sql STRICT;
--- End diff --
Oh, just noticed this is just a test file, so guess it probably doesn't matter...
---
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.
---
[GitHub] incubator-madlib pull request #65: Pivoting
Posted by decibel <gi...@git.apache.org>.
Github user decibel commented on a diff in the pull request:
https://github.com/apache/incubator-madlib/pull/65#discussion_r75951733
--- Diff: src/ports/postgres/modules/utilities/test/pivot.sql_in ---
@@ -152,15 +152,19 @@ SELECT assert(__p_7__ = 1.5,
'Wrong output in pivoting: Output dictionary') FROM pivout
WHERE id = 0 AND id2 = 0;
-DROP AGGREGATE IF EXISTS array_accum (anyelement);
-CREATE AGGREGATE array_accum (anyelement)
-(
- sfunc = array_append,
+DROP FUNCTION IF EXISTS array_add1(ANYARRAY, ANYELEMENT);
+DROP AGGREGATE IF EXISTS array_accum1 (anyelement);
+CREATE FUNCTION array_add1(ANYARRAY, ANYELEMENT) RETURNS ANYARRAY AS $$
+ SELECT $1 || $2
+$$ LANGUAGE sql STRICT;
--- End diff --
It would be best to also mark this as IMMUTABLE so the executor can inline it. (It would be even better to use the built-in array_agg if it exists; it's probably even faster.)
---
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.
---
[GitHub] incubator-madlib pull request #65: Pivoting
Posted by iyerr3 <gi...@git.apache.org>.
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.
---