Skip to content
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

[SMALL] Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server #30380

Merged
1 commit merged into from
Mar 2, 2023

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Mar 2, 2023

when producing update statement, when deciding whether we need CAST around the result of JSON_VALUE, we need to look if the property has converter, rather than just look at it's clr type. If the clr type is string, but it gets converted to int/bool etc we still need a CAST.

Fixes #30330

@maumar maumar requested a review from a team March 2, 2023 00:20
@maumar maumar changed the title Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server [SMALL] Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Hello @maumar!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
Copy link

ghost commented Mar 2, 2023

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines
  2. GitHub Actions

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

@maumar maumar removed the auto-merge label Mar 2, 2023
@maumar maumar changed the title [SMALL] Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server Mar 2, 2023
@maumar maumar changed the title Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server [SMALL] Fix to #30330 - Json: updating property with conversion from string to other type fails on sql server Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines
  2. Dotnet Policy Service

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

…o other type fails on sql server

when producing update statement, when deciding whether we need CAST around the result of JSON_VALUE, we need to look if the property has converter, rather than just look at it's clr type.
If the clr type is string, but it gets converted to int/bool etc we still need a CAST.

Fixes #30330
@ghost
Copy link

ghost commented Mar 2, 2023

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines
  2. GitHub Actions

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

1 similar comment
@ghost
Copy link

ghost commented Mar 2, 2023

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines
  2. GitHub Actions

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

@ghost
Copy link

ghost commented Mar 2, 2023

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

@@ -154,8 +154,10 @@ protected virtual int MergeIntoMinimumThreshold

if (columnModification.Property != null)
{
var needsTypeConversion = columnModification.Property.ClrType.IsNumeric()
|| columnModification.Property.ClrType == typeof(bool);
var propertyClrType = columnModification.Property.GetTypeMapping().Converter?.ProviderClrType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a simply shortcut to just get the provider CLR type of a property? If not, we probably should...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the method suggested by @AndriySvyryd, so I guess it's the best one we've got ;)

@@ -558,7 +558,7 @@ public override async Task Edit_single_property_char()

SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
UPDATE [JsonEntitiesAllTypes] SET [Reference] = JSON_MODIFY([Reference], 'strict $.TestCharacter', CAST(JSON_VALUE(@p0, '$[0]') AS nvarchar(1)))
UPDATE [JsonEntitiesAllTypes] SET [Reference] = JSON_MODIFY([Reference], 'strict $.TestCharacter', JSON_VALUE(@p0, '$[0]'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR :)

I noticed that we we send a single-element JSON array wrapping the value, and then use JSON_VALUE server-side to unwrap the value. What's the reason for having to do this, i.e. why not just send the value directly and just do JSON_MODIFY([Reference], 'strict $.TestCharacter', @p0)? The examples for JSON_VALUE just seem to show the simple, direct way...

If we did that, wouldn't we be able to just get rid of the CAST around the JSON_VALUE? I'm assuming the cast is needed because JSON_VALUE always returns nvarchar (but we need e.g. an int). But if we just embedded the value directly, it would be typed correctly and could just go directly into the document?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When passing values directly in parameter I hit issues with some data types (DateTime, Guid). e.g. if stored directly as parameter DateTime would be stored as "1\/1\/3000 12:34:56 PM" (and that wouldn't round trip), whereas what we want is "3000-01-01T12:34:56". By doing the array trick we always get values in a form that is appropriate to store as json for a given data type. Perhaps we could do special casing and simplify for types that work (which is the majority). Or better yet, when/if we have dedicated type mapping for json, we would always be able to render the parameter values correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filed #30410 to track this

WHERE [Id] = @p1;
""",
//
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to see if this can be enforced e.g. with .editorconfig

Suggested change
"""
"""

WHERE [Id] = @p1;
""",
//
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
"""

@ghost ghost merged commit 590d63c into main Mar 2, 2023
@ghost ghost deleted the fix30330 branch March 2, 2023 09:50
@roji
Copy link
Member

roji commented Mar 2, 2023

(@maumar just a ping to make sure you saw the comments above)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Json: updating property with conversion from string to other type fails on sql server
2 participants