You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/12/22 10:07:38 UTC

[GitHub] [ignite] ptupitsyn commented on a change in pull request #8568: IGNITE-12824: Allows to work with non UTC dates for .Net Core applications

ptupitsyn commented on a change in pull request #8568:
URL: https://github.com/apache/ignite/pull/8568#discussion_r547177545



##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs
##########
@@ -258,8 +255,16 @@ public static bool TryReadSystemType<T>(byte typeId, BinaryReader ctx, out T res
 
             if (handler == null)
             {
-                res = default(T);
-                return false;
+                if (typeId == BinaryTypeId.Timestamp)
+                {
+                    // Date.
+                    handler = new BinarySystemReader<DateTime?>(stream => BinaryUtils.ReadTimestamp(stream, ctx.Marshaller.DateTimeConverter));

Review comment:
       Avoid object allocation and call `ReadTimestamp` directly:
   ```
   res = TypeCaster<T>.Cast(BinaryUtils.ReadTimestamp(ctx.Stream, ctx.Marshaller.DateTimeConverter));
   return true;
   ```

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Binary
+{
+    using System;
+
+    /// <summary>
+    /// Converter for DateTime objects.
+    /// </summary>
+    public interface IDateTimeConverter
+    {
+        /// <summary>Convert date to Java ticks.</summary>

Review comment:
       `Convert` -> `Converts`, here and below

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Binary
+{
+    using System;
+
+    /// <summary>
+    /// Converter for DateTime objects.
+    /// </summary>
+    public interface IDateTimeConverter

Review comment:
       Since we decided to operate on Java-specific Timestamp format here, I think a better name would be `ITimestampConverter`. It is also consistent with `WriteTimestamp` / `ReadTimestamp` methods.

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs
##########
@@ -136,6 +137,11 @@ public BinaryConfiguration(params Type[] binaryTypes)
         /// </summary>
         public IBinarySerializer Serializer { get; set; }
 
+        /// <summary>
+        /// Default date time converter.
+        /// </summary>
+        public IDateTimeConverter DateTimeConverter { get; set; }

Review comment:
       See below - let's rename to `ITimestampConverter TimestampConverter`

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Binary
+{
+    using System;
+
+    /// <summary>
+    /// Converter for DateTime objects.

Review comment:
       `Converts <see cref="DateTime"/> values to Java Timestamp and back.`

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs
##########
@@ -136,6 +137,11 @@ public BinaryConfiguration(params Type[] binaryTypes)
         /// </summary>
         public IBinarySerializer Serializer { get; set; }
 
+        /// <summary>
+        /// Default date time converter.
+        /// </summary>

Review comment:
       Also please update the doc for `ForceTimestamp` below like this:
   ```
   Only UTC values are supported in Timestamp format. Other values will cause an exception on write, unless <see cref="TimestampConverter"/> is provided.
   ```

##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs
##########
@@ -136,6 +137,11 @@ public BinaryConfiguration(params Type[] binaryTypes)
         /// </summary>
         public IBinarySerializer Serializer { get; set; }
 
+        /// <summary>
+        /// Default date time converter.
+        /// </summary>

Review comment:
       ```
           /// <summary>
           /// Gets or sets a converter between <see cref="DateTime"/> and Java Timestamp.
           /// Called from <see cref="IBinaryWriter.WriteTimestamp"/>, <see cref="IBinaryWriter.WriteTimestampArray"/>,
           /// <see cref="IBinaryReader.ReadTimestamp"/>, <see cref="IBinaryReader.ReadTimestampArray"/>.
           /// <para />
           /// See also <see cref="ForceTimestamp"/>.
           /// </summary>
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org