Skip to content

Commit 8859ff5

Browse files
committed
paging
1 parent b90da1c commit 8859ff5

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/runs.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,18 @@ Searches for runs in an experiment based on filter.
109109
- `run_view_type::String`: ...
110110
- `max_results::Integer`: ...
111111
- `order_by::String`: ...
112+
- `page_token::String`: paging functionality, handled automatically. Not meant to be passed by the user.
112113
113114
# Returns
114-
- a vector of runs that were found
115+
- vector of [`MLFlowRun`](@ref) runs that were found in the list of experiments.
115116
116117
"""
117118
function searchruns(mlf::MLFlow, experiment_ids::AbstractVector{<:Integer};
118119
filter::String="",
119120
run_view_type::String="ACTIVE_ONLY",
120121
max_results::Int64=50000,
121-
order_by::AbstractVector{<:String}=[""]
122+
order_by::AbstractVector{<:String}=["attribute.start_time"],
123+
page_token::String=""
122124
)
123125
endpoint = "runs/search"
124126
run_view_type ["ACTIVE_ONLY", "DELETED_ONLY", "ALL"] || error("Unsupported run_view_type = $run_view_type")
@@ -127,15 +129,31 @@ function searchruns(mlf::MLFlow, experiment_ids::AbstractVector{<:Integer};
127129
filter=filter,
128130
run_view_type=run_view_type,
129131
max_results=max_results,
132+
order_by=order_by
130133
)
131-
if order_by != [""]
132-
kwargs.order_by = order_by
134+
if !isempty(page_token)
135+
kwargs = (; kwargs..., page_token=page_token)
133136
end
134137

135138
result = mlfpost(mlf, endpoint; kwargs...)
136-
haskey(result, "runs") || error("Malformed result from MLFow")
139+
haskey(result, "runs") || return MLFlowRun[]
140+
141+
runs = map(x -> MLFlowRun(x["info"], x["data"]), result["runs"])
142+
143+
# paging functionality
144+
if haskey(result, "next_page_token") && !isempty(result["next_page_token"])
145+
kwargs = (
146+
filter=filter,
147+
run_view_type=run_view_type,
148+
max_results=max_results,
149+
order_by=order_by,
150+
page_token=result["next_page_token"]
151+
)
152+
nextruns = searchruns(mlf, experiment_ids; kwargs...)
153+
return vcat(runs, nextruns)
154+
end
137155

138-
map(x -> MLFlowRun(x["info"], x["data"]), result["runs"])
156+
runs
139157
end
140158
function searchruns(mlf::MLFlow, experiment_id::Integer; kwargs...)
141159
searchruns(mlf, [experiment_id]; kwargs...)

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ end
7878
@show experiment_id
7979
runs = searchruns(mlf, experiment_id)
8080
@test length(runs) == 2
81+
runs = searchruns(mlf, experiment_id; filter="param.param2 = \"key2\"")
82+
@test length(runs) == 1
83+
@test_throws ErrorException searchruns(mlf, experiment_id; run_view_type="MEH")
84+
runs = searchruns(mlf, experiment_id; filter="param.param2 = \"key3\"")
85+
@test length(runs) == 0
86+
runs = searchruns(mlf, experiment_id; max_results=1) # test paging functionality
87+
@test length(runs) == 2
8188
# , "params.\"paramkey\" == \"paramval\"")
8289
# deleterun(mlf, exprunid)
8390

0 commit comments

Comments
 (0)