Skip to content

prefect.server.schemas.sorting

Schemas for sorting Prefect REST API objects.

ArtifactSort

Bases: AutoEnum

Defines artifact sorting options.

Source code in prefect/server/schemas/sorting.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
class ArtifactSort(AutoEnum):
    """Defines artifact sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    ID_DESC = AutoEnum.auto()
    KEY_DESC = AutoEnum.auto()
    KEY_ASC = AutoEnum.auto()

    def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort artifacts"""
        sort_mapping = {
            "CREATED_DESC": db.Artifact.created.desc(),
            "UPDATED_DESC": db.Artifact.updated.desc(),
            "ID_DESC": db.Artifact.id.desc(),
            "KEY_DESC": db.Artifact.key.desc(),
            "KEY_ASC": db.Artifact.key.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort artifacts

Source code in prefect/server/schemas/sorting.py
153
154
155
156
157
158
159
160
161
162
def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
    """Return an expression used to sort artifacts"""
    sort_mapping = {
        "CREATED_DESC": db.Artifact.created.desc(),
        "UPDATED_DESC": db.Artifact.updated.desc(),
        "ID_DESC": db.Artifact.id.desc(),
        "KEY_DESC": db.Artifact.key.desc(),
        "KEY_ASC": db.Artifact.key.asc(),
    }
    return sort_mapping[self.value]

DeploymentSort

Bases: AutoEnum

Defines deployment sorting options.

Source code in prefect/server/schemas/sorting.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
class DeploymentSort(AutoEnum):
    """Defines deployment sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()

    def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort deployments"""
        sort_mapping = {
            "CREATED_DESC": db.Deployment.created.desc(),
            "UPDATED_DESC": db.Deployment.updated.desc(),
            "NAME_ASC": db.Deployment.name.asc(),
            "NAME_DESC": db.Deployment.name.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort deployments

Source code in prefect/server/schemas/sorting.py
133
134
135
136
137
138
139
140
141
def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
    """Return an expression used to sort deployments"""
    sort_mapping = {
        "CREATED_DESC": db.Deployment.created.desc(),
        "UPDATED_DESC": db.Deployment.updated.desc(),
        "NAME_ASC": db.Deployment.name.asc(),
        "NAME_DESC": db.Deployment.name.desc(),
    }
    return sort_mapping[self.value]

FlowRunSort

Bases: AutoEnum

Defines flow run sorting options.

Source code in prefect/server/schemas/sorting.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class FlowRunSort(AutoEnum):
    """Defines flow run sorting options."""

    ID_DESC = AutoEnum.auto()
    START_TIME_ASC = AutoEnum.auto()
    START_TIME_DESC = AutoEnum.auto()
    EXPECTED_START_TIME_ASC = AutoEnum.auto()
    EXPECTED_START_TIME_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()
    NEXT_SCHEDULED_START_TIME_ASC = AutoEnum.auto()
    END_TIME_DESC = AutoEnum.auto()

    def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
        from sqlalchemy.sql.functions import coalesce

        """Return an expression used to sort flow runs"""
        sort_mapping = {
            "ID_DESC": db.FlowRun.id.desc(),
            "START_TIME_ASC": coalesce(
                db.FlowRun.start_time, db.FlowRun.expected_start_time
            ).asc(),
            "START_TIME_DESC": coalesce(
                db.FlowRun.start_time, db.FlowRun.expected_start_time
            ).desc(),
            "EXPECTED_START_TIME_ASC": db.FlowRun.expected_start_time.asc(),
            "EXPECTED_START_TIME_DESC": db.FlowRun.expected_start_time.desc(),
            "NAME_ASC": db.FlowRun.name.asc(),
            "NAME_DESC": db.FlowRun.name.desc(),
            "NEXT_SCHEDULED_START_TIME_ASC": db.FlowRun.next_scheduled_start_time.asc(),
            "END_TIME_DESC": db.FlowRun.end_time.desc(),
        }
        return sort_mapping[self.value]

FlowSort

Bases: AutoEnum

Defines flow sorting options.

Source code in prefect/server/schemas/sorting.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class FlowSort(AutoEnum):
    """Defines flow sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()

    def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort flows"""
        sort_mapping = {
            "CREATED_DESC": db.Flow.created.desc(),
            "UPDATED_DESC": db.Flow.updated.desc(),
            "NAME_ASC": db.Flow.name.asc(),
            "NAME_DESC": db.Flow.name.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort flows

Source code in prefect/server/schemas/sorting.py
114
115
116
117
118
119
120
121
122
def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
    """Return an expression used to sort flows"""
    sort_mapping = {
        "CREATED_DESC": db.Flow.created.desc(),
        "UPDATED_DESC": db.Flow.updated.desc(),
        "NAME_ASC": db.Flow.name.asc(),
        "NAME_DESC": db.Flow.name.desc(),
    }
    return sort_mapping[self.value]

LogSort

Bases: AutoEnum

Defines log sorting options.

Source code in prefect/server/schemas/sorting.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class LogSort(AutoEnum):
    """Defines log sorting options."""

    TIMESTAMP_ASC = AutoEnum.auto()
    TIMESTAMP_DESC = AutoEnum.auto()
    LEVEL_ASC = AutoEnum.auto()
    LEVEL_DESC = AutoEnum.auto()
    FLOW_RUN_ID_ASC = AutoEnum.auto()
    FLOW_RUN_ID_DESC = AutoEnum.auto()
    TASK_RUN_ID_ASC = AutoEnum.auto()
    TASK_RUN_ID_DESC = AutoEnum.auto()

    def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort task runs"""
        sort_mapping = {
            "TIMESTAMP_ASC": db.Log.timestamp.asc(),
            "TIMESTAMP_DESC": db.Log.timestamp.desc(),
            "LEVEL_ASC": db.Log.level.asc(),
            "LEVEL_DESC": db.Log.level.desc(),
            "FLOW_RUN_ID_ASC": db.Log.flow_run_id.asc(),
            "FLOW_RUN_ID_DESC": db.Log.flow_run_id.desc(),
            "TASK_RUN_ID_ASC": db.Log.task_run_id.asc(),
            "TASK_RUN_ID_DESC": db.Log.task_run_id.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort task runs

Source code in prefect/server/schemas/sorting.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
    """Return an expression used to sort task runs"""
    sort_mapping = {
        "TIMESTAMP_ASC": db.Log.timestamp.asc(),
        "TIMESTAMP_DESC": db.Log.timestamp.desc(),
        "LEVEL_ASC": db.Log.level.asc(),
        "LEVEL_DESC": db.Log.level.desc(),
        "FLOW_RUN_ID_ASC": db.Log.flow_run_id.asc(),
        "FLOW_RUN_ID_DESC": db.Log.flow_run_id.desc(),
        "TASK_RUN_ID_ASC": db.Log.task_run_id.asc(),
        "TASK_RUN_ID_DESC": db.Log.task_run_id.desc(),
    }
    return sort_mapping[self.value]

TaskRunSort

Bases: AutoEnum

Defines task run sorting options.

Source code in prefect/server/schemas/sorting.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class TaskRunSort(AutoEnum):
    """Defines task run sorting options."""

    ID_DESC = AutoEnum.auto()
    EXPECTED_START_TIME_ASC = AutoEnum.auto()
    EXPECTED_START_TIME_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()
    NEXT_SCHEDULED_START_TIME_ASC = AutoEnum.auto()
    END_TIME_DESC = AutoEnum.auto()

    def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort task runs"""
        sort_mapping = {
            "ID_DESC": db.TaskRun.id.desc(),
            "EXPECTED_START_TIME_ASC": db.TaskRun.expected_start_time.asc(),
            "EXPECTED_START_TIME_DESC": db.TaskRun.expected_start_time.desc(),
            "NAME_ASC": db.TaskRun.name.asc(),
            "NAME_DESC": db.TaskRun.name.desc(),
            "NEXT_SCHEDULED_START_TIME_ASC": db.TaskRun.next_scheduled_start_time.asc(),
            "END_TIME_DESC": db.TaskRun.end_time.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort task runs

Source code in prefect/server/schemas/sorting.py
65
66
67
68
69
70
71
72
73
74
75
76
def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
    """Return an expression used to sort task runs"""
    sort_mapping = {
        "ID_DESC": db.TaskRun.id.desc(),
        "EXPECTED_START_TIME_ASC": db.TaskRun.expected_start_time.asc(),
        "EXPECTED_START_TIME_DESC": db.TaskRun.expected_start_time.desc(),
        "NAME_ASC": db.TaskRun.name.asc(),
        "NAME_DESC": db.TaskRun.name.desc(),
        "NEXT_SCHEDULED_START_TIME_ASC": db.TaskRun.next_scheduled_start_time.asc(),
        "END_TIME_DESC": db.TaskRun.end_time.desc(),
    }
    return sort_mapping[self.value]