Here are the examples of the python api sqlalchemy.func.distinct taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
Source : views.py
with Apache License 2.0
from flink-extended
with Apache License 2.0
from flink-extended
def autocomplete(self, session=None):
"""Autocomplete."""
query = unquote(request.args.get('query', ''))
if not query:
wwwutils.json_response([])
# Provide suggestions of dag_ids and owners
dag_ids_query = session.query(DagModel.dag_id.label('item')).filter( # pylint: disable=no-member
~DagModel.is_subdag, DagModel.is_active, DagModel.dag_id.ilike('%' + query + '%')
) # noqa pylint: disable=no-member
owners_query = session.query(func.distinct(DagModel.owners).label('item')).filter(
~DagModel.is_subdag, DagModel.is_active, DagModel.owners.ilike('%' + query + '%')
) # noqa pylint: disable=no-member
# Hide DAGs if not showing status: "all"
status = flask_session.get(FILTER_STATUS_COOKIE)
if status == 'active':
dag_ids_query = dag_ids_query.filter(~DagModel.is_paused)
owners_query = owners_query.filter(~DagModel.is_paused)
elif status == 'paused':
dag_ids_query = dag_ids_query.filter(DagModel.is_paused)
owners_query = owners_query.filter(DagModel.is_paused)
filter_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
# pylint: disable=no-member
dag_ids_query = dag_ids_query.filter(DagModel.dag_id.in_(filter_dag_ids))
owners_query = owners_query.filter(DagModel.dag_id.in_(filter_dag_ids))
# pylint: enable=no-member
payload = [row[0] for row in dag_ids_query.union(owners_query).limit(10).all()]
return wwwutils.json_response(payload)
0
Source : access_request.py
with GNU Affero General Public License v3.0
from keitaroinc
with GNU Affero General Public License v3.0
from keitaroinc
def get_all_count(cls,
assigned_to=None,
requested_by=None,
order_by='created_at desc',
status='pending',
search=''):
'''Counts the total number of matching access requests based on the
provided criteria.
:param assigned_to: `str`, the ID of the user that the access requests
are assigned to.
:param requested_by: `str`, the ID of the user that requested the
access.
:param order_by: `str`, order by clause.
:param status: `str`, access request status. Default is `pending`.
:param search: `str`, search string to be matched against the entity
title.
:returns: `int`, total number of matching records.
'''
q = Session.query(func.count(func.distinct(access_request_table.c.id)))
if assigned_to:
q = q.join(AssignedAccessRequest)
q = q.filter(
assigned_access_requests_table.c.user_id == assigned_to)
if requested_by:
q = q.filter(access_request_table.c.user_id == requested_by)
if status:
q = q.filter(access_request_table.c.status == status)
if search:
q = q.filter(func.lower(access_request_table.c.entity_title).like(
func.lower('%{}%'.format(search))))
return q.scalar()
class AssignedAccessRequest(DomainObject):