Skip to content

Better make_query output #900

@mccalluc

Description

@mccalluc
def make_query(code_gen, identifier, accuracy_name, stats_name):
    def template(dp, GROUP_NAMES, stats_context, EXPR_NAME):
        groups = GROUP_NAMES
        QUERY_NAME = (
            stats_context.query().group_by(groups).agg(dp.len(), EXPR_NAME).WITH_KEYS
            if groups
            else stats_context.query().select(EXPR_NAME)
        )
        STATS_NAME = QUERY_NAME.release().collect()
        STATS_NAME  # type: ignore

    return (
        DefaultsTemplate(template)
        .fill_values(
            GROUP_NAMES=list(code_gen.analysis_plan.groups.keys()),
        )

We know whether GROUP_NAMES is going to be empty or not, so we can get rid of the conditional logic inside the template. I generally want to to move conditional logic outside the template, unless it serves a pedagogical purpose, and doesn't make things much more cluttered. I think this fails on both counts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Pending

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions