-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add Half type support for SQLite (#30931) #37481
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
base: main
Are you sure you want to change the base?
Add Half type support for SQLite (#30931) #37481
Conversation
- Add Half support in SqliteValueReader.GetFieldValue<T> - Add Half binding in SqliteValueBinder - Add SqliteHalfTypeMapping for EF Core SQLite provider - SQLite-specific implementation only (per maintainer feedback) - Use REAL store type, DbType is null (no DbType.Half exists) Fixes dotnet#30931
bricelam
left a comment
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.
Looking good to me.
You should also add logic for Half to SqliteDatabaseModelFactory.
| #if NET6_0_OR_GREATER | ||
| if (typeof(T) == typeof(Half)) | ||
| { | ||
| return (T)(object)(Half)GetFloat(ordinal); |
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.
Either add GetHalf, or use GetDouble here to avoid extra conversions.
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.
(below too)
|
For reference, the previous attempt was #35328 |
- Use GetDouble instead of GetFloat for Half reading (avoids extra conversion) - Add Half scaffolding support to SqliteDatabaseModelFactory - Add HALF, FLOAT16 type hints for Half CLR type mapping - Add Half range validation in REAL value type handling - Add Half default value parsing
|
Thanks again @bricelam — I pushed updates addressing the feedback:
(Also, thanks to AndriySvyryd for pointing me to the previous attempt.) |
bricelam
left a comment
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.
LGTM
|
|
||
| private static readonly HashSet<string> _floatTypes = new(StringComparer.OrdinalIgnoreCase) { "SINGLE" }; | ||
|
|
||
| private static readonly HashSet<string> _halfTypes = new(StringComparer.OrdinalIgnoreCase) { "HALF", "FLOAT16" }; |
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.
FLOAT16 seems inconsistent with the other floating-point types. I'd go with just HALF.
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.
BTW, the philosophy behind these names was to use names specified in the SQL standard, if available, or at least one generic/.NET name to allow some way of preserving the .NET type in the schema. But, the default EF Core mapping will always adhere to the STRICT rules.
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.
Thx !
Updated SqliteDatabaseModelFactory to drop FLOAT16 and keep only HALF as the explicit type hint (per your suggestion).
249ae47 to
6b86657
Compare
Per reviewer feedback, keep only HALF for consistency with other floating-point type hints (SINGLE for float).
Summary
Add Half (16-bit floating point) type support for Microsoft.Data.Sqlite and EF Core SQLite provider.
Fixes #30931
Changes
Microsoft.Data.Sqlite (ADO.NET layer)
GetFieldValue<Half>supportEF Core SQLite Provider
Tests
Design Notes
Based on #35328 feedback:
EFCore.Relational(no HalfTypeMapping in common layer)DbType-System.Data.DbTypehas no Half value, so DbType is null#if NET6_0_OR_GREATERfornetstandard2.0compatibility