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

    https://github.com/apache/incubator-madlib/pull/89#discussion_r97463365
  
    --- Diff: src/ports/postgres/modules/kmeans/kmeans.py_in ---
    @@ -34,6 +37,25 @@ def kmeans_validate_src(schema_madlib, rel_source, 
**kwargs):
     
     # ----------------------------------------------------------------------
     
    +def kmeans_validate_expr(schema_madlib, rel_source, expr_point, **kwargs):
    +    if not columns_exist_in_table(rel_source, [expr_point]):
    +
    +        p = re.compile('[Aa][Rr][Rr][Aa][Yy]\s*\[\s*[\s*\w|,\s*]+\s*\]')
    +
    +        if p.match(expr_point.strip()):
    +            view_name = unique_string('km_view')
    +
    +            plpy.execute(""" CREATE VIEW {view_name} AS
    +                SELECT {expr_point} AS expr FROM {rel_source}
    +                """.format(**locals()))
    +            return view_name,True
    +        else:
    +            plpy.error(
    +                """kmeans error: {expr_point} does not exist in 
{rel_source}!
    +                """.format(**locals()))
    +    return rel_source, False
    +
    --- End diff --
    
    It would be kinda nice to pre-compile the re by sticking a 
`kmeans_validate_expr.p = re.compile(...)` down here, as per 
http://stackoverflow.com/questions/279561/what-is-the-python-equivalent-of-static-variables-inside-a-function.
 Others might well have different ideas about that, though.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to