Skip to content

Commit

Permalink
Fix KeyColumn require and operators properties not being set to defau…
Browse files Browse the repository at this point in the history
…lt if a TableMapFunc is used. Closes #206
  • Loading branch information
kaidaguerre committed Nov 3, 2021
1 parent b577572 commit 6bda6bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion plugin/key_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (k *KeyColumn) Validate() []string {
// first set default operator and convert "!=" to "<>"
k.InitialiseOperators()
// ensure operators are valid

validOperators := []string{"=", "<>", "<", "<=", ">", ">="}
validRequire := []string{Required, Optional, AnyOf}
var res []string
Expand Down
11 changes: 6 additions & 5 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ func (p *Plugin) SetConnectionConfig(connectionName, connectionConfigString stri
}
}()

// first validate the plugin
if validationErrors := p.Validate(); validationErrors != "" {
return fmt.Errorf("plugin %s validation failed: \n%s", p.Name, validationErrors)
}

// create connection object
p.Connection = &Connection{Name: connectionName}

Expand Down Expand Up @@ -154,6 +149,12 @@ func (p *Plugin) initialiseTables(ctx context.Context) (err error) {
for _, table := range p.TableMap {
table.Plugin = p
}
// now validate the plugin
// NOTE: must do this after calling TableMapFunc
if validationErrors := p.Validate(); validationErrors != "" {
return fmt.Errorf("plugin %s validation failed: \n%s", p.Name, validationErrors)
}

return nil
}

Expand Down
1 change: 0 additions & 1 deletion plugin/table_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (t Table) GetSchema() *proto.TableSchema {
if len(t.List.KeyColumns) > 0 {
schema.ListCallKeyColumnList = t.List.KeyColumns.ToProtobuf()
}

}

return schema
Expand Down
9 changes: 8 additions & 1 deletion plugin/table_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func (t *Table) validate(name string, requiredColumns []*Column) []string {
// verify all required columns exist
validationErrors = t.validateRequiredColumns(requiredColumns)

// validated list config
// validated list and get config
// NOTE: this also sets key column require and operators to default value if not specified
validationErrors = append(validationErrors, t.validateListAndGetConfig()...)

// verify hydrate dependencies are valid
Expand Down Expand Up @@ -74,6 +75,8 @@ func columnTypeToString(columnType proto.ColumnType) string {
}
}

// validate list and get config
// NOTE: this initialises key column properties to their defaults
func (t *Table) validateListAndGetConfig() []string {
var validationErrors []string
// either get or list must be defined
Expand All @@ -96,6 +99,7 @@ func (t *Table) validateListAndGetConfig() []string {
}

// verify any key columns defined for GET only use '=' operators
// also set key column require and operators to default value if not specified
validationErrors = append(validationErrors, t.validateKeyColumns()...)

return validationErrors
Expand All @@ -122,6 +126,7 @@ func (t *Table) validateHydrateDependencies() []string {
}
return validationErrors
}

func (t *Table) detectCyclicHydrateDependencies() string {
var dependencies = topsort.NewGraph()
dependencies.AddNode("root")
Expand All @@ -147,6 +152,8 @@ func (t *Table) detectCyclicHydrateDependencies() string {
return ""
}

// validate key columns
// also set key column require and operators to default value if not specified
func (t *Table) validateKeyColumns() []string {
// get key columns should only have equals operators
var getValidationErrors []string
Expand Down

0 comments on commit 6bda6bd

Please sign in to comment.