Skip to content

Commit

Permalink
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
Browse files Browse the repository at this point in the history
…om/Azure/azure-cosmos-dotnet-v3 into users/akotalwar/TurnOnODEByDefault
  • Loading branch information
akotalwar committed Jan 19, 2024
2 parents 131112c + 78ea0e4 commit f84c9d9
Show file tree
Hide file tree
Showing 5 changed files with 567 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ private static SqlScalarExpression ApplyCustomConverters(Expression left, SqlLit
memberExpression = left as MemberExpression;
}

if (memberExpression != null)
if (memberExpression != null &&
right.Literal is not SqlNullLiteral)
{
Type memberType = memberExpression.Type;
if (memberType.IsNullable())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ WHERE (root["numericFieldDataMember"] = 1)]]></SqlQuery>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null})]]></SqlQuery>
WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null})]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
Expand All @@ -48,7 +48,7 @@ WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id":
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null}
SELECT VALUE {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null}
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
Expand All @@ -75,7 +75,7 @@ FROM root]]></SqlQuery>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE ((root["numericFieldDataMember"] > 1) ? {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null} : {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null})
SELECT VALUE ((root["numericFieldDataMember"] > 1) ? {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null} : {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null})
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
Expand Down Expand Up @@ -112,6 +112,111 @@ WHERE (root = {"numericFieldDataMember": root["numericFieldDataMember"], "string
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ nullable property, camelcase = True]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.DateTimeField != null))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["dateTimeFieldDataMember"] != null)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ nullable enum, camelcase = True]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.DataTypeField != null))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["dataTypeFieldDataMember"] != null)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ non-null nullable property]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.DateTimeField == Convert(new DateTime(1970, 1, 1, 0, 0, 0, 0, Utc), Nullable`1)))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["dateTimeFieldDataMember"] = "1970-01-01T00:00:00Z")]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ non-null nullable enum]]></Description>
<Expression><![CDATA[query.Where(doc => (Convert(doc.DataTypeField, Nullable`1) == Convert(Point, Nullable`1)))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["dataTypeFieldDataMember"] = 2)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ string null comparison, camelcase = True]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.StringField != null))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["stringFieldDataMember"] != null)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
Expand Down Expand Up @@ -146,7 +251,7 @@ WHERE (root["NumericFieldDataMember"] = 1)]]></SqlQuery>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null})]]></SqlQuery>
WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null})]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
Expand All @@ -165,7 +270,7 @@ WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id":
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null}
SELECT VALUE {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null}
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
Expand All @@ -192,7 +297,7 @@ FROM root]]></SqlQuery>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE ((root["NumericFieldDataMember"] > 1) ? {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null} : {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null})
SELECT VALUE ((root["NumericFieldDataMember"] > 1) ? {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null} : {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null})
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
Expand Down Expand Up @@ -229,6 +334,111 @@ WHERE (root = {"NumericFieldDataMember": root["NumericFieldDataMember"], "String
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ nullable property, camelcase = False]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.DateTimeField != null))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["DateTimeFieldDataMember"] != null)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ nullable enum, camelcase = False]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.DataTypeField != null))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["DataTypeFieldDataMember"] != null)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ non-null nullable property]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.DateTimeField == Convert(new DateTime(1970, 1, 1, 0, 0, 0, 0, Utc), Nullable`1)))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["DateTimeFieldDataMember"] = "1970-01-01T00:00:00Z")]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ non-null nullable enum]]></Description>
<Expression><![CDATA[query.Where(doc => (Convert(doc.DataTypeField, Nullable`1) == Convert(Point, Nullable`1)))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["DataTypeFieldDataMember"] = 2)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ string null comparison, camelcase = False]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.StringField != null))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["StringFieldDataMember"] != null)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
Expand Down
Loading

0 comments on commit f84c9d9

Please sign in to comment.