Beispiel #1
0
def collect(transform: dict, expr: ibis.Expr) -> ibis.Expr:
    fields = promote_list(transform["sort"]["field"])
    orders = promote_list(transform["sort"].get("order", ["ascending"] * len(fields)))
    assert len(fields) == len(orders)

    rules = [
        (field, (True if order == "ascending" else False))
        for field, order in zip(fields, orders)
    ]
    return expr.sort_by(rules)
    def maybe_add_random_sort(
        self, data_client: ibis.client, table: ibis.Expr
    ) -> ibis.Expr:
        """Return a randomly sorted query if it is supported for the client."""
        if type(data_client) in RANDOM_SORT_SUPPORTS:
            return table.sort_by(
                RandomSortKey(RANDOM_SORT_SUPPORTS[type(data_client)]).to_expr()
            )

        if type(data_client) != TeradataClient:
            # Teradata 'SAMPLE' is random by nature and does not require a sort by
            logging.warning(
                "Data Client %s Does Not Enforce Random Sort on Sample",
                str(type(data_client)),
            )
        return table
Beispiel #3
0
def collect(transform: dict, expr: ibis.Expr) -> ibis.Expr:
    """
    Apply a vega collect transform to an ibis expression.
    https://vega.github.io/vega/docs/transforms/collect/

    Parameters
    ----------
    transform: dict
        A JSON-able dictionary representing the vega transform.
    expr: ibis.Expr
        The expression to which to apply the transform.

    Returns
    -------
    transformed_expr: the transformed expression
    """
    fields = promote_list(transform["sort"]["field"])
    orders = promote_list(transform["sort"].get("order",
                                                ["ascending"] * len(fields)))
    assert len(fields) == len(orders)

    rules = [(field, (True if order == "ascending" else False))
             for field, order in zip(fields, orders)]
    return expr.sort_by(rules)