Skip to content

Commit

Permalink
Add images.name filter to the query
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Aug 1, 2024
1 parent ca84377 commit 71ec47b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 12 additions & 1 deletion pkg/api/aim/dao/repositories/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package repositories
import (
"context"
"database/sql"
"fmt"
"math"
"strings"

"gorm.io/gorm"

Expand Down Expand Up @@ -143,6 +145,8 @@ func (r ArtifactRepository) Search(
return nil, nil, nil, eris.Wrap(err, "error find result summary for artifact search")
}

imageNames := []string{}
imageNameQueryTemplate := `images.name == "%s"`
resultSummary := make(ArtifactSearchSummary, len(runIDs))
for _, rslt := range stepInfo {
traceMap, ok := resultSummary[rslt.RunUUID]
Expand All @@ -151,6 +155,10 @@ func (r ArtifactRepository) Search(
}
traceMap[rslt.Name] = append(traceMap[rslt.Name], rslt)
resultSummary[rslt.RunUUID] = traceMap
qImage := fmt.Sprintf(imageNameQueryTemplate, rslt.Name)
if strings.Contains(req.Query, qImage) {
imageNames = append(imageNames, rslt.Name)
}
}

// get a cursor for the artifacts
Expand All @@ -165,13 +173,16 @@ func (r ArtifactRepository) Search(
WHERE run_uuid IN ?
AND step BETWEEN ? AND ?
AND "index" BETWEEN ? AND ?
AND name IN ?
ORDER BY run_uuid, name, step
`,
runIDs,
req.RecordRangeMin(),
req.RecordRangeMax(math.MaxInt16),
req.IndexRangeMin(),
req.IndexRangeMax(math.MaxInt16))
req.IndexRangeMax(math.MaxInt16),
imageNames)

rows, err := tx.Rows()
if err != nil {
return nil, nil, nil, eris.Wrap(err, "error searching artifacts")
Expand Down
13 changes: 9 additions & 4 deletions tests/integration/golang/aim/run/search_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ func (s *SearchArtifactsTestSuite) Test_Ok() {
expectedImageIndexesAbsent []int
}{
{
name: "SearchArtifact",
request: request.SearchArtifactsRequest{},
name: "SearchArtifact",
request: request.SearchArtifactsRequest{
Query: `((images.name == "some-name") or (images.name == "other-name"))`,
},
includedRuns: []*models.Run{run1, run2},
expectedRecordRangeUsedMax: 4,
expectedIndexRangeUsedMax: 4,
Expand All @@ -146,9 +148,10 @@ func (s *SearchArtifactsTestSuite) Test_Ok() {
{
name: "SearchArtifactWithRecordRange",
request: request.SearchArtifactsRequest{
Query: `((images.name == "some-name"))`,
RecordRange: "0:2",
},
includedRuns: []*models.Run{run1, run2},
includedRuns: []*models.Run{run1},
expectedRecordRangeUsedMax: 2,
expectedIndexRangeUsedMax: 4,
expectedImageIndexesPresent: []int{0, 1, 2, 3},
Expand All @@ -157,9 +160,10 @@ func (s *SearchArtifactsTestSuite) Test_Ok() {
{
name: "SearchArtifactWithIndexRange",
request: request.SearchArtifactsRequest{
Query: `((images.name == "some-name"))`,
IndexRange: "0:2",
},
includedRuns: []*models.Run{run1, run2},
includedRuns: []*models.Run{run1},
expectedRecordRangeUsedMax: 4,
expectedIndexRangeUsedMax: 2,
expectedImageIndexesPresent: []int{0, 1, 2},
Expand All @@ -168,6 +172,7 @@ func (s *SearchArtifactsTestSuite) Test_Ok() {
{
name: "SearchArtifactWithIndexDensity",
request: request.SearchArtifactsRequest{
Query: `((images.name == "other-name"))`,
IndexDensity: 2,
},
includedRuns: []*models.Run{run2},
Expand Down

0 comments on commit 71ec47b

Please sign in to comment.