Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id D8AF8180630 for ; Tue, 2 Jan 2018 11:31:26 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C8AD1160C26; Tue, 2 Jan 2018 10:31:26 +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 C0E52160C1B for ; Tue, 2 Jan 2018 11:31:25 +0100 (CET) Received: (qmail 18253 invoked by uid 500); 2 Jan 2018 10:31:24 -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 18243 invoked by uid 99); 2 Jan 2018 10:31:24 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jan 2018 10:31:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 233DE18077C for ; Tue, 2 Jan 2018 10:31:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.173 X-Spam-Level: ** X-Spam-Status: No, score=2.173 tagged_above=-999 required=6.31 tests=[DKIM_ADSP_CUSTOM_MED=0.001, KAM_SHORT=0.001, NML_ADSP_CUSTOM_MED=1.2, SPF_HELO_PASS=-0.001, SPF_SOFTFAIL=0.972] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id UjIgMCYp_2-v for ; Tue, 2 Jan 2018 10:31:21 +0000 (UTC) Received: from n6.nabble.com (n6.nabble.com [162.255.23.37]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id B1F6E5F3E1 for ; Tue, 2 Jan 2018 10:31:20 +0000 (UTC) Received: from n6.nabble.com (localhost [127.0.0.1]) by n6.nabble.com (Postfix) with ESMTP id 2AC203D6A239 for ; Tue, 2 Jan 2018 03:31:15 -0700 (MST) Date: Tue, 2 Jan 2018 03:31:15 -0700 (MST) From: kotamrajuyashasvi To: user@ignite.apache.org Message-ID: <1514889075172-0.post@n6.nabble.com> Subject: Date type field in select query is returning wrong value when Time zones of Ignite Client and Server are different MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit archived-at: Tue, 02 Jan 2018 10:31:27 -0000 Hi In my sample Demo Ignite java program, Initially a Person entry is inserted from the Ignite Client into the Ignite cache. The Person Pojo has a "dob" field which is of java.util.Date type. Now when the Person Object is obtained using _val in query, the getTime() on dob field of Person Object gives same milliseconds that was used during the cache insert/put . But when querying for dob field in select query it returns a java.sql.Timestamp Object in QueryCursor and when getTime() on that Timestamp is called it returns different milliseconds value. This milliseconds value obtained from query will be used in other queries hence its crucial that correct milliseconds value is obtained in query result. This behavior is observed when Ignite Client and Server are in different TimeZones. The milliseconds value in the Date Object is independent of Timezone. Following is a sample reproducer: ****************** DemoProgram ************* package com.IgniteDemo; import java.util.*; import javax.cache.Cache.Entry; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; import org.apache.ignite.Ignition; import org.apache.ignite.cache.query.QueryCursor; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.cache.query.SqlQuery; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; public class DemoMain { public static void main(String[] args){ System.setProperty("user.timezone", "EST");//to change timezone of the ignite client program String ConfigPath = "default-config.xml"; Ignite ignite = Ignition.start(ConfigPath); IgniteCache cache = ignite.cache("Person"); System.out.println("cache size "+cache.size()); long dob = 771465600000L; Person p1 = new Person(1,"yash",22,"124345","addr",new Date(dob)); cache.put(p1.getPK(),p1); System.out.println("cache size "+cache.size()); System.out.println("case 1: Obtaining dob from Person Object"); SqlFieldsQuery sql = new SqlFieldsQuery( "select _val from Person where dob = ?"); try (QueryCursor> cursor = cache.query(sql.setArgs(new Date(7714656001000L)))) { for (List row : cursor){ dob = (((Person)row.get(0)).getDob().getTime()); System.out.println(" getTime of dob from Person Object : " + dob); } } sql = new SqlFieldsQuery( "select name from Person where dob = ?"); try (QueryCursor> cursor = cache.query(sql.setArgs(new Date(dob)))) { for (List row : cursor){ System.out.println(" name of person in query result : " + row.get(0)); } } System.out.println("case 2: Obtaining dob from Select query field "); sql = new SqlFieldsQuery( "select dob from Person where dob = ?"); try (QueryCursor> cursor = cache.query(sql.setArgs(new Date(7714656001000L)))) { for (List row : cursor){ dob = (((Date)row.get(0)).getTime()); System.out.println(" Object Type of dob from select query result object : " + row.get(0).getClass().getName()); System.out.println(" getTime of dob from select query result field object : " + dob); } } sql = new SqlFieldsQuery( "select name from Person where dob = ?"); try (QueryCursor> cursor = cache.query(sql.setArgs(new Date(dob)))) { for (List row : cursor){ System.out.println(" name of person in query result : " + row.get(0)); } } } *** OUTPUT *** cache size 0 cache size 1 case 1: Obtaining dob from Person Object getTime of dob from Person Object : 771465600000 name of person in query result : yash case 2: Obtaining dob from Select query field Object Type of dob from select query result object : java.sql.Timestamp getTime of dob from select query result field object : 771503400000 *********** Person.java ********************* package com.IgniteDemo; import java.util.Date; import org.apache.ignite.cache.query.annotations.QuerySqlField; public class Person { @QuerySqlField(index = false) private int person_no; @QuerySqlField(index = false) private String name; @QuerySqlField(index = false) private Integer age=null; @QuerySqlField(index = false) private String phno; @QuerySqlField(index = false) private String address; @QuerySqlField(index = false) public String tid="t1"; @QuerySqlField(index = false) public Date dob; public Date getDob() { return dob; } public void setDob(Date dob) { this.dob = dob; } public Person(){ } public int getPerson_no() { return person_no; } public void setPerson_no(int person_no) { this.person_no = person_no; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getPhno() { return phno; } public void setPhno(String phno) { this.phno = phno; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public PersonPK getPK(){ return new PersonPK(person_no,phno); } public Person(int person_no, String name, Integer age, String phno, String address, Date dob) { this.person_no = person_no; this.name = name; this.age = age; this.phno = phno; this.address = address; this.dob = dob; } } ******************************************************************************* ************* PersonPK.java *************** package com.IgniteDemo; import java.util.Arrays; public class PersonPK { private String phno; private int person_no; public PersonPK(){ } public PersonPK(int person_no,String phno){ this.person_no = person_no; this.phno = phno; } public int getPerson_no() { return person_no; } public void setPerson_no(int person_no) { this.person_no = person_no; } public String getPhno() { return phno; } public void setPhno(String phno) { this.phno = phno; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + person_no; result = prime * result + ((phno == null) ? 0 : phno.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; PersonPK other = (PersonPK) obj; if (person_no != other.person_no) return false; if (phno == null) { if (other.phno != null) return false; } else if (!phno.equals(other.phno)) return false; return true; } @Override public String toString() { return "PersonPK [phno=" + phno + ", person_no=" + person_no + "]"; } } *********************************************************************************** **************** default-config.xml **************************** com.IgniteDemo.PersonPK com.IgniteDemo.Person 127.0.0.1:47500..47509 ************************************************************************************* *********** persistence-settings.xml *********** *************************************************** ********** connection-settings.xml ************************************* 10.1.2.3 ********************************************************* -- Sent from: http://apache-ignite-users.70518.x6.nabble.com/