From 510bbd63245cb36f2492374e02bc6a559eef8a30 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Tue, 27 Feb 2024 12:04:50 -0500 Subject: [PATCH] PR FIXUP - FieldKind.IsArray etc --- client/definitions.go | 25 --------------- client/descriptions.go | 50 +++++++++++++++--------------- client/document.go | 2 +- db/collection.go | 2 +- db/collection_update.go | 2 +- planner/mapper/mapper.go | 8 ++--- request/graphql/parser/filter.go | 2 +- tests/gen/gen_auto.go | 2 +- tests/gen/gen_auto_config.go | 4 +-- tests/gen/gen_auto_configurator.go | 10 +++--- 10 files changed, 41 insertions(+), 66 deletions(-) diff --git a/client/definitions.go b/client/definitions.go index 974e904ec6..e521a69fcf 100644 --- a/client/definitions.go +++ b/client/definitions.go @@ -109,32 +109,7 @@ func NewFieldDefinition(local CollectionFieldDescription, global SchemaFieldDesc } } -// IsObject returns true if this field is an object type. -func (f FieldDefinition) IsObject() bool { - return (f.Kind == FieldKind_FOREIGN_OBJECT) || - (f.Kind == FieldKind_FOREIGN_OBJECT_ARRAY) -} - -// IsObjectArray returns true if this field is an object array type. -func (f FieldDefinition) IsObjectArray() bool { - return (f.Kind == FieldKind_FOREIGN_OBJECT_ARRAY) -} - // IsRelation returns true if this field is a relation. func (f FieldDefinition) IsRelation() bool { return f.RelationName != "" } - -// IsArray returns true if this field is an array type which includes inline arrays as well -// as relation arrays. -func (f FieldDefinition) IsArray() bool { - return f.Kind == FieldKind_BOOL_ARRAY || - f.Kind == FieldKind_INT_ARRAY || - f.Kind == FieldKind_FLOAT_ARRAY || - f.Kind == FieldKind_STRING_ARRAY || - f.Kind == FieldKind_FOREIGN_OBJECT_ARRAY || - f.Kind == FieldKind_NILLABLE_BOOL_ARRAY || - f.Kind == FieldKind_NILLABLE_INT_ARRAY || - f.Kind == FieldKind_NILLABLE_FLOAT_ARRAY || - f.Kind == FieldKind_NILLABLE_STRING_ARRAY -} diff --git a/client/descriptions.go b/client/descriptions.go index 1c6850f6a8..165a45bcdd 100644 --- a/client/descriptions.go +++ b/client/descriptions.go @@ -238,6 +238,31 @@ func (f FieldKind) String() string { } } +// IsObject returns true if this FieldKind is an object type. +func (f FieldKind) IsObject() bool { + return (f == FieldKind_FOREIGN_OBJECT) || + (f == FieldKind_FOREIGN_OBJECT_ARRAY) +} + +// IsObjectArray returns true if this FieldKind is an object array type. +func (f FieldKind) IsObjectArray() bool { + return (f == FieldKind_FOREIGN_OBJECT_ARRAY) +} + +// IsArray returns true if this FieldKind is an array type which includes inline arrays as well +// as relation arrays. +func (f FieldKind) IsArray() bool { + return f == FieldKind_BOOL_ARRAY || + f == FieldKind_INT_ARRAY || + f == FieldKind_FLOAT_ARRAY || + f == FieldKind_STRING_ARRAY || + f == FieldKind_FOREIGN_OBJECT_ARRAY || + f == FieldKind_NILLABLE_BOOL_ARRAY || + f == FieldKind_NILLABLE_INT_ARRAY || + f == FieldKind_NILLABLE_FLOAT_ARRAY || + f == FieldKind_NILLABLE_STRING_ARRAY +} + // Note: These values are serialized and persisted in the database, avoid modifying existing values. const ( FieldKind_None FieldKind = 0 @@ -343,36 +368,11 @@ type CollectionFieldDescription struct { ID FieldID } -// IsObject returns true if this field is an object type. -func (f SchemaFieldDescription) IsObject() bool { - return (f.Kind == FieldKind_FOREIGN_OBJECT) || - (f.Kind == FieldKind_FOREIGN_OBJECT_ARRAY) -} - -// IsObjectArray returns true if this field is an object array type. -func (f SchemaFieldDescription) IsObjectArray() bool { - return (f.Kind == FieldKind_FOREIGN_OBJECT_ARRAY) -} - // IsRelation returns true if this field is a relation. func (f SchemaFieldDescription) IsRelation() bool { return f.RelationName != "" } -// IsArray returns true if this field is an array type which includes inline arrays as well -// as relation arrays. -func (f SchemaFieldDescription) IsArray() bool { - return f.Kind == FieldKind_BOOL_ARRAY || - f.Kind == FieldKind_INT_ARRAY || - f.Kind == FieldKind_FLOAT_ARRAY || - f.Kind == FieldKind_STRING_ARRAY || - f.Kind == FieldKind_FOREIGN_OBJECT_ARRAY || - f.Kind == FieldKind_NILLABLE_BOOL_ARRAY || - f.Kind == FieldKind_NILLABLE_INT_ARRAY || - f.Kind == FieldKind_NILLABLE_FLOAT_ARRAY || - f.Kind == FieldKind_NILLABLE_STRING_ARRAY -} - // IsSet returns true if the target relation type is set. func (m RelationType) IsSet(target RelationType) bool { return m&target > 0 diff --git a/client/document.go b/client/document.go index 0157c595da..866910e89c 100644 --- a/client/document.go +++ b/client/document.go @@ -526,7 +526,7 @@ func (doc *Document) Set(field string, value any) error { if !exists { return NewErrFieldNotExist(field) } - if fd.IsRelation() && !fd.IsObjectArray() { + if fd.IsRelation() && !fd.Kind.IsObjectArray() { if !strings.HasSuffix(field, request.RelatedObjectID) { field = field + request.RelatedObjectID } diff --git a/db/collection.go b/db/collection.go index 3542905b59..ec007130b8 100644 --- a/db/collection.go +++ b/db/collection.go @@ -1446,7 +1446,7 @@ func (c *collection) tryGetFieldKey(primaryKey core.PrimaryDataStoreKey, fieldNa func (c *collection) tryGetSchemaFieldID(fieldName string) (uint32, bool) { for _, field := range c.Definition().GetFields() { if field.Name == fieldName { - if field.IsObject() || field.IsObjectArray() { + if field.Kind.IsObject() || field.Kind.IsObjectArray() { // We do not wish to match navigational properties, only // fields directly on the collection. return uint32(0), false diff --git a/db/collection_update.go b/db/collection_update.go index 0939a4088b..fc985d2c41 100644 --- a/db/collection_update.go +++ b/db/collection_update.go @@ -439,7 +439,7 @@ func (c *collection) makeSelectLocal(filter immutable.Option[request.Filter]) (* } for _, fd := range c.Schema().Fields { - if fd.IsObject() { + if fd.Kind.IsObject() { continue } slct.Fields = append(slct.Fields, &request.Field{ diff --git a/planner/mapper/mapper.go b/planner/mapper/mapper.go index fb18633b79..953d21ce17 100644 --- a/planner/mapper/mapper.go +++ b/planner/mapper/mapper.go @@ -112,9 +112,9 @@ func toSelect( // Remap all alias field names to use their internal field name mappings. for index, groupByField := range groupByFields { fieldDesc, ok := definition.GetFieldByName(groupByField) - if ok && fieldDesc.IsObject() && !fieldDesc.IsObjectArray() { + if ok && fieldDesc.Kind.IsObject() && !fieldDesc.Kind.IsObjectArray() { groupByFields[index] = groupByField + request.RelatedObjectID - } else if ok && fieldDesc.IsObjectArray() { + } else if ok && fieldDesc.Kind.IsObjectArray() { return nil, NewErrInvalidFieldToGroupBy(groupByField) } } @@ -289,7 +289,7 @@ func resolveAggregates( if childIsMapped { fieldDesc, isField := def.GetFieldByName(target.hostExternalName) - if isField && !fieldDesc.IsObject() { + if isField && !fieldDesc.Kind.IsObject() { var order *OrderBy if target.order.HasValue() && len(target.order.Value().Conditions) > 0 { // For inline arrays the order element will consist of just a direction @@ -792,7 +792,7 @@ func getTopLevelInfo( definition = collection.Definition() // Map all fields from schema into the map as they are fetched automatically for _, f := range definition.GetFields() { - if f.IsObject() { + if f.Kind.IsObject() { // Objects are skipped, as they are not fetched by default and // have to be requested via selects. continue diff --git a/request/graphql/parser/filter.go b/request/graphql/parser/filter.go index bd71925b7a..d7e7f44d40 100644 --- a/request/graphql/parser/filter.go +++ b/request/graphql/parser/filter.go @@ -222,7 +222,7 @@ func parseFilterFieldsForDescriptionMap( fields = append(fields, parsedFileds...) default: f, found := col.GetFieldByName(k) - if !found || f.IsObject() { + if !found || f.Kind.IsObject() { continue } fields = append(fields, f) diff --git a/tests/gen/gen_auto.go b/tests/gen/gen_auto.go index 659b4d0c83..c837b822a9 100644 --- a/tests/gen/gen_auto.go +++ b/tests/gen/gen_auto.go @@ -225,7 +225,7 @@ func validateDefinitions(definitions []client.CollectionDefinition) error { if field.Name == "" { return NewErrIncompleteColDefinition("field name is empty") } - if field.IsObject() { + if field.Kind.IsObject() { if field.Schema == "" { return NewErrIncompleteColDefinition("field schema is empty") } diff --git a/tests/gen/gen_auto_config.go b/tests/gen/gen_auto_config.go index 7e31a98388..eab85dd318 100644 --- a/tests/gen/gen_auto_config.go +++ b/tests/gen/gen_auto_config.go @@ -86,8 +86,8 @@ func checkAndValidateMinMax(field *client.SchemaFieldDescription, conf *genConfi _, hasMin := conf.props["min"] if hasMin { var err error - if field.IsArray() || field.Kind == client.FieldKind_NILLABLE_INT { - err = validateMinConfig[int](conf, field.IsArray()) + if field.Kind.IsArray() || field.Kind == client.FieldKind_NILLABLE_INT { + err = validateMinConfig[int](conf, field.Kind.IsArray()) } else { err = validateMinConfig[float64](conf, false) } diff --git a/tests/gen/gen_auto_configurator.go b/tests/gen/gen_auto_configurator.go index a499398f9c..b4746ae437 100644 --- a/tests/gen/gen_auto_configurator.go +++ b/tests/gen/gen_auto_configurator.go @@ -273,11 +273,11 @@ func (g *docsGenConfigurator) getDemandForPrimaryType( ) (typeDemand, error) { primaryTypeDef := g.types[primaryType] for _, field := range primaryTypeDef.Schema.Fields { - if field.IsObject() && field.Schema == secondaryType { + if field.Kind.IsObject() && field.Schema == secondaryType { primaryDemand := typeDemand{min: secondaryDemand.min, max: secondaryDemand.max} minPerDoc, maxPerDoc := 1, 1 - if field.IsArray() { + if field.Kind.IsArray() { fieldConf := g.config.ForField(primaryType, field.Name) minPerDoc, maxPerDoc = getMinMaxOrDefault(fieldConf, 0, secondaryDemand.max) // if we request min 100 of secondary docs and there can be max 5 per primary doc, @@ -339,14 +339,14 @@ func (g *docsGenConfigurator) calculateDemandForSecondaryTypes( ) error { typeDef := g.types[typeName] for _, field := range typeDef.Schema.Fields { - if field.IsObject() && !field.IsPrimaryRelation { + if field.Kind.IsObject() && !field.IsPrimaryRelation { primaryDocDemand := g.docsDemand[typeName] newSecDemand := typeDemand{min: primaryDocDemand.min, max: primaryDocDemand.max} minPerDoc, maxPerDoc := 1, 1 curSecDemand, hasSecDemand := g.docsDemand[field.Schema] - if field.IsArray() { + if field.Kind.IsArray() { fieldConf := g.config.ForField(typeName, field.Name) if prop, ok := fieldConf.props["min"]; ok { minPerDoc = prop.(int) @@ -418,7 +418,7 @@ func getRelationGraph(types map[string]client.CollectionDefinition) map[string][ for typeName, typeDef := range types { for _, field := range typeDef.Schema.Fields { - if field.IsObject() { + if field.Kind.IsObject() { if field.IsPrimaryRelation { primaryGraph[typeName] = appendUnique(primaryGraph[typeName], field.Schema) } else {