Add Half type support for SQLite (#30931)#37481
Add Half type support for SQLite (#30931)#37481kimjaejung96 wants to merge 3 commits intodotnet:mainfrom
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.
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.
Either add GetHalf, or use GetDouble here to avoid extra conversions.
|
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.) |
|
|
||
| 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.
FLOAT16 seems inconsistent with the other floating-point types. I'd go with just HALF.
There was a problem hiding this comment.
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.
Thx !
Updated SqliteDatabaseModelFactory to drop FLOAT16 and keep only HALF as the explicit type hint (per your suggestion).
There was a problem hiding this comment.
Hi. @roji All checks are green and the PR has an approving review. Could you check when you have a moment? Thanks!
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