-
Notifications
You must be signed in to change notification settings - Fork 5
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 generic type validation to support datetimes and non-ASCII strings. #291
Conversation
And also document which type is compatible with which `DataType`.
…ing. If the generic type is string, we check ourselves that the `DataType` is a string one. This ensures the exception thrown is `ArgumentException` instead of `TileDBException`. The exception message also is more descriptive.
019ff81
to
5ccc03f
Compare
The failing examples in #258 succeed after this. |
Is there any way that external users could be relying on this behavior? |
Besides the validation we do, one other use case I could find for this method is to dynamically construct an array of that type using reflection, as part of processing TileDB arrays of unknown schemata, but there are better ways of doing this. Another thing we could do is make an internal edition of this method with the updated behavior and deprecate the public |
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.
Another thing we could do is make an internal edition of this method with the updated behavior and deprecate the public TypeToDataType and DataTypeToType methods, keeping the existing behavior in the meantime.
+1, let's do it that way, thanks 💪
@@ -55,5 +56,39 @@ public static void ThrowIfManagedType<T>() | |||
ThrowHelpers.ThrowManagedType(); | |||
} | |||
} | |||
|
|||
/// <summary> | |||
/// Returns whether values of type <typeparamref name="T"/> can be stored or |
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.
The obsoletions in question have not yet shipped.
Thanks |
SC-24612
The C# API's rules around type validation in its generic methods have some defects that prevent datetime types and non-ASCII strings from being used. This PR improves the type validation to fix these cases.
Summary of changes
Type
to a TileDBDataType
and compare them, we do the opposite. This happens because (with few exceptions), the mapping between .NET types and TileDB data types is one-to-many, and so by "narrowing down" we can validate that datetime data types match withlong
, whilelong
maps toDataType.Int64
.ErrorHandling.CheckDataType
. It accepts a generic type parameter and aDataType
regular parameter, and fails if they are incompatible.DataType.Boolean
andStringUtf16
. Besidesbyte
andushort
, they can also match withbool
andchar
(in .NET it's 2 bytes long) respectively.StringUtf32
andSystem.Text.Rune
, but the Core must validate that UTF-32 strings contain valid Unicode codepoints (if it already does, please let me know).EnumUtil.DataTypeToType
method mapped all stringDataType
s tosbyte
, which is an obviously wrong behavior, and inconsistent with what the C++ API does. This PR changes it to map ASCII and UTF-8 strings tobyte
, UTF-16 strings toushort
, and UTF-32 strings touint
.DataType
s with multiple valid types (likeStringUtf16
andBoolean
),DataTypeToType
returns the matching numeric type.ArgumentException
which is more appropriate thanInvalidOperationException
. Not commonly expected to hit, but worth mentioning.