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

Fix incorrect result of sql server tinyint #11274

Conversation

tangjiangling
Copy link
Member

@tangjiangling tangjiangling commented Mar 2, 2022

Description

Is this change a fix, improvement, new feature, refactoring, or other?

Fix the correctness of query results.

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

SQL Server connector.

How would you describe this change to a non-technical end user or system administrator?

Fix incorrect result of SQL Server TINYINT.

Related issues, pull requests, and links

Fixes #11209

Documentation

(x) Sufficient documentation is included in this PR.

Release notes

(x) Release notes entries required with the following suggested text:

# SQL Server
* Fix incorrect results when querying SQL Server ``tinyint`` columns by mapping them to Trino ``smallint``. ({issue}`11209`)

@cla-bot cla-bot bot added the cla-signed label Mar 2, 2022
@tangjiangling tangjiangling requested review from ebyhr and findepi March 2, 2022 09:13
@tangjiangling tangjiangling force-pushed the fix-incorrect-result-of-SqlServer-TINYINT branch from 359a12a to fba55aa Compare March 2, 2022 09:14
@findepi findepi requested review from hashhar and removed request for findepi March 2, 2022 09:18
@hashhar
Copy link
Member

hashhar commented Mar 2, 2022

docs need to be updated in sqlserver.rst type mapping table

@tangjiangling
Copy link
Member Author

tangjiangling commented Mar 2, 2022

I found that there are some other type mappings not covered by the SQL Server documentation (e.g. bit, decimal, tinyint, etc.), so I will only add tinyint related documentation in this PR, and I will file an issue to track the remaining parts.

@tangjiangling tangjiangling force-pushed the fix-incorrect-result-of-SqlServer-TINYINT branch from fba55aa to e73a4eb Compare March 2, 2022 12:54
@ebyhr ebyhr removed their request for review March 2, 2022 13:02
@tangjiangling tangjiangling force-pushed the fix-incorrect-result-of-SqlServer-TINYINT branch from e73a4eb to 62dfd53 Compare March 2, 2022 13:37
Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

LGTM.

Thanks a lot @tangjiangling.

@github-actions github-actions bot added the docs label Mar 2, 2022
@hashhar
Copy link
Member

hashhar commented Mar 2, 2022

@tangjiangling CI is failing. You'll also need to adjust io.trino.tests.product.sqlserver.TestSelect.testAllDatatypes it seems.

@tangjiangling
Copy link
Member Author

Got it, I'll take a look.

In the original implementation, we mapped SQL Server tinyint to Trino
TINYINT, but there is a difference in the range they supported:

- Trino TINYINT supports a range of [-128, 127]
- SQL Server tinyint supports a range of [0, 255]

So we can't read or write values in the range [128, 255], so we map SQL
Server tinyint to Trino SMALLINT in this commit.

Although we are now extending the range of SQL Server tinyint in Trino,
we don't have to worry about Trino writing values that are not in the
range [0, 255] to SQL Server, because SQL Server already guarantees this
for us and this behavior is verified by the
`BaseSqlServerTypeMapping#testUnsupportedTinyint` test.
@tangjiangling tangjiangling force-pushed the fix-incorrect-result-of-SqlServer-TINYINT branch from 62dfd53 to 95d2e8e Compare March 2, 2022 18:58
@tangjiangling
Copy link
Member Author

Updated and successfully ran SQL Server PTs locally.

@hashhar hashhar merged commit 4b20ba1 into trinodb:master Mar 3, 2022
@github-actions github-actions bot added this to the 373 milestone Mar 3, 2022
@tangjiangling tangjiangling deleted the fix-incorrect-result-of-SqlServer-TINYINT branch March 3, 2022 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

SqlServer TINYINT incorrect results
2 participants