-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
Support JsonOverlaps function #1985
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,74 @@ WHERE JSON_UNQUOTE(`j`.`CustomerElement`) = 'foo' | |
|
||
#region Functions | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_with_json_element() | ||
{ | ||
using var ctx = CreateContext(); | ||
var element = JsonDocument.Parse(@"{""Name"": ""Joe"", ""Age"": -1}").RootElement; | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(e.CustomerElement, element)); | ||
|
||
Assert.Equal(1, count); | ||
AssertSql( | ||
$@"@__element_1='{{""Name"":""Joe"",""Age"":-1}}' (Nullable = false) (Size = 4000) | ||
|
||
SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(`j`.`CustomerElement`, {InsertJsonConvert("@__element_1")})"); | ||
} | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_with_string() | ||
{ | ||
using var ctx = CreateContext(); | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(e.CustomerElement, @"{""Name"": ""Joe"", ""Age"": -1}")); | ||
|
||
Assert.Equal(1, count); | ||
AssertSql( | ||
@"SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(`j`.`CustomerElement`, '{""Name"": ""Joe"", ""Age"": -1}')"); | ||
} | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_using_JsonExtract_with_json_element() | ||
{ | ||
using var ctx = CreateContext(); | ||
var element = JsonDocument.Parse(@"[3,-1]").RootElement; | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(EF.Functions.JsonExtract<string[]>(e.CustomerElement, "$.Statistics.Nested.IntArray"), element)); | ||
|
||
Assert.Equal(1, count); | ||
var dd = InsertJsonConvert("@__element_1") ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably obsolete code that can be removed. |
||
AssertSql( | ||
$@"@__element_1='[3,-1]' (Nullable = false) (Size = 4000) | ||
|
||
SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(JSON_EXTRACT(`j`.`CustomerElement`, '$.Statistics.Nested.IntArray'), {InsertJsonConvert("@__element_1")})"); | ||
} | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_using_JsonExtract_with_json_string() | ||
{ | ||
using var ctx = CreateContext(); | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(EF.Functions.JsonExtract<string[]>(e.CustomerElement, "$.Statistics.Nested.IntArray"), @"[3,-1]")); | ||
|
||
Assert.Equal(1, count); | ||
var dd = InsertJsonConvert("@__element_1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably obsolete code that can be removed. |
||
AssertSql( | ||
$@"SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(JSON_EXTRACT(`j`.`CustomerElement`, '$.Statistics.Nested.IntArray'), '[3,-1]')"); | ||
} | ||
|
||
[Fact] | ||
public void JsonContains_with_json_element() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,7 +346,75 @@ WHERE JSON_UNQUOTE(`j`.`CustomerJToken`) = 'foo' | |
LIMIT 2"); | ||
} | ||
|
||
#region Functions | ||
#region Functions | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_with_json_element() | ||
{ | ||
using var ctx = CreateContext(); | ||
var element = JObject.Parse(@"{""Name"": ""Joe"", ""Age"": -1}").Root; | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(e.CustomerJToken, element)); | ||
|
||
Assert.Equal(1, count); | ||
AssertSql( | ||
$@"@__element_1='{{""Name"":""Joe"",""Age"":-1}}' (Size = 4000) | ||
|
||
SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(`j`.`CustomerJToken`, {InsertJsonConvert("@__element_1")})"); | ||
} | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_with_string() | ||
{ | ||
using var ctx = CreateContext(); | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(e.CustomerJToken, @"{""Name"": ""Joe"", ""Age"": -1}")); | ||
|
||
Assert.Equal(1, count); | ||
AssertSql( | ||
@"SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(`j`.`CustomerJToken`, '{""Name"": ""Joe"", ""Age"": -1}')"); | ||
} | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_using_JsonExtract_with_json_element() | ||
{ | ||
using var ctx = CreateContext(); | ||
var element = JArray.Parse(@"[3,-1]"); | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(EF.Functions.JsonExtract<string[]>(e.CustomerJToken, "$.Statistics.Nested.IntArray"), element)); | ||
|
||
Assert.Equal(1, count); | ||
var dd = InsertJsonConvert("@__element_1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably obsolete code that can be removed. |
||
AssertSql( | ||
$@"@__element_1='[3,-1]' (Size = 4000) | ||
|
||
SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(JSON_EXTRACT(`j`.`CustomerJToken`, '$.Statistics.Nested.IntArray'), {InsertJsonConvert("@__element_1")})"); | ||
} | ||
|
||
[ConditionalFact] | ||
[SupportedServerVersionCondition(nameof(ServerVersionSupport.JsonOverlaps))] | ||
public void JsonOverlaps_using_JsonExtract_with_json_string() | ||
{ | ||
using var ctx = CreateContext(); | ||
var count = ctx.JsonEntities.Count(e => | ||
EF.Functions.JsonOverlaps(EF.Functions.JsonExtract<string[]>(e.CustomerJToken, "$.Statistics.Nested.IntArray"), @"[3,-1]")); | ||
|
||
Assert.Equal(1, count); | ||
var dd = InsertJsonConvert("@__element_1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably obsolete code that can be removed. |
||
AssertSql( | ||
$@"SELECT COUNT(*) | ||
FROM `JsonEntities` AS `j` | ||
WHERE JSON_OVERLAPS(JSON_EXTRACT(`j`.`CustomerJToken`, '$.Statistics.Nested.IntArray'), '[3,-1]')"); | ||
} | ||
|
||
[Fact] | ||
public void JsonContains_with_json_element() | ||
|
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.
The parameters should probably be renamed to
json1
andjson2
respectively, to be closer to the ones used in MySQL/MariaDB (candidate
is the parameter name MySQL uses for theJSON_CONTAINS()
function).