Skip to content

Commit

Permalink
OPIK-55 Find experiment by partial name and case-insensitive (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrescrz authored Sep 4, 2024
1 parent 22440b5 commit 8515987
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ INNER JOIN (
FROM experiments
WHERE workspace_id = :workspace_id
<if(dataset_id)> AND dataset_id = :dataset_id <endif>
<if(name)> AND name = :name <endif>
<if(name)> AND ilike(name, CONCAT('%', :name, '%')) <endif>
ORDER BY id DESC, last_updated_at DESC
LIMIT 1 BY id
) AS e
Expand Down Expand Up @@ -322,8 +322,8 @@ SELECT count(id) as count
FROM experiments
WHERE workspace_id = :workspace_id
<if(dataset_id)> AND dataset_id = :dataset_id <endif>
<if(name)> AND name = :name <endif>
ORDER BY last_updated_at DESC
<if(name)> AND ilike(name, CONCAT('%', :name, '%')) <endif>
ORDER BY id DESC, last_updated_at DESC
LIMIT 1 BY id
) as latest_rows
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void getById__whenApiKeyIsPresent__thenReturnProperResponse(String apiKey, boole
void create__whenApiKeyIsPresent__thenReturnProperResponse(String apiKey, boolean success) {
var expectedExperiment = podamFactory.manufacturePojo(Experiment.class);

String workspaceName = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();

mockTargetWorkspace(okApikey, workspaceName, WORKSPACE_ID);

Expand Down Expand Up @@ -285,7 +285,7 @@ void find__whenApiKeyIsPresent__thenReturnProperResponse(String apiKey, boolean
@ParameterizedTest
@MethodSource("credentials")
void deleteExperimentItems__whenApiKeyIsPresent__thenReturnProperResponse(String apiKey, boolean success) {
String workspaceName = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();

var createRequest = podamFactory.manufacturePojo(ExperimentItemsBatch.class);

Expand Down Expand Up @@ -319,7 +319,7 @@ void deleteExperimentItems__whenApiKeyIsPresent__thenReturnProperResponse(String
@ParameterizedTest
@MethodSource("credentials")
void createExperimentItems__whenApiKeyIsPresent__thenReturnProperResponse(String apiKey, boolean success) {
String workspaceName = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();

mockTargetWorkspace(okApikey, workspaceName, WORKSPACE_ID);

Expand All @@ -346,7 +346,7 @@ void createExperimentItems__whenApiKeyIsPresent__thenReturnProperResponse(String
@MethodSource("credentials")
void getExperimentItemById__whenApiKeyIsPresent__thenReturnProperResponse(String apiKey, boolean success) {

String workspaceName = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var expectedExperimentItem = podamFactory.manufacturePojo(ExperimentItem.class);
var id = expectedExperimentItem.id();

Expand Down Expand Up @@ -588,9 +588,9 @@ class FindExperiments {

@Test
void findByDatasetId() {
String workspaceName = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -622,15 +622,28 @@ void findByDatasetId() {
unexpectedExperiments, apiKey);
}

@Test
void findByName() {
String workspaceName = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
Stream<Arguments> findByName() {
var exactName = RandomStringUtils.randomAlphanumeric(10);
var exactNameIgnoreCase = RandomStringUtils.randomAlphanumeric(10);
var partialName = RandomStringUtils.randomAlphanumeric(10);
var partialNameIgnoreCase = RandomStringUtils.randomAlphanumeric(10);
return Stream.of(
arguments(exactName, exactName),
arguments(exactNameIgnoreCase, exactNameIgnoreCase.toLowerCase()),
arguments(partialName, partialName.substring(1, partialName.length() - 1)),
arguments(partialNameIgnoreCase,
partialNameIgnoreCase.substring(1, partialNameIgnoreCase.length() - 1).toLowerCase()));
}

@MethodSource
@ParameterizedTest
void findByName(String name, String nameQueryParam) {
var workspaceName = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

var name = RandomStringUtils.randomAlphanumeric(10);
var experiments = PodamFactoryUtils.manufacturePojoList(podamFactory, Experiment.class)
.stream()
.map(experiment -> experiment.toBuilder()
Expand All @@ -650,18 +663,18 @@ void findByName() {
var expectedExperiments2 = experiments.subList(0, pageSize - 1).reversed();
var expectedTotal = experiments.size();

findAndAssert(workspaceName, 1, pageSize, datasetId, name, expectedExperiments1, expectedTotal,
findAndAssert(workspaceName, 1, pageSize, datasetId, nameQueryParam, expectedExperiments1, expectedTotal,
unexpectedExperiments, apiKey);
findAndAssert(workspaceName, 2, pageSize, datasetId, name, expectedExperiments2, expectedTotal,
findAndAssert(workspaceName, 2, pageSize, datasetId, nameQueryParam, expectedExperiments2, expectedTotal,
unexpectedExperiments, apiKey);
}

@Test
void findByDatasetIdAndName() {

String workspaceName = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -697,9 +710,9 @@ void findByDatasetIdAndName() {

@Test
void findAll() {
String workspaceName = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -733,9 +746,9 @@ void findAll() {

@Test
void findAllAndCalculateFeedbackAvg() {
String workspaceName = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -862,9 +875,9 @@ void findAllAndCalculateFeedbackAvg() {

@Test
void findAllAndTraceDeleted() {
String workspaceName = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -1310,9 +1323,9 @@ void getNotFound() {
@Test
void createAndGetWithDeletedTrace() {

String workspaceName = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -1617,10 +1630,10 @@ void createAndGet() {
@Test
void insertInvalidDatasetItemWorkspace() {

String workspaceName = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();

String workspaceId = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName, workspaceId);

Expand Down Expand Up @@ -1650,11 +1663,11 @@ void insertInvalidDatasetItemWorkspace() {
@Test
void insertInvalidExperimentWorkspace() {

String workspaceName1 = UUID.randomUUID().toString();
String apiKey = UUID.randomUUID().toString();
String workspaceId = UUID.randomUUID().toString();
var workspaceName = UUID.randomUUID().toString();
var apiKey = UUID.randomUUID().toString();
var workspaceId = UUID.randomUUID().toString();

mockTargetWorkspace(apiKey, workspaceName1, workspaceId);
mockTargetWorkspace(apiKey, workspaceName, workspaceId);

UUID experimentId = createAndAssert(podamFactory.manufacturePojo(Experiment.class), API_KEY,
TEST_WORKSPACE);
Expand All @@ -1670,7 +1683,7 @@ void insertInvalidExperimentWorkspace() {
try (var actualResponse = client.target(getExperimentItemsPath())
.request()
.header(HttpHeaders.AUTHORIZATION, apiKey)
.header(WORKSPACE_HEADER, workspaceName1)
.header(WORKSPACE_HEADER, workspaceName)
.post(Entity.json(request))) {

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(409);
Expand Down

0 comments on commit 8515987

Please sign in to comment.