Skip to content

Commit

Permalink
Merge pull request #70 from simple-machines/topic/entity-required-typ…
Browse files Browse the repository at this point in the history
…e-field

Add required type field to entities
  • Loading branch information
HuwCampbell authored Aug 2, 2022
2 parents ddd9159 + 955fa86 commit f983465
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
17 changes: 9 additions & 8 deletions client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package anaml

// Entity ..
type Entity struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"adt_type"`
DefaultColumn *string `json:"defaultColumn,omitempty"`
Entities *[]int `json:"entities,omitempty"`
Labels []string `json:"labels"`
Attributes []Attribute `json:"attributes"`
ID int `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"adt_type"`
DefaultColumn *string `json:"defaultColumn,omitempty"`
RequiredType *interface{} `json:"requiredType,omitempty"`
Entities *[]int `json:"entities,omitempty"`
Labels []string `json:"labels"`
Attributes []Attribute `json:"attributes"`
}

// EntityMapping ..
Expand Down
36 changes: 36 additions & 0 deletions client/resource_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const entityDescription = `# Entities
Expand Down Expand Up @@ -50,6 +51,15 @@ func ResourceEntity() *schema.Resource {
Optional: true,
ExactlyOneOf: []string{"default_column", "entities"},
},
"required_type": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"entities"},
ValidateFunc: validation.StringInSlice([]string{
"string", "integer", "long", "binary",
}, false),
Description: "The data type the entity is encoded as. If set, tables' entity columns must be of this type. One of string, integer, long, or binary",
},
"entities": {
Type: schema.TypeList,
Description: "Entities from which this composite entity is derived",
Expand Down Expand Up @@ -99,6 +109,25 @@ func resourceEntityRead(d *schema.ResourceData, m interface{}) error {
if err := d.Set("default_column", entity.DefaultColumn); err != nil {
return err
}

if entity.RequiredType != nil {
derefed := *(entity.RequiredType)
requiredTypeString, ok := derefed.(string)

if ok {
if err := d.Set("required_type", requiredTypeString); err != nil {
return err
}
} else {
if err := d.Set("required_type", "Complex Type"); err != nil {
return err
}
}
} else {
if err := d.Set("required_type", nil); err != nil {
return err
}
}
if err := d.Set("entities", nil); err != nil {
return err
}
Expand All @@ -107,6 +136,9 @@ func resourceEntityRead(d *schema.ResourceData, m interface{}) error {
if err := d.Set("default_column", nil); err != nil {
return err
}
if err := d.Set("required_type", nil); err != nil {
return err
}
if err := d.Set("entities", identifierList(*entity.Entities)); err != nil {
return err
}
Expand All @@ -131,6 +163,10 @@ func buildEntity(d *schema.ResourceData) Entity {
if default_column := d.Get("default_column").(string); default_column != "" {
entity.Type = "base"
entity.DefaultColumn = &default_column
if required_type, set := d.GetOk("required_type"); set {
required_type := required_type
entity.RequiredType = &required_type
}
} else {
entities := expandIdentifierList(d.Get("entities").([]interface{}))
entity.Type = "composite"
Expand Down
2 changes: 1 addition & 1 deletion client/resource_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ResourceFeature() *schema.Resource {
"sum", "count", "countdistinct", "avg", "std", "min", "max", "minby", "maxby",
"last", "percentagechange", "absolutechange", "standardscore", "basketsum",
"basketlast", "collectlist", "collectset",
}, true),
}, false),
RequiredWith: []string{"table"},
},
"post_aggregation": {
Expand Down
6 changes: 3 additions & 3 deletions client/resource_feature_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func folderDestinationSchema() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"overwrite", "ignore", "append", "errorifexists",
}, true),
}, false),
},
},
}
Expand All @@ -202,7 +202,7 @@ func tableDestinationSchema() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"overwrite", "ignore", "append", "errorifexists",
}, true),
}, false),
},
},
}
Expand All @@ -221,7 +221,7 @@ func topicDestinationSchema() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"json", "avro",
}, true),
}, false),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion client/resource_feature_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func ResourceFeatureTemplate() *schema.Resource {
"sum", "count", "countdistinct", "avg", "std", "min", "max", "minby", "maxby",
"last", "percentagechange", "absolutechange", "standardscore", "basketsum",
"basketlast", "collectlist", "collectset",
}, true),
}, false),
},
"post_aggregation": {
Type: schema.TypeString,
Expand Down

0 comments on commit f983465

Please sign in to comment.