Github user njayaram2 commented on a diff in the pull request:

    https://github.com/apache/incubator-madlib/pull/141#discussion_r122319562
  
    --- Diff: src/ports/postgres/modules/graph/bfs.py_in ---
    @@ -0,0 +1,445 @@
    +# 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.
    +
    +# Breadth-First Search
    +
    +# Please refer to the bfs.sql_in file for the documentation
    +
    +"""
    +@file bfs.py_in
    +
    +@namespace graph
    +"""
    +
    +import plpy
    +from graph_utils import *
    +from utilities.control import MinWarning
    +from utilities.utilities import _assert
    +from utilities.utilities import extract_keyvalue_params
    +from utilities.utilities import split_quoted_delimited_str
    +from utilities.validate_args import table_exists
    +from utilities.validate_args import columns_exist_in_table
    +
    +m4_changequote(`<!', `!>')
    +
    +def _validate_bfs(vertex_table, vertex_id, edge_table, edge_params,
    +    source_vertex, out_table, max_distance, directed, grouping_cols_list, 
**kwargs):
    +
    +    validate_graph_coding(vertex_table, vertex_id, edge_table, edge_params,
    +        out_table,'BFS')
    +
    +    _assert((max_distance >= 0) and isinstance(max_distance,int),
    +        """Graph BFS: Invalid max_distance type or value ({0}), must be 
integer, 
    +        be greater than or equal to 0 and be less than max allowable 
integer 
    +        (2147483647).""".
    +        format(max_distance))
    +
    +    _assert(isinstance(directed,bool),
    +        """Graph BFS: Invalid value for directed ({0}), must be 
boolean.""".
    +        format(directed))
    +
    +    _assert(isinstance(source_vertex,int),
    +        """Graph BFS: Source vertex {source_vertex} has to be an 
integer.""".
    +        format(**locals()))
    +    src_exists = plpy.execute("""
    +        SELECT * FROM {vertex_table} WHERE {vertex_id}={source_vertex}
    +        """.format(**locals()))
    +    if src_exists.nrows() == 0:
    +        plpy.error(
    +            """Graph BFS: Source vertex {source_vertex} is not present in 
the 
    +            vertex table {vertex_table}.""".
    +            format(**locals()))
    +
    +    vt_error = plpy.execute(
    +        """ SELECT {vertex_id}
    +            FROM {vertex_table}
    +            WHERE {vertex_id} IS NOT NULL
    +            GROUP BY {vertex_id}
    +            HAVING count(*) > 1 """.format(**locals()))
    +    if vt_error.nrows() != 0:
    +        plpy.error(
    +            """Graph BFS: Source vertex table {vertex_table} contains 
duplicate 
    +            vertex id's.""".
    +            format(**locals()))
    +
    +    _assert(not table_exists(out_table+"_summary"),
    +        "Graph BFS: Output summary table already exists!")
    +
    +    if grouping_cols_list is not None:
    +        _assert(columns_exist_in_table(edge_table, grouping_cols_list),
    +            """Graph BFS: Not all columns from {grouping_cols_list} are 
present 
    +            in edge table ({edge_table}).""".
    +            format(**locals()))
    +
    +    return None
    +
    +def _grp_from_table(tbl, grp_list):
    +
    +    """
    +    Helper function for selecting grouping columns of a table
    +    Args:
    +        @param tbl        Name of the table
    +        @param grp_list   The list of grouping columns
    +    """
    +    return ' , '.join([" {tbl}.{i} ".format(**locals())
    +        for i in grp_list])
    +
    +def _grp_null_checks(grp_list):
    +
    +    """
    +    Helper function for generating NULL checks for grouping columns 
    +    to be used within a WHERE clause
    +    Args:
    +        @param grp_list   The list of grouping columns
    +    """
    +    return ' AND '.join([" {i} IS NOT NULL ".format(**locals())
    +        for i in grp_list])
    +
    --- End diff --
    
    Might be a good idea to move functions `_grp_null_checks ` and 
`_grp_from_table ` to `utilities.validate_args.py_in`. If you do, I would 
recommend changing the function names to capture the fact that these would 
return some sql clauses.


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

Reply via email to