blag commented on code in PR #26358: URL: https://github.com/apache/airflow/pull/26358#discussion_r983127756
########## airflow/www/views.py: ########## @@ -3550,6 +3556,82 @@ def dataset_dependencies(self): {'Content-Type': 'application/json; charset=utf-8'}, ) + @expose('/object/list_datasets') + @auth.has_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_DATASET)]) + def get_datasets(self): + """Get datasets""" + allowed_attrs = ['uri', 'last_dataset_update'] + + limit = int(request.args.get("limit", 25)) + offset = int(request.args.get("offset", 0)) + order_by = request.args.get("order_by", "uri") + lstripped_orderby = order_by.lstrip('-') + + if lstripped_orderby not in allowed_attrs: + return { + "detail": ( + f"Ordering with '{lstripped_orderby}' is disallowed or the attribute does not " + "exist on the model" + ) + }, 400 + + limit = 50 if limit > 50 else limit + + with create_session() as session: + if lstripped_orderby == "uri": + if order_by[0] == "-": + order_by = (DatasetModel.uri.desc(),) + else: + order_by = (DatasetModel.uri.asc(),) + elif lstripped_orderby == "last_dataset_update": + if order_by[0] == "-": + order_by = ( + func.max(DatasetEvent.timestamp).desc(), + DatasetModel.uri.asc(), + ) + if session.bind.dialect.name == "postgresql": + order_by = (order_by[0].nulls_last(), *order_by[1:]) + else: + order_by = ( + func.max(DatasetEvent.timestamp).asc(), + DatasetModel.uri.desc(), + ) + if session.bind.dialect.name == "postgresql": + order_by = (order_by[0].nulls_first(), *order_by[1:]) + + total_entries = session.query(func.count(DatasetModel.id)).scalar() + + datasets = [ + dict(dataset) + for dataset in session.query( + DatasetModel.id, + DatasetModel.uri, + func.max(DatasetEvent.timestamp).label("last_dataset_update"), + func.count(distinct(DatasetEvent.id)).label("total_updates"), + ) + .outerjoin(DatasetEvent, DatasetEvent.dataset_id == DatasetModel.id) + .outerjoin( + DagScheduleDatasetReference, DagScheduleDatasetReference.dataset_id == DatasetModel.id + ) + .outerjoin( + TaskOutletDatasetReference, TaskOutletDatasetReference.dataset_id == DatasetModel.id + ) Review Comment: Not anymore; removed, thanks! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org