[GitHub] incubator-madlib pull request #78: Graph: SSSP

2017-01-19 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/incubator-madlib/pull/78


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-19 Thread orhankislal
Github user orhankislal commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r93107178
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,372 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs using the Bellman-Ford
+algorhtm [1].
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+
+[1] https://en.wikipedia.org/wiki/Bellman-Ford_algorithm
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+   EPSILON = 1.0E-06
+
+   message = unique_string(desp='message')
+
+   oldupdate = unique_string(desp='oldupdate')
+   newupdate = unique_string(desp='newupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS {0},{1},{2}".format(
+   message,oldupdate,newupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST('Infinity' AS DOUBLE PRECISION) AS 
{weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {oldupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+   {local_distribution}
+   """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {newupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-16 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92910394
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,372 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs using the Bellman-Ford
+algorhtm [1].
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+
+[1] https://en.wikipedia.org/wiki/Bellman-Ford_algorithm
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+   EPSILON = 1.0E-06
+
+   message = unique_string(desp='message')
+
+   oldupdate = unique_string(desp='oldupdate')
+   newupdate = unique_string(desp='newupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS {0},{1},{2}".format(
+   message,oldupdate,newupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST('Infinity' AS DOUBLE PRECISION) AS 
{weight},
+   CAST({INT_MAX} AS INT) AS parent
--- End diff --

I think it'd be better to make that NULL instead of int_max. You can do 
that via `NULL::int AS parent`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-16 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92910625
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,372 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs using the Bellman-Ford
+algorhtm [1].
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+
+[1] https://en.wikipedia.org/wiki/Bellman-Ford_algorithm
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+   EPSILON = 1.0E-06
+
+   message = unique_string(desp='message')
+
+   oldupdate = unique_string(desp='oldupdate')
+   newupdate = unique_string(desp='newupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS {0},{1},{2}".format(
+   message,oldupdate,newupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST('Infinity' AS DOUBLE PRECISION) AS 
{weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {oldupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+   {local_distribution}
+   """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {newupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-16 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92910595
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,372 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs using the Bellman-Ford
+algorhtm [1].
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+
+[1] https://en.wikipedia.org/wiki/Bellman-Ford_algorithm
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+   EPSILON = 1.0E-06
+
+   message = unique_string(desp='message')
+
+   oldupdate = unique_string(desp='oldupdate')
+   newupdate = unique_string(desp='newupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS {0},{1},{2}".format(
+   message,oldupdate,newupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST('Infinity' AS DOUBLE PRECISION) AS 
{weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {oldupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+   {local_distribution}
+   """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {newupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-16 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92910466
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,372 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs using the Bellman-Ford
+algorhtm [1].
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+
+[1] https://en.wikipedia.org/wiki/Bellman-Ford_algorithm
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+   EPSILON = 1.0E-06
+
+   message = unique_string(desp='message')
+
+   oldupdate = unique_string(desp='oldupdate')
+   newupdate = unique_string(desp='newupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS {0},{1},{2}".format(
+   message,oldupdate,newupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST('Infinity' AS DOUBLE PRECISION) AS 
{weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {oldupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+   {local_distribution}
+   """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {newupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-16 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92910546
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,372 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs using the Bellman-Ford
+algorhtm [1].
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+
+[1] https://en.wikipedia.org/wiki/Bellman-Ford_algorithm
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+   EPSILON = 1.0E-06
+
+   message = unique_string(desp='message')
+
+   oldupdate = unique_string(desp='oldupdate')
+   newupdate = unique_string(desp='newupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS {0},{1},{2}".format(
+   message,oldupdate,newupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST('Infinity' AS DOUBLE PRECISION) AS 
{weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {oldupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+   {local_distribution}
+   """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {newupdate}(
+   id INT, val DOUBLE PRECISION, parent INT)
+  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread orhankislal
Github user orhankislal commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92069560
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
--- End diff --

Yes, it can only be called from inside the database. No, it is not a 
SECURITY DEFINER function.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92069133
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
--- End diff --

Well, the issue exists throughout the code. Maybe it's just not worth 
worrying about... this code can only be called from inside the database anyway, 
right? If you're already in the database, you don't need SQL injection to break 
things, UNLESS the function is SECURITY DEFINER (which presumably this is not).


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread orhankislal
Github user orhankislal commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92064461
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
--- End diff --

Would this be an improvement for the ease-of-use only or the performance as 
well? Even if we give that as an option, the current implementation of the 
algorithm requires a place to store the intermediate results. Since this is in 
the order of O(|V|) we would still need a table for it.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92044676
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
--- End diff --

There should be some kind of documentation about the algorithm used; at 
least a reference to the wiki article.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92041602
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST({INT_MAX} AS INT) AS {weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+
+   plpy.execute(
+   """ CREATE TEMP TABLE {message}(
+   id INT, val INT, parent INT)
+   {local_distribution} """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {toupdate}(
+   id INT, val INT, parent INT)
+   {local_distribution} """.format(**locals()))
+   temp_table = unique_string(desp='temp')
+   sql = m4_ifdef(,
+   """ CREATE TABLE {temp_table} (
+   {vertex_id} INT, {weight} INT, parent 
INT) {distribution};
+   """,  )
  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92051375
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST({INT_MAX} AS INT) AS {weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+
+   plpy.execute(
+   """ CREATE TEMP TABLE {message}(
--- End diff --

Ok, after reading [2], I see why this is called messages.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92054290
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
+
+   plpy.execute(
+   """ CREATE TABLE {out_table} AS
+   SELECT {vertex_id}::INT AS {vertex_id},
+   CAST({INT_MAX} AS INT) AS {weight},
+   CAST({INT_MAX} AS INT) AS parent
+   FROM {vertex_table} {distribution} 
""".format(**locals()))
+
+   plpy.execute(
+   """ CREATE TEMP TABLE {message}(
+   id INT, val INT, parent INT)
+   {local_distribution} """.format(**locals()))
+   plpy.execute(
+   """ CREATE TEMP TABLE {toupdate}(
+   id INT, val INT, parent INT)
+   {local_distribution} """.format(**locals()))
+   temp_table = unique_string(desp='temp')
+   sql = m4_ifdef(,
+   """ CREATE TABLE {temp_table} (
+   {vertex_id} INT, {weight} INT, parent 
INT) {distribution};
+   """,  )
  

[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-12 Thread decibel
Github user decibel commented on a diff in the pull request:

https://github.com/apache/incubator-madlib/pull/78#discussion_r92040714
  
--- Diff: src/ports/postgres/modules/graph/sssp.py_in ---
@@ -0,0 +1,347 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Single Source Shortest Path
+
+# Please refer to the sssp.sql_in file for the documentation
+
+"""
+@file sssp.py_in
+
+@namespace graph
+"""
+
+import plpy
+from utilities.control import MinWarning
+from utilities.utilities import _assert
+from utilities.utilities import extract_keyvalue_params
+from utilities.utilities import unique_string
+from utilities.validate_args import get_cols
+from utilities.validate_args import unquote_ident
+from utilities.validate_args import table_exists
+from utilities.validate_args import columns_exist_in_table
+from utilities.validate_args import table_is_empty
+
+m4_changequote(`')
+
+def graph_sssp(schema_madlib, vertex_table, vertex_id, edge_table,
+   edge_args, source_vertex, out_table, **kwargs):
+   """
+Single source shortest path function for graphs
+Args:
+@param vertex_table Name of the table that contains the vertex 
data.
+@param vertex_idName of the column containing the vertex 
ids.
+@param edge_table   Name of the table that contains the edge 
data.
+@param edge_argsA comma-delimited string containing 
multiple
+   named arguments of the 
form "name=value".
+@param source_vertexThe source vertex id for the algorithm to 
start.
+@param out_table   Name of the table to store the 
result of SSSP.
+"""
+
+   with MinWarning("warning"):
+
+   INT_MAX = 2147483647
+
+   message = unique_string(desp='message')
+   toupdate = unique_string(desp='toupdate')
+
+   params_types = {'src': str, 'dest': str, 'weight': str}
+   default_args = {'src': 'src', 'dest': 'dest', 'weight': 
'weight'}
+   edge_params = extract_keyvalue_params(edge_args,
+params_types,
+default_args)
+   if vertex_id is None:
+   vertex_id = "id"
+
+   src = edge_params["src"]
+   dest = edge_params["dest"]
+   weight = edge_params["weight"]
+
+   distribution = m4_ifdef(, ,
+   )
+   local_distribution = m4_ifdef(, ,
+   )
+
+   validate_graph_coding(vertex_table, vertex_id, edge_table,
+   edge_params, source_vertex, out_table)
+
+   plpy.execute(" DROP TABLE IF EXISTS 
{0},{1}".format(message,toupdate))
--- End diff --

There's a SQL-injection risk here. Additionally, this assumes that 
`message` and `toupdate` are correctly quoted. But maybe that's OK in this 
context...


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-madlib pull request #78: Graph: SSSP

2016-12-05 Thread orhankislal
GitHub user orhankislal opened a pull request:

https://github.com/apache/incubator-madlib/pull/78

Graph: SSSP

JIRA: MADLIB-992

- Introduces a new module: Graph.
- Implements the single source shortest path algorithm (Bellman-Ford).

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/orhankislal/incubator-madlib feature/graph_bf3

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-madlib/pull/78.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 #78


commit 298aeae2ab31bd59edac5e7784c53816844988ab
Author: Orhan Kislal 
Date:   2016-12-05T17:38:42Z

Graph: SSSP

JIRA: MADLIB-992

- Introduces a new module: Graph.
- Implements the single source shortest path algorithm (Bellman-Ford).




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---