You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by xt...@apache.org on 2016/07/28 17:16:51 UTC
incubator-madlib git commit: Path: Add examples to online help.
Repository: incubator-madlib
Updated Branches:
refs/heads/master 195ad6436 -> 01518122b
Path: Add examples to online help.
Closes #59
Project: http://git-wip-us.apache.org/repos/asf/incubator-madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-madlib/commit/01518122
Tree: http://git-wip-us.apache.org/repos/asf/incubator-madlib/tree/01518122
Diff: http://git-wip-us.apache.org/repos/asf/incubator-madlib/diff/01518122
Branch: refs/heads/master
Commit: 01518122b398bb23c5b4ce6a545ab7e541b235e4
Parents: 195ad64
Author: Nandish Jayaram <nj...@pivotal.io>
Authored: Wed Jul 27 14:42:58 2016 -0700
Committer: Xiaocheng Tang <xi...@gmail.com>
Committed: Thu Jul 28 10:15:33 2016 -0700
----------------------------------------------------------------------
src/ports/postgres/modules/utilities/path.py_in | 108 ++++++++++++++++---
1 file changed, 95 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/01518122/src/ports/postgres/modules/utilities/path.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/utilities/path.py_in b/src/ports/postgres/modules/utilities/path.py_in
index 2b3085a..8559116 100644
--- a/src/ports/postgres/modules/utilities/path.py_in
+++ b/src/ports/postgres/modules/utilities/path.py_in
@@ -308,20 +308,28 @@ def _parse_symbol_str(symbol_expr, pattern_expr):
def path_help_message(schema_madlib, message, **kwargs):
""" Help message for path function
"""
- help_string = """
-------------------------------------------------------------
- SUMMARY
-------------------------------------------------------------
+ summary_string = """
+---------------------------------------------------------------------------
+ SUMMARY
+---------------------------------------------------------------------------
Functionality: Path
-The goal of the MADlib path function is to perform regular pattern
-matching over a sequence of rows, and to extract useful information about the
-matches. The useful information could be a simple count of matches or
-something more involved like aggregation.
+The goal of the MADlib path function is to perform regular pattern matching
+over a sequence of rows, and to extract useful information about the matches.
+The useful information could be a simple count of matches or something more
+involved like aggregation.
-------------------------------------------------------------
- USAGE
-------------------------------------------------------------
+For more details on function usage:
+ SELECT {schema_madlib}.path('usage');
+
+For a small example on using the function:
+ SELECT {schema_madlib}.path('example');
+ """.format(schema_madlib=schema_madlib)
+
+ usage_string = """
+---------------------------------------------------------------------------
+ USAGE
+---------------------------------------------------------------------------
SELECT {schema_madlib}.path(
'source_table', -- Name of the table
'output_table', -- Table name to store the path results
@@ -333,6 +341,80 @@ SELECT {schema_madlib}.path(
persist_rows -- Boolean indicating whether to output the matched rows
-- in an additional table (named <output_table>_tuples)
);
-"""
- return help_string.format(schema_madlib=schema_madlib)
+ """.format(schema_madlib=schema_madlib)
+
+ example_string = """
+---------------------------------------------------------------------------
+ EXAMPLE
+---------------------------------------------------------------------------
+- Create an input data set.
+
+DROP TABLE IF EXISTS eventlog, path_output, path_output_tuples;
+CREATE TABLE eventlog (event_timestamp TIMESTAMP,
+ user_id INT,
+ session_id INT,
+ page TEXT,
+ revenue FLOAT);
+INSERT INTO eventlog VALUES
+('04/15/2015 01:03:00', 100821, 100, 'LANDING', 0),
+('04/15/2015 01:04:00', 100821, 100, 'WINE', 0),
+('04/15/2015 01:05:00', 100821, 100, 'CHECKOUT', 39),
+('04/15/2015 02:06:00', 100821, 101, 'WINE', 0),
+('04/15/2015 02:09:00', 100821, 101, 'WINE', 0),
+('04/15/2015 01:15:00', 101121, 102, 'LANDING', 0),
+('04/15/2015 01:16:00', 101121, 102, 'WINE', 0),
+('04/15/2015 01:17:00', 101121, 102, 'CHECKOUT', 15),
+('04/15/2015 01:18:00', 101121, 102, 'LANDING', 0),
+('04/15/2015 01:19:00', 101121, 102, 'HELP', 0),
+('04/15/2015 01:21:00', 101121, 102, 'WINE', 0),
+('04/15/2015 01:22:00', 101121, 102, 'CHECKOUT', 23),
+('04/15/2015 02:15:00', 101331, 103, 'LANDING', 0),
+('04/15/2015 02:16:00', 101331, 103, 'WINE', 0),
+('04/15/2015 02:17:00', 101331, 103, 'HELP', 0),
+('04/15/2015 02:18:00', 101331, 103, 'WINE', 0),
+('04/15/2015 02:19:00', 101331, 103, 'CHECKOUT', 16),
+('04/15/2015 02:22:00', 101443, 104, 'BEER', 0),
+('04/15/2015 02:25:00', 101443, 104, 'CHECKOUT', 12),
+('04/15/2015 02:29:00', 101881, 105, 'LANDING', 0),
+('04/15/2015 02:30:00', 101881, 105, 'BEER', 0),
+('04/15/2015 01:05:00', 102201, 106, 'LANDING', 0),
+('04/15/2015 01:06:00', 102201, 106, 'HELP', 0),
+('04/15/2015 01:09:00', 102201, 106, 'LANDING', 0),
+('04/15/2015 02:15:00', 102201, 107, 'WINE', 0),
+('04/15/2015 02:16:00', 102201, 107, 'BEER', 0),
+('04/15/2015 02:17:00', 102201, 107, 'WINE', 0),
+('04/15/2015 02:18:00', 102871, 108, 'BEER', 0),
+('04/15/2015 02:19:00', 102871, 108, 'WINE', 0),
+('04/15/2015 02:22:00', 102871, 108, 'CHECKOUT', 21),
+('04/15/2015 02:25:00', 102871, 108, 'LANDING', 0),
+('04/15/2015 02:17:00', 103711, 109, 'BEER', 0),
+('04/15/2015 02:18:00', 103711, 109, 'LANDING', 0),
+('04/15/2015 02:19:00', 103711, 109, 'WINE', 0);
+
+- Calculate the revenue by checkout:
+
+SELECT {schema_madlib}.path(
+ 'eventlog', -- Name of input table
+ 'path_output', -- Table name to store path results
+ 'session_id', -- Partition input table by session
+ 'event_timestamp ASC', -- Order partitions in input table by time
+ 'buy:=page=''CHECKOUT''', -- Define a symbol for checkout events
+ '(buy)', -- Pattern search: purchase
+ 'sum(revenue) as checkout_rev', -- Aggregate: sum revenue by checkout
+ TRUE -- Persist matches
+ );
+
+SELECT * FROM path_output ORDER BY session_id, match_id;
+ """.format(schema_madlib=schema_madlib)
+
+ if not message:
+ return summary_string
+ elif message.lower() in ('usage', 'help', '?'):
+ return usage_string
+ elif message.lower() in ('example', 'examples'):
+ return example_string
+ else:
+ return """
+No such option. Use "SELECT {schema_madlib}.path()" for help.
+ """.format(schema_madlib=schema_madlib)
# ------------------------------------------------------------