From 9ae39a5a5c9bf93e6175f4777bbdbe129aedbc71 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Mon, 8 May 2023 17:33:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0CompareValueToKey=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=8F=AF=E4=BB=A5=E5=AF=B9=E5=B1=9E=E6=80=A7=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E4=B8=AA=E6=AF=94=E8=BE=83=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=97=B6=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/Sample.SqlServer/Controllers/ValuesController.cs | 2 ++ .../AbstractShardingOperatorVirtualTableRoute.cs | 6 +++++- .../MultiAggregateOrderStreamMergeAsyncEnumerator.cs | 2 +- .../ShardingMergers/AbstractEnumerableShardingMerger.cs | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/samples/Sample.SqlServer/Controllers/ValuesController.cs b/samples/Sample.SqlServer/Controllers/ValuesController.cs index ad4c713a..ccc7d8f2 100644 --- a/samples/Sample.SqlServer/Controllers/ValuesController.cs +++ b/samples/Sample.SqlServer/Controllers/ValuesController.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Metadata; +using ShardingCore; using ShardingCore.Core.VirtualRoutes.TableRoutes; using ShardingCore.Extensions.ShardingQueryableExtensions; using ShardingCore.Core; @@ -43,6 +44,7 @@ namespace Sample.SqlServer.Controllers _shardingRouteManager = shardingRuntimeContext.GetShardingRouteManager(); _readWriteManager = shardingRuntimeContext.GetShardingReadWriteManager(); _shardingRuntimeContext = shardingRuntimeContext; + } [HttpGet] diff --git a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingOperatorVirtualTableRoute.cs b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingOperatorVirtualTableRoute.cs index f0d46de5..677dcdf5 100644 --- a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingOperatorVirtualTableRoute.cs +++ b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/Abstractions/AbstractShardingOperatorVirtualTableRoute.cs @@ -53,7 +53,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions { if (EntityMetadata.IsMainShardingTableKey(shardingPropertyName)) { - return GetRouteToFilter((TKey)shardingKey, shardingOperator); + return GetRouteToFilter(CompareValueToKey(shardingKey), shardingOperator); } else { @@ -61,6 +61,10 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions } } + public virtual TKey CompareValueToKey(object shardingKey) + { + return (TKey)shardingKey; + } public abstract Func GetRouteToFilter(TKey shardingKey, ShardingOperatorEnum shardingOperator); diff --git a/src/ShardingCore/Sharding/Enumerators/StreamMergeAsync/MultiAggregateOrderStreamMergeAsyncEnumerator.cs b/src/ShardingCore/Sharding/Enumerators/StreamMergeAsync/MultiAggregateOrderStreamMergeAsyncEnumerator.cs index 02d05e9e..b3c3919a 100644 --- a/src/ShardingCore/Sharding/Enumerators/StreamMergeAsync/MultiAggregateOrderStreamMergeAsyncEnumerator.cs +++ b/src/ShardingCore/Sharding/Enumerators/StreamMergeAsync/MultiAggregateOrderStreamMergeAsyncEnumerator.cs @@ -168,7 +168,7 @@ namespace ShardingCore.Sharding.Enumerators if (aggregateValues.IsNotEmpty()) { - var copyFields = string.Join(",", _mergeContext.SelectContext.SelectProperties.Select(o=>o.PropertyName)); + // var copyFields = string.Join(",", _mergeContext.SelectContext.SelectProperties.Select(o=>o.PropertyName)); CurrentValue = AggregateExtension.CopyTSource(aggregateValues.First()); if (aggregateValues.Count > 1) diff --git a/src/ShardingCore/Sharding/MergeEngines/Executors/ShardingMergers/AbstractEnumerableShardingMerger.cs b/src/ShardingCore/Sharding/MergeEngines/Executors/ShardingMergers/AbstractEnumerableShardingMerger.cs index f97872fe..c0be3129 100644 --- a/src/ShardingCore/Sharding/MergeEngines/Executors/ShardingMergers/AbstractEnumerableShardingMerger.cs +++ b/src/ShardingCore/Sharding/MergeEngines/Executors/ShardingMergers/AbstractEnumerableShardingMerger.cs @@ -75,7 +75,7 @@ namespace ShardingCore.Sharding.MergeEngines.Executors.ShardingMergers //聚合 if (parallelResults is IEnumerable> parallelStreamEnumeratorResults) { - var mergeAsyncEnumerators = new List>(parallelResults.Count); + var mergeAsyncEnumerators = new List>(parallelResults.Count+previewResultsCount); if (previewResultsCount == 1) { mergeAsyncEnumerators.Add(beforeInMemoryResults.First());