Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
searchModelVersions()
API in Java client (#7880)
* add ModelVersionsPage Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add searchModelVersions signatures Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * finish searchModelVersions() methods Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add overloaded searchModelVersions() Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add test Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * fix http GET for model-versions/search Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * fix test: search by run id Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * remove unused imports Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * reformat line > 100 characters Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add args to makeSearchModelVersions() Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add args to searchModelVersions() & overloaded methods Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add args to ModelVersionsPage Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * add tests for pagination & new args Signed-off-by: gabrielfu <hfu.gabriel@gmail.com> * fix builder to handle null search filter & page token Signed-off-by: gabrielfu <hfu.gabriel@gmail.com>
- Loading branch information
Showing
4 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
mlflow/java/client/src/main/java/org/mlflow/tracking/ModelVersionsPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.mlflow.tracking; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.mlflow.api.proto.ModelRegistry.*; | ||
|
||
public class ModelVersionsPage implements Page<ModelVersion> { | ||
|
||
private final String token; | ||
private final List<ModelVersion> mvs; | ||
|
||
private final MlflowClient client; | ||
private final String searchFilter; | ||
private final List<String> orderBy; | ||
private final int maxResults; | ||
|
||
/** | ||
* Creates a fixed size page of ModelVersions. | ||
*/ | ||
ModelVersionsPage(List<ModelVersion> mvs, | ||
String token, | ||
String searchFilter, | ||
int maxResults, | ||
List<String> orderBy, | ||
MlflowClient client) { | ||
this.mvs = Collections.unmodifiableList(mvs); | ||
this.token = token; | ||
this.searchFilter = searchFilter; | ||
this.orderBy = orderBy; | ||
this.maxResults = maxResults; | ||
this.client = client; | ||
} | ||
|
||
/** | ||
* @return The number of model versions in the page. | ||
*/ | ||
public int getPageSize() { | ||
return this.mvs.size(); | ||
} | ||
|
||
/** | ||
* @return True if a token for the next page exists and isn't empty. Otherwise returns false. | ||
*/ | ||
public boolean hasNextPage() { | ||
return this.token != null && this.token != ""; | ||
} | ||
|
||
/** | ||
* @return An optional with the token for the next page. | ||
* Empty if the token doesn't exist or is empty. | ||
*/ | ||
public Optional<String> getNextPageToken() { | ||
if (this.hasNextPage()) { | ||
return Optional.of(this.token); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
/** | ||
* @return The next page of model versions matching the search criteria. | ||
* If there are no more pages, an {@link org.mlflow.tracking.EmptyPage} will be returned. | ||
*/ | ||
public Page<ModelVersion> getNextPage() { | ||
if (this.hasNextPage()) { | ||
return this.client.searchModelVersions(this.searchFilter, | ||
this.maxResults, | ||
this.orderBy, | ||
this.token); | ||
} else { | ||
return new EmptyPage(); | ||
} | ||
} | ||
|
||
/** | ||
* @return An iterable over the model versions in this page. | ||
*/ | ||
public List<ModelVersion> getItems() { | ||
return mvs; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters