示例#1
0
def group_ordering_taql(table_proxy, group_cols, index_cols, taql_where=''):
    if len(group_cols) == 0:
        raise ValueError("group_ordering_taql requires " "len(group_cols) > 0")
    else:
        index_group_cols = [
            "GAGGR(%s) as GROUP_%s" % (c, c) for c in index_cols
        ]
        # Group Row ID's
        index_group_cols.append("GROWID() AS __tablerow__")
        # Number of rows in the group
        index_group_cols.append("GCOUNT() as __tablerows__")
        # The first row of the group
        index_group_cols.append("GROWID()[0] as __firstrow__")

        groupby = groupby_clause(group_cols)
        select = select_clause(group_cols + index_group_cols)

        if taql_where != '':
            taql_where = "\nHAVING\n\t%s" % taql_where

        query = "%s\nFROM\n\t$1\n%s%s" % (select, groupby, taql_where)

        return TableProxy(taql_factory,
                          query,
                          tables=[table_proxy],
                          __executor_key__=table_proxy.executor_key)

    raise RuntimeError("Invalid condition in group_ordering_taql")
示例#2
0
def group_ordering_taql(table_proxy, group_cols, index_cols, taql_where=''):
    if len(group_cols) == 0:
        raise ValueError("group_ordering_taql requires "
                         "len(group_cols) > 0")
    else:
        index_group_cols = [f"GAGGR({c}) as GROUP_{c}"
                            for c in index_cols]
        # Group Row ID's
        index_group_cols.append("GROWID() AS __tablerow__")
        # Number of rows in the group
        index_group_cols.append("GCOUNT() as __tablerows__")
        # The first row of the group
        index_group_cols.append("GROWID()[0] as __firstrow__")

        groupby = groupby_clause(group_cols)
        select = select_clause(group_cols + index_group_cols)

        if taql_where != '':
            taql_where = f"\nWHERE\n\t{taql_where}"

        query = f"{select}\nFROM\n\t$1{taql_where}\n{groupby}"

        return TableProxy(taql_factory, query, tables=[table_proxy],
                          __executor_key__=table_proxy.executor_key)

    raise RuntimeError("Invalid condition in group_ordering_taql")
示例#3
0
def ordering_taql(table_proxy, index_cols, taql_where=''):
    select = select_clause(["ROWID() as __tablerow__"])
    orderby = "\n" + orderby_clause(index_cols)

    if taql_where != '':
        taql_where = f"\nWHERE\n\t{taql_where}"

    query = f"{select}\nFROM\n\t$1{taql_where}{orderby}"

    return TableProxy(taql_factory, query, tables=[table_proxy],
                      __executor_key__=table_proxy.executor_key)
示例#4
0
def ordering_taql(table_proxy, index_cols, taql_where=''):
    select = select_clause(["ROWID() as __tablerow__"])
    orderby = "\n" + orderby_clause(index_cols)

    if taql_where != '':
        taql_where = "\nWHERE\n\t%s" % taql_where

    query = "%s\nFROM\n\t$1%s%s" % (select, taql_where, orderby)

    return TableProxy(taql_factory, query, tables=[table_proxy],
                      __executor_key__=table_proxy.executor_key)