python类row_number()的实例源码

elements.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:QXSConsolas 作者: qxsch 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(*util.to_list(order_by))
        if partition_by is not None:
            self.partition_by = ClauseList(*util.to_list(partition_by))
elements.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(*util.to_list(order_by))
        if partition_by is not None:
            self.partition_by = ClauseList(*util.to_list(partition_by))
elements.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:python_ddd_flask 作者: igorvinnicius 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
missions.py 文件源码 项目:kort-core 作者: kort 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_missions(lat, lon, radius, limit, lang, user_id):
    try:
        location = WKTElement('POINT('+str(lon)+' '+str(lat)+')', srid=4326)
        no_of_errors = 10

        # get already solved error ids
        already_solved = db_session.query(api.models.Solution.error_id). \
            filter(api.models.Solution.user_id == user_id)

        # get nearest neighbors candidates from location
        q = db_session.query(api.models.kort_errors.schema, api.models.kort_errors.errorId) \
            .filter((~api.models.kort_errors.errorId.in_(already_solved))) \
            .order_by(api.models.kort_errors.geom.distance_centroid(location)) \
            .limit(limit*no_of_errors).subquery()

        # partition by error type
        q = db_session.query(api.models.kort_errors, func.row_number().over(
                partition_by=api.models.kort_errors.error_type).label("row_number")) \
            .filter(tuple_(api.models.kort_errors.schema, api.models.kort_errors.errorId).in_(q))\
            .filter(func.ST_DistanceSphere(api.models.kort_errors.geom, location) < radius).subquery()

        # set max errors of each type
        q = db_session.query(api.models.kort_errors).select_entity_from(q).filter(q.c.row_number <= limit/no_of_errors)

    except Exception as e:
        logger.error(traceback.format_exc())
    return [p.dump(lang) for p in q][:limit]
elements.py 文件源码 项目:Data-visualization 作者: insta-code1 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:micro-blog 作者: nickChenyx 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:python-flask-security 作者: weinbergdavid 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:Lixiang_zhaoxin 作者: hejaxian 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
functions.py 文件源码 项目:hoaxy-backend 作者: IUNetSci 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def column_windows(session, w_column, w_size, fb_kw=None, f_expr=None):
    """Return a series of WHERE clauses against a given column that break it
    into windows.

    Parameters
    ----------
    session : object
        An instance of SQLAlchemy Session.
    w_column : object
        Column object that is used to split into windows, should be an
        integer column.
    w_size : int
        Size of the window
    fb_kw : dict
        The filter_by keywords, used by query.filter_by().
    f_expr : list
        The filter expressions, used by query.filter().

    Returns
    -------
    iterable
        Each element of the iterable is a whereclause expression, which
        specify the range of the window over the column `w_col`.

    Exmaple
    -------
    for whereclause in column_windows(q.session, w_column, w_size):
        for row in q.filter(whereclause).order_by(w_column):
            yield row

    """

    def int_for_range(start_id, end_id):
        """Internal function to build range."""
        if end_id:
            return and_(w_column >= start_id, w_column < end_id)
        else:
            return w_column >= start_id

    q = session.query(
        w_column, func.row_number().over(order_by=w_column).label('w_row_num'))
    if fb_kw:
        q = q.filter_by(**fb_kw)
    if f_expr:
        q = q.filter(*f_expr)
    q = q.from_self(w_column)
    if w_size > 1:
        q = q.filter(sqlalchemy.text("w_row_num % {}=1".format(w_size)))

    intervals = [id for id, in q]

    while intervals:
        start = intervals.pop(0)
        if intervals:
            end = intervals[0]
        else:
            end = None
        yield int_for_range(start, end)
elements.py 文件源码 项目:Hawkeye 作者: tozhengxq 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)
elements.py 文件源码 项目:ngx_status 作者: YoYoAdorkable 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, func, partition_by=None, order_by=None):
        """Produce an :class:`.Over` object against a function.

        Used against aggregate or so-called "window" functions,
        for database backends that support window functions.

        E.g.::

            from sqlalchemy import over
            over(func.row_number(), order_by='x')

        Would produce "ROW_NUMBER() OVER(ORDER BY x)".

        :param func: a :class:`.FunctionElement` construct, typically
         generated by :data:`~.expression.func`.
        :param partition_by: a column element or string, or a list
         of such, that will be used as the PARTITION BY clause
         of the OVER construct.
        :param order_by: a column element or string, or a list
         of such, that will be used as the ORDER BY clause
         of the OVER construct.

        This function is also available from the :data:`~.expression.func`
        construct itself via the :meth:`.FunctionElement.over` method.

        .. versionadded:: 0.7

        """
        self.func = func
        if order_by is not None:
            self.order_by = ClauseList(
                *util.to_list(order_by),
                _literal_as_text=_literal_as_label_reference)
        if partition_by is not None:
            self.partition_by = ClauseList(
                *util.to_list(partition_by),
                _literal_as_text=_literal_as_label_reference)


问题


面经


文章

微信
公众号

扫码关注公众号