Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B074A200CBE for ; Fri, 7 Jul 2017 15:26:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AF0451690EE; Fri, 7 Jul 2017 13:26:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CEE451690ED for ; Fri, 7 Jul 2017 15:26:54 +0200 (CEST) Received: (qmail 23395 invoked by uid 500); 7 Jul 2017 13:26:53 -0000 Mailing-List: contact user-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@ignite.apache.org Delivered-To: mailing list user@ignite.apache.org Received: (qmail 23386 invoked by uid 99); 7 Jul 2017 13:26:53 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Jul 2017 13:26:53 +0000 Received: from mail-qk0-f179.google.com (mail-qk0-f179.google.com [209.85.220.179]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 54B571A0029 for ; Fri, 7 Jul 2017 13:26:52 +0000 (UTC) Received: by mail-qk0-f179.google.com with SMTP id p21so27048502qke.3 for ; Fri, 07 Jul 2017 06:26:52 -0700 (PDT) X-Gm-Message-State: AIVw112SMMjUDG6d5q1rE7+L3as0FfTm5NpWoochIhinZ+T3RjhjXUOE GiRYtWrwIoNZwVcDyCQEOJncVvWJx9rT X-Received: by 10.55.174.66 with SMTP id x63mr18778794qke.137.1499434011362; Fri, 07 Jul 2017 06:26:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.55.239 with HTTP; Fri, 7 Jul 2017 06:26:21 -0700 (PDT) In-Reply-To: <1499244246457-14319.post@n6.nabble.com> References: <1499235584875-14318.post@n6.nabble.com> <1499244246457-14319.post@n6.nabble.com> From: Pavel Tupitsyn Date: Fri, 7 Jul 2017 16:26:21 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Dymanically add QueryField on Cache Entity and perform DateTime filter. To: user@ignite.apache.org Content-Type: multipart/alternative; boundary="94eb2c0617009cb42b0553ba2f81" archived-at: Fri, 07 Jul 2017 13:26:55 -0000 --94eb2c0617009cb42b0553ba2f81 Content-Type: text/plain; charset="UTF-8" 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 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. > --94eb2c0617009cb42b0553ba2f81 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Addition:

In upcoming 2.1 version there= is a=C2=A0Binar= yReflectiveSerializer.Forc= eTimestamp=C2=A0property, which makes it write any DateTime as a Tim= estamp.
So instead of a custom serializer, you can do this:
=

BinaryConfiguration = =3D new BinaryConfiguration
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 TypeConfigurations =3D new[] { new BinaryTypeConfiguration(typeof(A= BC)) {
Serializer =3D new BinaryReflectiveSerializer {ForceTimestamp =3D true} }= }
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }

On Wed, Jul 5, 2017 at 11:44 AM, ptupitsyn &l= t;ptupitsyn@apach= e.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://apacheigni= te-net.readme.io/docs/sql-queries#section-java-type-name-mapping<= /a>

To enforce SQL-compatible TimeStamp format:
1) Mark the field with [QuerySqlField]. Looks like this is not an option fo= r
you, though, since reflection is used

2) Implement IBinarizable:

public class ABC : IBinarizable
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 public int Id { get; set; }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 public string Name { get; set; }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 public DateTime StartTime { get; set; }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 public void WriteBinary(IBinaryWriter writer) =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writer.WriteInt(&qu= ot;Id", Id);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writer.WriteString(= "Name", Name);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writer.WriteTimesta= mp("StartTime", StartTime);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 public void ReadBinary(IBinaryReader reader) =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Id =3D reader.ReadI= nt("Id");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Name =3D reader.Rea= dString("Name");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 StartTime =3D reade= r.ReadTimestamp("StartTime").GetValueOrDefault();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
}

3) Implement IBinarySerializer:

public class AbcSerializer : IBinarySerializer
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 public void WriteBinary(object o, IBinaryWriter= writer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 var abc =3D (ABC)o;=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writer.WriteInt(&qu= ot;Id", abc.Id);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writer.WriteString(= "Name", abc.Name);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writer.WriteTimesta= mp("StartTime", abc.StartTime);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 public void ReadBinary(object o, IBinaryReader = reader)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 var abc =3D (ABC)o;=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 abc.Id =3D reader.R= eadInt("Id");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 abc.Name =3D reader= .ReadString("Name");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 abc.StartTime =3D r= eader.ReadTimestamp("StartTime").GetValueOrDefault(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
}

and register it in config:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 BinaryConfiguration= =3D new BinaryConfiguration
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 TypeConfigurations =3D new[] { new BinaryTypeConfiguration(= typeof(ABC)) {
Serializer =3D new AbcSerializer() }}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }




--
View this message in context:
http://ap= ache-ignite-users.70518.x6.nabble.com/Dymanically-add-QueryField-= on-Cache-Entity-and-perform-DateTime-filter-tp14318p14319.ht= ml
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

--94eb2c0617009cb42b0553ba2f81--