def _grouprule_aggs_filter(having, columns):
    """
    Given (having) conditions, return what to filter on as a string, to be used
    after groupbys as grouped.query(string returned by this function).

    :param having:
    :type having: list
    :param columns: Columns on which the group by is made.
    :type columns: list
    :return: String to be used on a df.query to filter based on the "having" conditions.
    :rtype: str
    """
    cond = having[0]
    operator_map = dict()
    operator_map['gt'] = '>'
    operator_map['lt'] = '<'
    operator_map['eq'] = '=='
    first_operator = cond['operator']
    if cond['aggregator'] == 'count' and cond['column'] == '*':
        result = '_groupby_agg_%s_%s %s %s' % (columns[0], 'size',
            operator_map[first_operator], cond['value'])
    else:
        result = '_groupby_agg_%s_%s %s %s' % (cond['column'], cond[
            'aggregator'], operator_map[first_operator], cond['value'])
    for cond in having[1:]:
        operator = cond['operator']
        if cond['aggregator'] == 'count' and cond['column'] == '*':
            result = result + ' and _groupby_agg_%s_%s %s %s' % (columns[0],
                'size', operator_map[operator], cond['value'])
        else:
            result = result + ' and _groupby_agg_%s_%s %s %s' % (cond[
                'column'], cond['aggregator'], operator_map[operator], cond
                ['value'])
    return result
