Repository: ignite Updated Branches: refs/heads/ignite-2.0 1f743465d -> 6090ebdfc
IGNITE-4413 .NET: Fix DateTime argument handling in SqlQuery This closes #1341 # Conflicts: # modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/83d961cf Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/83d961cf Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/83d961cf Branch: refs/heads/ignite-2.0 Commit: 83d961cff88cf2ead0bbc4ded3285f4faf9157fc Parents: 8dd4ada Author: Pavel Tupitsyn <[email protected]> Authored: Mon Dec 12 17:52:22 2016 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Mon Dec 12 18:23:17 2016 +0300 ---------------------------------------------------------------------- .../Query/CacheQueriesCodeConfigurationTest.cs | 24 ++++++++++++++-- .../Cache/Query/CacheQueriesTest.cs | 8 ++++++ .../Apache.Ignite.Core/Cache/Query/QueryBase.cs | 15 ++++++++-- .../Apache.Ignite.Core/Impl/Cache/CacheImpl.cs | 29 +------------------- 4 files changed, 43 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/83d961cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs index d5f98ac..92e2891 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs @@ -52,7 +52,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query Fields = new[] { new QueryField("Name", typeof (string)), - new QueryField("Age", typeof (int)) + new QueryField("Age", typeof (int)), + new QueryField("Birthday", typeof(DateTime)), }, Indexes = new[] { @@ -71,7 +72,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query cache[1] = new QueryPerson("Arnold", 10); cache[2] = new QueryPerson("John", 20); - using (var cursor = cache.Query(new SqlQuery(typeof (QueryPerson), "age > 10"))) + using (var cursor = cache.Query(new SqlQuery(typeof (QueryPerson), "age > ? and birthday < ?", + 10, DateTime.UtcNow))) { Assert.AreEqual(2, cursor.GetAll().Single().Key); } @@ -145,7 +147,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Query cache[2] = new AttributeQueryPerson("John", 20); - using (var cursor = cache.Query(new SqlQuery(typeof(AttributeQueryPerson), "age > ?", 10))) + using (var cursor = cache.Query(new SqlQuery(typeof(AttributeQueryPerson), + "age > ? and age < ? and birthday > ? and birthday < ?", 10, 30, + DateTime.UtcNow.AddYears(-21), DateTime.UtcNow.AddYears(-19)))) { Assert.AreEqual(2, cursor.GetAll().Single().Key); } @@ -186,6 +190,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query { Name = name; Age = age; + Salary = age; + Birthday = DateTime.UtcNow.AddYears(-age); } /// <summary> @@ -214,6 +220,18 @@ namespace Apache.Ignite.Core.Tests.Cache.Query /// </value> [QuerySqlField] public AttributeQueryAddress Address { get; set; } + + /// <summary> + /// Gets or sets the salary. + /// </summary> + [QuerySqlField] + public decimal? Salary { get; set; } + + /// <summary> + /// Gets or sets the birthday. + /// </summary> + [QuerySqlField] + public DateTime Birthday { get; set; } } /// <summary> http://git-wip-us.apache.org/repos/asf/ignite/blob/83d961cf/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs index a8ffe13..af79db9 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs @@ -15,6 +15,7 @@ * limitations under the License. */ +// ReSharper disable UnusedAutoPropertyAccessor.Global namespace Apache.Ignite.Core.Tests.Cache.Query { using System; @@ -758,6 +759,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query { Name = name; Age = age; + Birthday = DateTime.UtcNow.AddYears(-age); } /// <summary> @@ -769,6 +771,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Query /// Age. /// </summary> public int Age { get; set; } + + /// <summary> + /// Gets or sets the birthday. + /// </summary> + [QuerySqlField] // Enforce Timestamp serialization + public DateTime Birthday { get; set; } } /// <summary> http://git-wip-us.apache.org/repos/asf/ignite/blob/83d961cf/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/QueryBase.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/QueryBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/QueryBase.cs index cf1f637..d992845 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/QueryBase.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/QueryBase.cs @@ -17,6 +17,8 @@ namespace Apache.Ignite.Core.Cache.Query { + using System; + using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Cache; @@ -66,7 +68,7 @@ namespace Apache.Ignite.Core.Cache.Query /// </summary> /// <param name="writer">Writer.</param> /// <param name="args">Arguments.</param> - internal static void WriteQueryArgs(BinaryWriter writer, object[] args) + internal static void WriteQueryArgs(IBinaryRawWriter writer, object[] args) { if (args == null) writer.WriteInt(0); @@ -75,7 +77,16 @@ namespace Apache.Ignite.Core.Cache.Query writer.WriteInt(args.Length); foreach (var arg in args) - writer.WriteObject(arg); + { + // Write DateTime as TimeStamp always, otherwise it does not make sense + // Wrapped DateTime comparison does not work in SQL + var dt = arg as DateTime?; // Works with DateTime also + + if (dt != null) + writer.WriteTimestamp(dt); + else + writer.WriteObject(arg); + } } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/83d961cf/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs index 359611d..57e70e1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs @@ -991,7 +991,7 @@ namespace Apache.Ignite.Core.Impl.Cache writer.WriteString(qry.Sql); writer.WriteInt(qry.PageSize); - WriteQueryArgs(writer, qry.Arguments); + QueryBase.WriteQueryArgs(writer, qry.Arguments); writer.WriteBoolean(qry.EnableDistributedJoins); writer.WriteBoolean(qry.EnforceJoinOrder); @@ -1010,33 +1010,6 @@ namespace Apache.Ignite.Core.Impl.Cache return new QueryCursor<TK, TV>(cursor, Marshaller, _flagKeepBinary); } - /// <summary> - /// Write query arguments. - /// </summary> - /// <param name="writer">Writer.</param> - /// <param name="args">Arguments.</param> - private static void WriteQueryArgs(BinaryWriter writer, object[] args) - { - if (args == null) - writer.WriteInt(0); - else - { - writer.WriteInt(args.Length); - - foreach (var arg in args) - { - // Write DateTime as TimeStamp always, otherwise it does not make sense - // Wrapped DateTime comparison does not work in SQL - var dt = arg as DateTime?; // Works with DateTime also - - if (dt != null) - writer.WriteTimestamp(dt); - else - writer.WriteObject(arg); - } - } - } - /** <inheritdoc /> */ public IContinuousQueryHandle QueryContinuous(ContinuousQuery<TK, TV> qry) {
