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

    https://github.com/apache/incubator-madlib/pull/69#discussion_r86653948
  
    --- Diff: 
src/ports/postgres/modules/elastic_net/elastic_net_generate_result.py_in ---
    @@ -13,50 +14,99 @@ def __elastic_net_generate_result (optimizer, 
iteration_run, **args):
         """
         Generate result table for all optimizers
         """
    -    plpy.execute("""
    -                 drop table if exists {tbl_result};
    -                 create table {tbl_result} (
    -                     family            text,
    -                     features          text[],
    -                     features_selected text[],
    -                     coef_nonzero      double precision[],
    -                     coef_all          double precision[],
    -                     intercept         double precision,
    -                     log_likelihood    double precision,
    -                     standardize       boolean,
    -                     iteration_run     integer)
    -                 """.format(**args))
    -
         standardize_flag = "True" if args["normalization"] else "False"
    -
    +    source_table = args["rel_source"]
         if optimizer == "fista":
    -        result_func = "__gaussian_fista_result(_state)"
    -        tbl_state = "{tbl_fista_state}"
    +        result_func = 
"__gaussian_fista_result({col_grp_state})".format(col_grp_state=args["col_grp_state"])
    +        tbl_state = "{rel_state}".format(rel_state=args["rel_state"])
         elif optimizer == "igd":
             result_func = "__gaussian_igd_result(_state, '{sq_str}'::double 
precision[], {threshold}::double precision, {tolerance}::double precision)"
             tbl_state = "{tbl_igd_state}"
     
    -    result = plpy.execute(
    -        """
    -        select
    -            (result).coefficients as coef,
    -            (result).intercept as intercept
    -        from (
    -            select {{schema_madlib}}.{result_func} as result
    -            from {tbl_state}
    -            where _iteration = {{iteration_run}}
    +    grouping_column = args['grouping_col']
    +    col_grp_key = args['col_grp_key']
    +    grouping_str = args['grouping_str']
    +    groupby_str, grouping_str1, using_str = "", "", "ON TRUE"
    +    if grouping_column:
    +        groupby_str = "GROUP BY {grouping_col}, {col_grp_key}".format(
    +            grouping_col=grouping_column, col_grp_key=col_grp_key)
    +        grouping_str1 = grouping_column + ","
    +        select_grouping_info = ','.join([grp_col.strip()+"\t text" 
    +            for grp_col in grouping_column.split(',')]) + ","
    +        using_str = "USING ({col_grp_key})".format(col_grp_key=col_grp_key)
    +    else:
    +        select_grouping_info = ""
    +
    +    ## Create the output table
    +    plpy.execute("""
    +             drop table if exists {tbl_result};
    +             create table {tbl_result} (
    +                 {select_grouping_info}
    +                 family            text,
    +                 features          text[],
    +                 features_selected text[],
    +                 coef_nonzero      double precision[],
    +                 coef_all          double precision[],
    +                 intercept         double precision,
    +                 log_likelihood    double precision,
    +                 standardize       boolean,
    +                 iteration_run     integer)
    +             """.format(select_grouping_info=select_grouping_info, **args))
    +
    +    out_table_qstr = """
    +        SELECT
    +            {grouping_str1}
    +            (result).coefficients AS coef,
    +            (result).intercept AS intercept
    +        FROM (
    +            SELECT {schema_madlib}.{result_func} AS result,
    +            {col_grp_key}
    +            FROM {tbl_state}
    +            WHERE {col_grp_iteration} = {iteration_run}
             ) t
    -        """.format(result_func = result_func, tbl_state = 
tbl_state).format(
    +        join
    +        (
    +            SELECT
    +                {grouping_str1}
    +                array_to_string(ARRAY[{grouping_str}],
    +                                ','
    +                               ) AS {col_grp_key}
    +            FROM {source_table}
    +                {groupby_str}
    +        ) n_tuples_including_nulls_subq
    +        {using_str}
    +        """.format(result_func = result_func, tbl_state = tbl_state,
    +            col_grp_iteration = args["col_grp_iteration"],
                 iteration_run = iteration_run,
    -            **args))[0]
    +            groupby_str=groupby_str,
    +            grouping_str1=grouping_str1,
    +            grouping_str=grouping_str,
    +            using_str=using_str,
    +            col_grp_key=col_grp_key,
    +            source_table=source_table,
    +            schema_madlib = args["schema_madlib"])
    +    if grouping_column:
    --- End diff --
    
    They are the same, but the query string will have to be different then. 
Changed the query string based on grouping or 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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to