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 48FF2200BB1 for ; Thu, 3 Nov 2016 15:39:25 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 47B25160B0B; Thu, 3 Nov 2016 14:39:25 +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 8D4F0160AFE for ; Thu, 3 Nov 2016 15:39:24 +0100 (CET) Received: (qmail 40766 invoked by uid 500); 3 Nov 2016 14:39:23 -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 40757 invoked by uid 99); 3 Nov 2016 14:39:23 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2016 14:39:23 +0000 Received: from mail-yb0-f181.google.com (mail-yb0-f181.google.com [209.85.213.181]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 2C46E1A0046 for ; Thu, 3 Nov 2016 14:39:23 +0000 (UTC) Received: by mail-yb0-f181.google.com with SMTP id f97so17685957ybi.1 for ; Thu, 03 Nov 2016 07:39:23 -0700 (PDT) X-Gm-Message-State: ABUngvdlR2HEn40C/ENERpNgsXwLzj5mXJ5SGUVlHlfuvEcAa+/EN5kueWGU1dzBrSksvySpSkKG6slQnyhwTA== X-Received: by 10.37.17.196 with SMTP id 187mr7256148ybr.56.1478183962476; Thu, 03 Nov 2016 07:39:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.171.134 with HTTP; Thu, 3 Nov 2016 07:39:22 -0700 (PDT) In-Reply-To: References: From: Andrey Gura Date: Thu, 3 Nov 2016 17:39:22 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Null column values - bug To: user@ignite.apache.org Content-Type: multipart/alternative; boundary=001a113e67feffaf010540668506 archived-at: Thu, 03 Nov 2016 14:39:25 -0000 --001a113e67feffaf010540668506 Content-Type: text/plain; charset=UTF-8 String.valuOf(null) return "null" string by contract. On Thu, Nov 3, 2016 at 5:33 PM, Anil wrote: > HI , > > null values are returned as "null" with ignite jdbc result set. > > private T getTypedValue(int colIdx, Class cls) throws SQLException > { > ensureNotClosed(); > ensureHasCurrentRow(); > > try { > T val = cls == String.class ? (T)String.valueOf(curr.get(colIdx > - 1)) : (T)curr.get(colIdx - 1); > > wasNull = val == null; > > return val; > } > catch (IndexOutOfBoundsException ignored) { > throw new SQLException("Invalid column index: " + colIdx); > } > catch (ClassCastException ignored) { > throw new SQLException("Value is an not instance of " + > cls.getName()); > } > } > > > if a column value is null (curr.get(colIdx - 1) return null but > String.valueOf( (curr.get(colIdx - 1) ) is not null it is "null". > > ArrayList obj = new ArrayList(); > obj.add(null); > System.out.println(null == (String)String.valueOf(obj.get(0))); > > above Sysout is false. > > Fix : > > Object colValue = curr.get(colIdx - 1); > > T val = cls == String.class ? (String) colValue : (T) colValue; > > or return (T) colValue > > > please let me know if you see any issues. thanks > > > --001a113e67feffaf010540668506 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
String.valuOf(null) return "null" string by cont= ract.

On= Thu, Nov 3, 2016 at 5:33 PM, Anil <anilklce@gmail.com> wro= te:
HI ,

<= div>null values are returned as "null" with ignite jdbc result se= t.

=C2=A0private <T> T getTypedVal= ue(int colIdx, Class<T> cls) throws SQLException {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 ensureNotClosed();
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 ensureHasCurrentRow();

=C2=A0 =C2=A0 =C2=A0 = =C2=A0 try {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 T val =3D = cls =3D=3D String.class ? (T)String.valueOf(curr.get(colIdx - 1)) : (T= )curr.get(colIdx - 1);

=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 wasNull =3D val =3D=3D null;

=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return val;
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 catch (IndexOutOfBoundsE= xception ignored) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 thr= ow new SQLException("Invalid column index: " + colIdx);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 catch = (ClassCastException ignored) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 throw new SQLException("Value is an not instance of " + c= ls.getName());
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2= =A0 }


if a column value is nu= ll (curr.get(colIdx - 1) return null but String.valueOf( (curr.get(colIdx -= 1) ) is not null it is "null".

ArrayLis= t<String> obj =3D new ArrayList<String>();
= =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 obj.add(null);
System.out.println(null =3D=3D (= String)String.valueOf(obj.get(0)));

above Sysout is false.=C2=A0

Fix :
Object colValue =3D curr.get(colIdx - 1);

T val =3D cls =3D=3D String.class ? (String) colValue : (T) colVal= ue;

or return (T) colValue


please let me know if you see any issues. thanks
=



--001a113e67feffaf010540668506--