ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pavel Tupitsyn <ptupit...@apache.org>
Subject Re: Dymanically add QueryField on Cache Entity and perform DateTime filter.
Date Fri, 07 Jul 2017 13:26:21 GMT
Addition:

In upcoming 2.1 version there is a BinaryReflectiveSerializer.
ForceTimestamp property, which makes it write any DateTime as a Timestamp.
So instead of a custom serializer, you can do this:

BinaryConfiguration = new BinaryConfiguration
                {
                        TypeConfigurations = new[] { new
BinaryTypeConfiguration(typeof(ABC)) {
Serializer = new BinaryReflectiveSerializer {ForceTimestamp = true} }}
                }

On Wed, Jul 5, 2017 at 11:44 AM, ptupitsyn <ptupitsyn@apache.org> wrote:

> Hi,
>
> Please properly subscribe to the mailing list so that the community can
> receive email notifications for your messages. To subscribe, send empty
> email to user-subscribe@ignite.apache.org and follow simple instructions
> in
> the reply.
>
> I have reproduced the problem, it is caused by the fact that DateTime is
> serialized in .NET-specific format by default, and this does not work in
> SQL, see "DateTime and SQL" section:
> https://apacheignite-net.readme.io/docs/sql-queries#
> section-java-type-name-mapping
>
> To enforce SQL-compatible TimeStamp format:
> 1) Mark the field with [QuerySqlField]. Looks like this is not an option
> for
> you, though, since reflection is used
>
> 2) Implement IBinarizable:
>
> public class ABC : IBinarizable
> {
>         public int Id { get; set; }
>         public string Name { get; set; }
>         public DateTime StartTime { get; set; }
>
>         public void WriteBinary(IBinaryWriter writer)
>         {
>                 writer.WriteInt("Id", Id);
>                 writer.WriteString("Name", Name);
>                 writer.WriteTimestamp("StartTime", StartTime);
>         }
>
>         public void ReadBinary(IBinaryReader reader)
>         {
>                 Id = reader.ReadInt("Id");
>                 Name = reader.ReadString("Name");
>                 StartTime = reader.ReadTimestamp("
> StartTime").GetValueOrDefault();
>         }
> }
>
> 3) Implement IBinarySerializer:
>
> public class AbcSerializer : IBinarySerializer
> {
>         public void WriteBinary(object o, IBinaryWriter writer)
>         {
>                 var abc = (ABC)o;
>
>                 writer.WriteInt("Id", abc.Id);
>                 writer.WriteString("Name", abc.Name);
>                 writer.WriteTimestamp("StartTime", abc.StartTime);
>         }
>
>         public void ReadBinary(object o, IBinaryReader reader)
>         {
>                 var abc = (ABC)o;
>
>                 abc.Id = reader.ReadInt("Id");
>                 abc.Name = reader.ReadString("Name");
>                 abc.StartTime = reader.ReadTimestamp("
> StartTime").GetValueOrDefault();
>         }
> }
>
> and register it in config:
>                 BinaryConfiguration = new BinaryConfiguration
>                 {
>                         TypeConfigurations = new[] { new
> BinaryTypeConfiguration(typeof(ABC)) {
> Serializer = new AbcSerializer() }}
>                 }
>
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Dymanically-add-QueryField-on-
> Cache-Entity-and-perform-DateTime-filter-tp14318p14319.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Mime
View raw message