-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSHARP-5375: Remove KnownSerializerRegistry. #1552
base: main
Are you sure you want to change the base?
Conversation
@@ -32,6 +32,7 @@ internal static class PartialEvaluator | |||
typeof(DateTimeExtensions), | |||
typeof(LinqExtensions), | |||
typeof(MongoEnumerable), | |||
typeof(Mql), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep Mql.Constant(...)
from being evaluated client-side.
@@ -102,7 +103,7 @@ public static AggregationExpression Translate(TranslationContext context, Method | |||
var funcLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(method, arguments[2]); | |||
var funcParameters = funcLambda.Parameters; | |||
var accumulatorParameter = funcParameters[0]; | |||
var accumulatorSerializer = context.KnownSerializersRegistry.GetSerializer(accumulatorParameter); | |||
var accumulatorSerializer = BsonSerializer.LookupSerializer(accumulatorParameter.Type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to have a factory for numeric return types to protect ourselves from users registering weird serializers for numeric types.
} | ||
else | ||
{ | ||
throw new ExpressionNotSupportedException(expression, because: "the registred serializer is not representation configurable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, contains a typo... will fix in next commit.
AggregationExpression ifTrueTranslation; | ||
AggregationExpression ifFalseTranslation; | ||
IBsonSerializer resultSerializer; | ||
if (ifTrueExpression is ConstantExpression ifTrueConstantExpression) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one result is a constant use the serializer of the other expression to serialize the constant.
@@ -57,7 +57,7 @@ public static AggregationExpression Translate(TranslationContext context, NewExp | |||
var millisecondTranslation = millisecondExpression != null ? ExpressionToAggregationExpressionTranslator.Translate(context, millisecondExpression) : null; | |||
|
|||
var ast = AstExpression.DateFromParts(yearTranslation.Ast, monthTranslation.Ast, dayTranslation.Ast, hourTranslation?.Ast, minuteTranslation?.Ast, secondTranslation?.Ast, millisecondTranslation?.Ast); | |||
var serializer = context.KnownSerializersRegistry.GetSerializer(expression); | |||
var serializer = DateTimeSerializer.Instance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to look up anything. We know which serializer we need.
@@ -27,7 +27,7 @@ public static AstFilter Translate(TranslationContext context, ParameterExpressio | |||
{ | |||
if (context.SymbolTable.TryGetSymbol(expression, out var symbol)) | |||
{ | |||
var serializer = context.KnownSerializersRegistry.GetSerializer(expression); | |||
var serializer = symbol.Serializer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to look up anything. We know which serializer we need.
_translationOptions = translationOptions ?? new ExpressionTranslationOptions(); | ||
_data = data; // can be null | ||
} | ||
|
||
// public properties | ||
public TranslationContextData Data => _data; | ||
public KnownSerializersRegistry KnownSerializersRegistry => _knownSerializersRegistry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of making the serializer registry part of the context so we're not tied to using the global registry?
In the short term it's the same thing, but it looks towards the future where we want to specify different registries for different collections.
@@ -71,7 +72,7 @@ public void Predicate_should_use_correct_representation(int i, string projection | |||
(d => new R<E> { N = d.Id, V = d.I1 == E.E1 ? d.S1 : E.E2 }, "{ $project : { N : '$_id', V : { $cond : { if : { $eq : ['$I1', 1] }, then : '$S1', else : 'E2' } }, _id : 0 } }", new[] { E.E1, E.E2 }), | |||
(d => new R<E> { N = d.Id, V = d.I1 == E.E1 ? E.E1 : d.S2 }, "{ $project : { N : '$_id', V : { $cond : { if : { $eq : ['$I1', 1] }, then : 'E1', else : '$S2' } }, _id : 0 } }", new[] { E.E1, E.E2 }), | |||
(d => new R<E> { N = d.Id, V = d.I1 == E.E1 ? d.S1 : d.S2 }, "{ $project : { N : '$_id', V : { $cond : { if : { $eq : ['$I1', 1] }, then : '$S1', else : '$S2' } }, _id : 0 } }", new[] { E.E1, E.E2 }), | |||
(d => new R<E> { N = d.Id, V = d.S1 == E.E1 ? E.E1 : E.E2 }, "{ $project : { N : '$_id', V : { $cond : { if : { $eq : ['$S1', 'E1'] }, then : 'E1', else : 'E2' } }, _id : 0 } }", new[] { E.E1, E.E2 }), | |||
(d => new R<E> { N = d.Id, V = d.S1 == E.E1 ? Mql.Constant(E.E1, BsonType.String) : E.E2 }, "{ $project : { N : '$_id', V : { $cond : { if : { $eq : ['$S1', 'E1'] }, then : 'E1', else : 'E2' } }, _id : 0 } }", new[] { E.E1, E.E2 }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the scenario we were discussing in Slack.
Since the ternary operator has two constants we now default to using the registered serializer, but using Mql.Constant
the user can override that.
No description provided.