ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-5442 .NET: Fix LINQ conditional statement for nullables
Date Tue, 20 Jun 2017 09:48:37 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 5560b12c0 -> 19a78a9d9


IGNITE-5442 .NET: Fix LINQ conditional statement for nullables

This closes #2144


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/19a78a9d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/19a78a9d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/19a78a9d

Branch: refs/heads/master
Commit: 19a78a9d90084e72c194a8cc4017bbdaca0dc761
Parents: 5560b12
Author: Sergey Stronchinskiy <gurustronpublic@gmail.com>
Authored: Tue Jun 20 12:48:28 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Tue Jun 20 12:48:28 2017 +0300

----------------------------------------------------------------------
 .../Cache/Query/CacheLinqTest.cs                | 57 ++++++++++++++++++--
 .../dotnet/Apache.Ignite.Linq/Impl/SqlTypes.cs  | 17 ++++--
 2 files changed, 66 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/19a78a9d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
index 9c38871..7874681 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
@@ -381,11 +381,26 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         [Test]
         public void TestConditions()
         {
-            var persons = GetPersonCache().AsCacheQueryable();
-
-            var res = persons.Select(x => new {Foo = x.Key%2 == 0 ? "even" : "odd", x.Value}).ToArray();
-            Assert.AreEqual("even", res[0].Foo);
-            Assert.AreEqual("odd", res[1].Foo);
+            TestConditional("even", "odd");
+            TestConditional(new Address { Zip = 99999 }, new Address { Zip = 7777777 }, (a1,
a2) => a1.Zip == a2.Zip);
+            TestConditional(new RoleKey(int.MaxValue, long.MinValue), new RoleKey(int.MinValue,
long.MaxValue));
+            TestConditionalWithNullableStructs<int>();
+            TestConditionalWithNullableStructs<uint>();
+            TestConditionalWithNullableStructs<Guid>();
+            TestConditionalWithNullableStructs<byte>();
+            TestConditionalWithNullableStructs<sbyte>();
+            TestConditionalWithNullableStructs<short>();
+            TestConditionalWithNullableStructs<ushort>();
+            TestConditionalWithNullableStructs<bool>();
+            TestConditionalWithNullableStructs<long>();
+            TestConditionalWithNullableStructs<ulong>();
+            TestConditionalWithNullableStructs<double>();
+            TestConditionalWithNullableStructs<float>();
+            TestConditionalWithNullableStructs<decimal>();
+            TestConditionalWithNullableStructs<DateTime>(DateTime.UtcNow);
+
+            var charException = Assert.Throws<NotSupportedException>(() => TestConditionalWithNullableStructs<char>());
+            Assert.AreEqual("Type is not supported for SQL mapping: System.Char", charException.Message);
 
             var roles = GetRoleCache().AsCacheQueryable();
             CheckFunc(x => x.Value.Name ?? "def_name", roles);
@@ -1826,6 +1841,38 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             CollectionAssert.AreEqual(expected, actual, new NumericComparer());
         }
 
+        /// <summary>
+        /// Tests conditinal statement
+        /// </summary>
+        private void TestConditional<T>(T even , T odd, Func<T,T,bool> comparer
= null)
+        {
+            var persons = GetPersonCache().AsCacheQueryable();
+
+            var res = persons
+                .Select(x => new {Foo = x.Key % 2 == 0 ? even : odd, x.Value})
+                .ToArray();
+
+            if (comparer != null)
+            {
+                Assert.IsTrue(comparer(even, res[0].Foo));
+                Assert.IsTrue(comparer(odd, res[1].Foo));
+            }
+            else
+            {
+                Assert.AreEqual(even, res[0].Foo);
+                Assert.AreEqual(odd, res[1].Foo);
+            }
+        }
+
+        /// <summary>
+        /// Tests conditinal statement for structs with default and null values
+        /// </summary>
+        private void TestConditionalWithNullableStructs<T>(T? defaultFalue = null)
where T : struct
+        {
+            var def = defaultFalue ?? default(T);
+            TestConditional(def, (T?) null);
+        }
+
         public interface IPerson
         {
             int Age { get; set; }

http://git-wip-us.apache.org/repos/asf/ignite/blob/19a78a9d/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/SqlTypes.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/SqlTypes.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/SqlTypes.cs
index abaac21..22fc53f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/SqlTypes.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/SqlTypes.cs
@@ -33,7 +33,6 @@ namespace Apache.Ignite.Linq.Impl
             {typeof (sbyte), "tinyint"},
             {typeof (short), "smallint"},
             {typeof (ushort), "int"},
-            {typeof (char), "nvarchar(1)"},
             {typeof (int), "int"},
             {typeof (uint), "bigint"},
             {typeof (long), "bigint"},
@@ -44,9 +43,14 @@ namespace Apache.Ignite.Linq.Impl
             {typeof (decimal), "decimal"},
             {typeof (Guid), "uuid"},
             {typeof (DateTime), "timestamp"},
-            {typeof (DateTime?), "timestamp"},
         };
 
+        /** */
+        private static readonly HashSet<Type> NotSupportedTypes = new HashSet<Type>(new
[]
+        {
+            typeof(char)
+        }); 
+
         /// <summary>
         /// Gets the corresponding Java type name.
         /// </summary>
@@ -55,9 +59,16 @@ namespace Apache.Ignite.Linq.Impl
             if (type == null)
                 return null;
 
+            type = Nullable.GetUnderlyingType(type) ?? type;
+
+            if (NotSupportedTypes.Contains(type))
+            {
+                throw new NotSupportedException("Type is not supported for SQL mapping: "
+ type);
+            }
+
             string res;
 
-            return !NetToSql.TryGetValue(type, out res) ? null : res;
+            return NetToSql.TryGetValue(type, out res) ? res : null;
         }
     }
 }


Mime
View raw message