Skip to content

Commit

Permalink
feat: added new order constraint EntityPrimaryKeyNatural, added optio…
Browse files Browse the repository at this point in the history
…n to QueryValidator to to switch running profiles between demo and local evita instance, moved structures sorting logic to tests only - we only need it to be sorted for comparing in documentation tests, added documentation to query constraints and commonly used model classes, fixed serialization of ComplexDataObject when inner object is present fixed bugs found thanks to the new documentation tests
  • Loading branch information
tpz committed Dec 5, 2023
1 parent 9a09a95 commit 0d8b9fe
Show file tree
Hide file tree
Showing 135 changed files with 4,717 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public void Visit(DataItemMap mapItem)
var stackNode = _stack.Peek();
if (stackNode is JObject objectNode)
{
objectNode.Add(_propertyNameStack.Peek());
_stack.Push(objectNode);
JObject newObject = new();
objectNode.Add(_propertyNameStack.Peek(), newObject);
_stack.Push(newObject);
}
else if (stackNode is JArray arrayNode)
{
Expand Down Expand Up @@ -233,4 +234,4 @@ private void WriteNull()
throw new InvalidOperationException($"Unexpected type of node on stack: {theNode?.GetType()}");
}
}
}
}
77 changes: 49 additions & 28 deletions EvitaDB.Client/Converters/Models/Data/EntityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ public static T ToEntity<T>(Func<GrpcSealedEntity, ISealedEntitySchema> entitySc
parentEntity = parent;
}

return (T) Entity.InternalBuild(
List<Reference> references = grpcEntity.References
.Select(it => ToReference(entitySchema, entitySchemaProvider, it, evitaRequest))
.ToList();

if (IDevelopmentConstants.IsTestRun)
{
references.Sort((x, y) => x.ReferenceKey.CompareTo(y.ReferenceKey));
}

return (T)Entity.InternalBuild(
grpcEntity.PrimaryKey,
grpcEntity.Version,
entitySchema,
Expand Down Expand Up @@ -99,26 +108,37 @@ public static T ToEntity<T>(Func<GrpcSealedEntity, ISealedEntitySchema> entitySc
);
}

private static ICollection<AttributeValue> ToAttributeValues(
private static IDictionary<AttributeKey, AttributeValue> ToAttributeValues(
IDictionary<string, GrpcEvitaValue> globalAttributesMap,
IDictionary<string, GrpcLocalizedAttribute> localizedAttributesMap
)
{
List<AttributeValue> result = new(globalAttributesMap.Count + localizedAttributesMap.Count);
AttributeValue[] attributeValueTuples = new AttributeValue[globalAttributesMap.Count + localizedAttributesMap.Values.Select(x => x.Attributes.Count).Sum()];
int index = 0;
foreach (var (key, localizedAttributeSet) in localizedAttributesMap)
{
CultureInfo locale = new CultureInfo(key);
foreach (KeyValuePair<string, GrpcEvitaValue> attributeEntry in localizedAttributeSet.Attributes)
{
result.Add(
ToAttributeValue(new AttributeKey(attributeEntry.Key, locale), attributeEntry.Value)
);
attributeValueTuples[index++] =
ToAttributeValue(new AttributeKey(attributeEntry.Key, locale), attributeEntry.Value);
}
}

foreach (var (attributeName, value) in globalAttributesMap)
{
result.Add(ToAttributeValue(new AttributeKey(attributeName), value));
attributeValueTuples[index++] = ToAttributeValue(new AttributeKey(attributeName), value);
}

if (IDevelopmentConstants.IsTestRun)
{
Array.Sort(attributeValueTuples, (x, y) => x.Key.CompareTo(y.Key));
}

IDictionary<AttributeKey, AttributeValue> result = new Dictionary<AttributeKey, AttributeValue>(attributeValueTuples.Length);
foreach (var attributeValue in attributeValueTuples)
{
result.Add(attributeValue.Key, attributeValue);
}

return result;
Expand All @@ -133,37 +153,38 @@ private static AttributeValue ToAttributeValue(AttributeKey attributeKey, GrpcEv
EvitaDataTypesConverter.ToEvitaValue(attributeValue)
);
}

private static ICollection<AssociatedDataValue> ToAssociatedDataValues(
private static IDictionary<AssociatedDataKey, AssociatedDataValue> ToAssociatedDataValues(
IDictionary<string, GrpcEvitaAssociatedDataValue> globalAssociatedDataMap,
IDictionary<string, GrpcLocalizedAssociatedData> localizedAssociatedDataMap
)
{
List<AssociatedDataValue> result = new(globalAssociatedDataMap.Count + localizedAssociatedDataMap.Count);

AssociatedDataValue[] associatedDataValueTuples = new AssociatedDataValue[globalAssociatedDataMap.Count + localizedAssociatedDataMap.Values.Select(x => x.AssociatedData.Count).Sum()];
int index = 0;
foreach (var (key, localizedAssociatedDataSet) in localizedAssociatedDataMap)
{
CultureInfo locale = new CultureInfo(key);
foreach (KeyValuePair<string, GrpcEvitaAssociatedDataValue> associatedDataEntry in
localizedAssociatedDataSet.AssociatedData)
foreach (KeyValuePair<string, GrpcEvitaAssociatedDataValue> associatedDataEntry in localizedAssociatedDataSet.AssociatedData)
{
result.Add(
ToAssociatedDataValue(
new AssociatedDataKey(associatedDataEntry.Key, locale),
associatedDataEntry.Value
)
);
associatedDataValueTuples[index++] =
ToAssociatedDataValue(new AssociatedDataKey(associatedDataEntry.Key, locale), associatedDataEntry.Value);
}
}

foreach (var (associatedDataName, value) in globalAssociatedDataMap)
foreach (var (attributeName, value) in globalAssociatedDataMap)
{
result.Add(
ToAssociatedDataValue(
new AssociatedDataKey(associatedDataName),
value
)
);
associatedDataValueTuples[index++] = ToAssociatedDataValue(new AssociatedDataKey(attributeName), value);
}

if (IDevelopmentConstants.IsTestRun)
{
Array.Sort(associatedDataValueTuples, (x, y) => x.Key.CompareTo(y.Key));
}

IDictionary<AssociatedDataKey, AssociatedDataValue> result = new Dictionary<AssociatedDataKey, AssociatedDataValue>(associatedDataValueTuples.Length);
foreach (var associatedDataValue in associatedDataValueTuples)
{
result.Add(associatedDataValue.Key, associatedDataValue);
}

return result;
Expand Down Expand Up @@ -206,7 +227,7 @@ associatedDataValue.PrimitiveValue is not null
grpcPrice.Version
);
}

private static Reference ToReference(
ISealedEntitySchema entitySchema,
Func<GrpcSealedEntity, ISealedEntitySchema> entitySchemaProvider,
Expand Down Expand Up @@ -255,4 +276,4 @@ private static Reference ToReference(
: ToEntity<ISealedEntity>(entitySchemaProvider, grpcReference.GroupReferencedEntity, evitaRequest)
);
}
}
}
29 changes: 20 additions & 9 deletions EvitaDB.Client/Converters/Models/ResponseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static IDataChunk<T> ConvertToDataChunk<T>(GrpcQueryResponse grpcResponse

public static IEvitaResponseExtraResult[] ToExtraResults(
Func<GrpcSealedEntity, ISealedEntitySchema> entitySchemaFetcher,
EvitaRequest evitaRequest,
EvitaRequest evitaRequest,
GrpcExtraResults? extraResults)
{
Query query = evitaRequest.Query;
Expand Down Expand Up @@ -101,7 +101,7 @@ extraResults.SelfHierarchy is not null
evitaRequest,
hierarchyConstraints
.OfType<HierarchyOfReference>()
.First(it => it.ReferenceNames.Any(name => name == x.Key)),
.First(it => it.ReferenceNames.Any(name => name == x.Key)),
x.Value)
)
)
Expand Down Expand Up @@ -155,8 +155,11 @@ GrpcFacetGroupStatistics grpcFacetGroupStatistics
return new FacetGroupStatistics(
grpcFacetGroupStatistics.ReferenceName,
grpcFacetGroupStatistics.GroupEntity is not null
? EntityConverter.ToEntity<ISealedEntity>(entitySchemaFetcher, grpcFacetGroupStatistics.GroupEntity, evitaRequest)
: EntityConverter.ToEntityReference(grpcFacetGroupStatistics.GroupEntityReference),
? EntityConverter.ToEntity<ISealedEntity>(entitySchemaFetcher, grpcFacetGroupStatistics.GroupEntity,
evitaRequest.DeriveCopyWith(grpcFacetGroupStatistics.GroupEntity.EntityType, entityGroupFetch!))
: grpcFacetGroupStatistics.GroupEntityReference is not null
? EntityConverter.ToEntityReference(grpcFacetGroupStatistics.GroupEntityReference)
: null,
grpcFacetGroupStatistics.Count,
grpcFacetGroupStatistics.FacetStatistics
.Select(x => ToFacetStatistics(entitySchemaFetcher, evitaRequest, entityFetch, x))
Expand All @@ -176,12 +179,12 @@ grpcFacetStatistics.FacetEntity is not null
? EntityConverter.ToEntity<ISealedEntity>(
entitySchemaFetcher,
grpcFacetStatistics.FacetEntity,
evitaRequest
evitaRequest.DeriveCopyWith(grpcFacetStatistics.FacetEntity.EntityType, entityFetch!)
)
: EntityConverter.ToEntityReference(grpcFacetStatistics.FacetEntityReference),
grpcFacetStatistics.Requested,
grpcFacetStatistics.Count,
grpcFacetStatistics is {Impact: not null, MatchCount: not null}
grpcFacetStatistics is { Impact: not null, MatchCount: not null }
? new RequestImpact(
grpcFacetStatistics.Impact.Value,
grpcFacetStatistics.MatchCount.Value
Expand All @@ -206,7 +209,8 @@ GrpcHierarchy grpcHierarchy
cnt => cnt is IHierarchyRequireConstraint hrc && x.Key == hrc.OutputName
);
EntityFetch? entityFetch = QueryUtils.FindConstraint<EntityFetch>(hierarchyConstraint!);
return x.Value.LevelInfos.Select(y => ToLevelInfo(entitySchemaFetcher, evitaRequest, entityFetch, y)).ToList();
return x.Value.LevelInfos.Select(y => ToLevelInfo(entitySchemaFetcher, evitaRequest, entityFetch, y))
.ToList();
});
}

Expand All @@ -219,7 +223,14 @@ GrpcLevelInfo grpcLevelInfo
{
return new LevelInfo(
grpcLevelInfo.Entity is not null
? EntityConverter.ToEntity<ISealedEntity>(entitySchemaFetcher, grpcLevelInfo.Entity, evitaRequest)
? EntityConverter.ToEntity<ISealedEntity>(
entitySchemaFetcher,
grpcLevelInfo.Entity,
evitaRequest.DeriveCopyWith(
grpcLevelInfo.Entity.EntityType,
entityFetch!
)
)
: EntityConverter.ToEntityReference(grpcLevelInfo.EntityReference),
grpcLevelInfo.Requested,
grpcLevelInfo.QueriedEntityCount,
Expand Down Expand Up @@ -259,4 +270,4 @@ private static Bucket ToBucket(GrpcHistogram.Types.GrpcBucket grpcBucket)
grpcBucket.Requested
);
}
}
}
Loading

0 comments on commit 0d8b9fe

Please sign in to comment.