Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Lyft-Flyte
Browse files Browse the repository at this point in the history
* origin/master:
  #patch Allow unscoped filtering on all NamedEntity(Metadata) fields (#124)
  Put testdata together with test cases (#123)
  • Loading branch information
schottra committed Sep 8, 2020
2 parents 9cd682d + fab4226 commit 27cb574
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/common/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
Task = "t"
TaskExecution = "te"
Workflow = "w"
NamedEntity = "nen"
NamedEntityMetadata = "nem"
)

Expand Down
17 changes: 16 additions & 1 deletion pkg/common/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ var executionIdentifierFields = map[string]bool{
"name": true,
}

var entityMetadataFields = map[string]bool{
"description": true,
"state": true,
}

const unrecognizedFilterFunction = "unrecognized filter function: %s"
const unsupportedFilterExpression = "unsupported filter expression: %s"
const invalidSingleValueFilter = "invalid single value filter expression: %s"
Expand Down Expand Up @@ -235,14 +240,24 @@ func customizeField(field string, entity Entity) string {
return field
}

func customizeEntity(field string, entity Entity) Entity {
// NamedEntity is considered a single object, but the metdata
// is stored using a different entity type.
if entity == NamedEntity && entityMetadataFields[field] {
return NamedEntityMetadata
}
return entity
}

// Returns a filter which uses a single argument value.
func NewSingleValueFilter(entity Entity, function FilterExpression, field string, value interface{}) (InlineFilter, error) {
if _, ok := singleValueFilters[function]; !ok {
return nil, GetInvalidSingleValueFilterErr(function)
}
customizedField := customizeField(field, entity)
customizedEntity := customizeEntity(field, entity)
return &inlineFilterImpl{
entity: entity,
entity: customizedEntity,
function: function,
field: customizedField,
value: value,
Expand Down
14 changes: 13 additions & 1 deletion pkg/common/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestNewSingleBoolValueFilter(t *testing.T) {
assert.Equal(t, expression.Args, true)
}

func TestNewSingleValueCustomizedFilter(t *testing.T) {
func TestNewSingleValueCustomizedFieldFilter(t *testing.T) {
filter, err := NewSingleValueFilter(Execution, Equal, "project", "a project")
assert.NoError(t, err)

Expand All @@ -61,6 +61,18 @@ func TestNewSingleValueCustomizedFilter(t *testing.T) {
assert.Equal(t, "node_executions.execution_project = ?", expression.Query)
}

func TestNewSingleValueCustomizedEntityFilter(t *testing.T) {
filter, err := NewSingleValueFilter(NamedEntity, Equal, "state", 1)
assert.NoError(t, err)

assert.Equal(t, NamedEntityMetadata, filter.GetEntity())

filter, err = NewSingleValueFilter(NamedEntity, Equal, "description", "test value")
assert.NoError(t, err)

assert.Equal(t, NamedEntityMetadata, filter.GetEntity())
}

func TestNewRepeatedValueFilter(t *testing.T) {
vals := []string{"SuperAwesomeProject", "AnotherAwesomeProject"}
filter, err := NewRepeatedValueFilter(Workflow, ValueIn, "project", vals)
Expand Down
2 changes: 1 addition & 1 deletion pkg/executioncluster/impl/random_cluster_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func initTestConfig(fileName string) error {
}

configAccessor := viper.NewAccessor(config.Options{
SearchPaths: []string{filepath.Join(pwd, "../testdata", fileName)},
SearchPaths: []string{filepath.Join(pwd, "testdata", fileName)},
StrictMode: false,
})
return configAccessor.UpdateConfig(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/impl/named_entity_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (m *NamedEntityManager) getQueryFilters(referenceEntity core.ResourceType,
if len(requestFilters) == 0 {
return filters, nil
}
additionalFilters, err := util.ParseFilters(requestFilters, common.NamedEntityMetadata)
additionalFilters, err := util.ParseFilters(requestFilters, common.NamedEntity)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/manager/impl/util/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var filterFieldEntityPrefix = map[string]common.Entity{
"execution": common.Execution,
"node_execution": common.NodeExecution,
"task_execution": common.TaskExecution,
"entities": common.NamedEntity,
"named_entity_metadata": common.NamedEntityMetadata,
}

Expand Down
1 change: 1 addition & 0 deletions pkg/repositories/gormimpl/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var entityToTableName = map[common.Entity]string{
common.Task: "tasks",
common.TaskExecution: "task_executions",
common.Workflow: "workflows",
common.NamedEntity: "entities",
common.NamedEntityMetadata: "named_entity_metadata",
}

Expand Down

0 comments on commit 27cb574

Please sign in to comment.