Skip to content

Commit

Permalink
Fix issue #2712: add overload to set custom uri functions on model scope
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed Aug 7, 2023
1 parent 6c6ea19 commit b32c248
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2284,9 +2284,9 @@ static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Min ->
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Sum -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.VirtualPropertyCount -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken.Merge(Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token1, Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token2) -> Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.Edm.IEdmTypeReference edmTypeReference, Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.RemoveCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2291,9 +2291,9 @@ static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Min ->
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Sum -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.VirtualPropertyCount -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken.Merge(Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token1, Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token2) -> Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.Edm.IEdmTypeReference edmTypeReference, Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.RemoveCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2284,9 +2284,9 @@ static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Min ->
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Sum -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.VirtualPropertyCount -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken.Merge(Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token1, Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token2) -> Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.Edm.IEdmTypeReference edmTypeReference, Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.RemoveCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2284,9 +2284,9 @@ static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Min ->
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.Sum -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition.VirtualPropertyCount -> Microsoft.OData.UriParser.Aggregation.AggregationMethodDefinition
static Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken.Merge(Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token1, Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken token2) -> Microsoft.OData.UriParser.Aggregation.EntitySetAggregateToken
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> void
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, Microsoft.OData.Edm.IEdmModel model = null) -> bool
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.Edm.IEdmTypeReference edmTypeReference, Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.AddCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> void
static Microsoft.OData.UriParser.CustomUriLiteralParsers.RemoveCustomUriLiteralParser(Microsoft.OData.UriParser.IUriLiteralParser customUriLiteralParser) -> bool
Expand Down
16 changes: 13 additions & 3 deletions src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ internal static KeyValuePair<string, FunctionSignatureWithReturnType> MatchSigna
/// </summary>
/// <param name="functionCallToken">The function call token to get the signatures for.</param>
/// <param name="enableCaseInsensitive">Optional flag for whether case insensitive match is enabled.</param>
/// <param name="model">Optional model for whether the custom function is from model scoped or global scoped. In 8.x, it will always from model scoped.</param>
/// <returns>The signatures which match the supplied function name.</returns>
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "need to use lower characters for built-in functions.")]
internal static IList<KeyValuePair<string, FunctionSignatureWithReturnType>> GetUriFunctionSignatures(string functionCallToken, bool enableCaseInsensitive = false)
internal static IList<KeyValuePair<string, FunctionSignatureWithReturnType>> GetUriFunctionSignatures(string functionCallToken,
bool enableCaseInsensitive = false, IEdmModel model = null)
{
IList<KeyValuePair<string, FunctionSignatureWithReturnType>> customUriFunctionsNameSignatures = null;
string builtInUriFunctionName = null;
Expand All @@ -155,7 +157,15 @@ internal static IList<KeyValuePair<string, FunctionSignatureWithReturnType>> Get

// Try to find the function in the user custom functions
bool customFound = CustomUriFunctions.TryGetCustomFunction(functionCallToken, out customUriFunctionsNameSignatures,
enableCaseInsensitive);
enableCaseInsensitive, model);

// for back-compatibility, we first find custom functions from model scope
// If not found, try to find from global scope
if (!customFound)
{
customFound = CustomUriFunctions.TryGetCustomFunction(functionCallToken, out customUriFunctionsNameSignatures,
enableCaseInsensitive, model: null);
}

bool builtInFound = BuiltInUriFunctions.TryGetBuiltInFunction(functionCallToken, enableCaseInsensitive, out builtInUriFunctionName,
out builtInUriFunctionsSignatures);
Expand Down Expand Up @@ -301,7 +311,7 @@ private QueryNode BindAsUriFunction(FunctionCallToken functionCallToken, List<Qu

// Do some validation and get potential Uri functions that could match what we saw
IList<KeyValuePair<string, FunctionSignatureWithReturnType>> nameSignatures = GetUriFunctionSignatures(functionCallToken.Name,
this.state.Configuration.EnableCaseInsensitiveUriFunctionIdentifier);
this.state.Configuration.EnableCaseInsensitiveUriFunctionIdentifier, this.state.Model);

SingleValueNode[] argumentNodeArray = ValidateArgumentsAreSingleValue(functionCallToken.Name, argumentNodes);
KeyValuePair<string, FunctionSignatureWithReturnType> nameSignature = MatchSignatureToUriFunction(functionCallToken.Name, argumentNodeArray, nameSignatures);
Expand Down
Loading

0 comments on commit b32c248

Please sign in to comment.