|
1 |
| -IntOrString = Union{Int, String} |
| 1 | +const IntOrString = Union{Int, String} |
| 2 | +const MLFlowUpsertData{T} = Union{Array{T}, Dict{String, String}, |
| 3 | + Array{Pair{String, String}}, Array{Dict{String, String}}} |
2 | 4 |
|
3 | 5 | const MLFLOW_ERROR_CODES = (;
|
4 | 6 | RESOURCE_ALREADY_EXISTS = "RESOURCE_ALREADY_EXISTS",
|
5 | 7 | RESOURCE_DOES_NOT_EXIST = "RESOURCE_DOES_NOT_EXIST",
|
6 | 8 | )
|
7 | 9 |
|
8 |
| -""" |
9 |
| - pairtags_to_dictarray(pair_array::Array{Pair{Any, Any}}) |
10 |
| -
|
11 |
| -Transforms an array of `Pair` tags into an array of MLFlow compatible `Dict` |
12 |
| -format tags. |
13 |
| -
|
14 |
| -```@example |
15 |
| -# Having an array of pairs |
16 |
| -["foo" => "bar", "missy" => "gala"] |
17 |
| -
|
18 |
| -# Will be transformed into an array of dictionaries |
19 |
| -[Dict("key" => "foo", "value" => "bar"), Dict("key" => "missy", "value" => "gala")] |
20 |
| -``` |
21 |
| -""" |
22 |
| -function pairtags_to_dictarray(pair_array::Array{<:Pair})::Array{<:Dict} |
23 |
| - dict_array = Dict[] |
24 |
| - for pair in pair_array |
25 |
| - key = string(pair.first) |
26 |
| - value = string(pair.second) |
27 |
| - push!(dict_array, Dict("key" => key, "value" => value)) |
| 10 | +function dict_to_array(dict::Dict{String, String})::MLFlowUpsertData |
| 11 | + tags = Tag[] |
| 12 | + for (key, value) in dict |
| 13 | + push!(tags, Tag(key, value)) |
28 | 14 | end
|
29 | 15 |
|
30 |
| - return dict_array |
| 16 | + return tags |
31 | 17 | end
|
32 | 18 |
|
33 |
| -""" |
34 |
| - tagsdict_to_dictarray(dict::Dict{Any, Any}) |
35 |
| -
|
36 |
| -Transforms a dictionary into an array of `Dict`. |
37 |
| -
|
38 |
| -```@example |
39 |
| -# Having a dictionary |
40 |
| -Dict("foo" => "bar", "missy" => "gala") |
41 |
| -
|
42 |
| -# Will be transformed into an array of dictionaries |
43 |
| -[Dict("key" => "foo", "value" => "bar"), Dict("key" => "missy", "value" => "gala")] |
44 |
| -``` |
45 |
| -""" |
46 |
| -function tagsdict_to_dictarray(dict::Dict{<:Any})::Array{<:Dict} |
47 |
| - dict_array = Dict[] |
48 |
| - for (key, value) in dict |
49 |
| - push!(dict_array, Dict("key" => key |> string, |
50 |
| - "value" => value |> string)) |
| 19 | +function pairsarray_to_array(pair_array::Array{<:Pair})::MLFlowUpsertData |
| 20 | + entity_array = Tag[] |
| 21 | + for pair in pair_array |
| 22 | + println(pair) |
| 23 | + key = pair.first |> string |
| 24 | + value = pair.second |> string |
| 25 | + push!(entity_array, Tag(key, value)) |
51 | 26 | end
|
52 | 27 |
|
53 |
| - return dict_array |
| 28 | + return entity_array |
54 | 29 | end
|
55 | 30 |
|
56 |
| -""" |
57 |
| - tagarray_to_dictarray(tag_array::Array{Tag}) |
58 |
| -
|
59 |
| -Transforms an array of `Tag` into an array of `Dict`. |
60 |
| -
|
61 |
| -```@example |
62 |
| -# Having an array of tags |
63 |
| -[Tag("foo", "bar"), Tag("missy", "gala")] |
64 |
| -
|
65 |
| -# Will be transformed into an array of dictionaries |
66 |
| -[Dict("key" => "foo", "value" => "bar"), Dict("key" => "missy", "value" => "gala")] |
67 |
| -``` |
68 |
| -""" |
69 |
| -function tagarray_to_dictarray(tag_array::Array{Tag})::Array{<:Dict} |
70 |
| - dict_array = Dict[] |
71 |
| - for tag in tag_array |
72 |
| - push!(dict_array, Dict("key" => tag.key , "value" => tag.value)) |
| 31 | +function dictarray_to_array(dict_array::Array{Dict{String, String}})::MLFlowUpsertData |
| 32 | + tags = Tag[] |
| 33 | + for dict in dict_array |
| 34 | + push!(tags, Tag(dict["key"], dict["value"])) |
73 | 35 | end
|
74 | 36 |
|
75 |
| - return dict_array |
| 37 | + return tags |
76 | 38 | end
|
77 | 39 |
|
78 |
| -function parsetags(tags::Union{Dict{<:Any}, Array{<:Any}})::Array{<:Dict} |
79 |
| - parsed_tags = Dict[] |
80 |
| - if tags isa Array{Tag} |
81 |
| - parsed_tags = tags |> tagarray_to_dictarray |
82 |
| - elseif tags isa Array{<:Pair} |
83 |
| - parsed_tags = tags |> pairtags_to_dictarray |
84 |
| - elseif tags isa Dict{<:Any} |
85 |
| - parsed_tags = tags |> tagsdict_to_dictarray |
| 40 | +function parse(entities::MLFlowUpsertData{T}) where T<:LoggingData |
| 41 | + println(typeof(entities)) |
| 42 | + if entities isa Dict{String, String} |
| 43 | + return entities |> dict_to_array |
| 44 | + elseif entities isa Array{Pair{String, String}} |
| 45 | + return entities |> pairsarray_to_array |
| 46 | + elseif entities isa Array{Dict{String, String}} |
| 47 | + return entities |> dictarray_to_array |
86 | 48 | end
|
87 |
| - |
88 |
| - return parsed_tags |
| 49 | + return entities |
89 | 50 | end
|
| 51 | + |
| 52 | +refresh(instance::MLFlow, experiment::Experiment)::Experiment = |
| 53 | + getexperiment(instance, experiment.experiment_id) |
| 54 | +refresh(instance::MLFlow, run::Run)::Run = |
| 55 | + getrun(instance, run.info.run_id) |
0 commit comments