Return-Path: Delivered-To: apmail-incubator-cassandra-user-archive@minotaur.apache.org Received: (qmail 34152 invoked from network); 15 Jun 2009 16:41:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Jun 2009 16:41:17 -0000 Received: (qmail 11722 invoked by uid 500); 15 Jun 2009 16:41:29 -0000 Delivered-To: apmail-incubator-cassandra-user-archive@incubator.apache.org Received: (qmail 11708 invoked by uid 500); 15 Jun 2009 16:41:29 -0000 Mailing-List: contact cassandra-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-user@incubator.apache.org Delivered-To: mailing list cassandra-user@incubator.apache.org Received: (qmail 11696 invoked by uid 99); 15 Jun 2009 16:41:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jun 2009 16:41:29 +0000 X-ASF-Spam-Status: No, hits=3.4 required=10.0 tests=HTML_MESSAGE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [74.125.92.149] (HELO qw-out-1920.google.com) (74.125.92.149) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jun 2009 16:41:19 +0000 Received: by qw-out-1920.google.com with SMTP id 9so2150640qwj.54 for ; Mon, 15 Jun 2009 09:40:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.84.209 with SMTP id k17mr1405060qcl.61.1245084058482; Mon, 15 Jun 2009 09:40:58 -0700 (PDT) In-Reply-To: References: <70cd74010906150926r76e4166araaed65b5341b4c88@mail.gmail.com> Date: Mon, 15 Jun 2009 12:40:58 -0400 Message-ID: <70cd74010906150940h168aefa2q52ad2bf7a5f4f819@mail.gmail.com> Subject: Re: Querying columns return strange characters From: Ivan Chang To: cassandra-user@incubator.apache.org Content-Type: multipart/alternative; boundary=0016364eef740577cc046c65b955 X-Virus-Checked: Checked by ClamAV on apache.org --0016364eef740577cc046c65b955 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thank you so much for the tip, it works! On Mon, Jun 15, 2009 at 12:34 PM, Jonathan Ellis wrote: > byte[].toString is not the inverse of String.getBytes; you need to use > new String(byte[]) for that. > > fyi, the characters you see are > > [: this is an array > B: of bytes > dcb03b: memory address > > this will let you recognize such output in the future :) > > -Jonathan > > On Mon, Jun 15, 2009 at 11:26 AM, Ivan Chang wrote: > > I modified some test cases in the Cassandra distribution. Specifically > in > > the unit test package I modified ServerTest.java, basically just tried to > > insert some columns and retrieve them. Here's part of the code: > > > > RowMutation rm = new RowMutation("Table1", "partner0"); > > ColumnFamily cf = new ColumnFamily("Standard1", "Standard"); > > long now = Calendar.getInstance().getTimeInMillis(); > > System.out.println(now); > > cf.addColumn("firstname", "John".getBytes(), now); > > cf.addColumn("lastname", "Doe".getBytes(), now); > > rm.add(cf); > > try { > > rm.apply(); > > } catch (Exception e) { > > } > > > > Table table = Table.open("Table1"); > > > > try { > > Row result = table.getRow("partner0", "Standard1"); > > System.out.println(result.toString()); > > ColumnFamily cres = result.getColumnFamily("Standard1"); > > Map cols = cres.getColumns(); > > System.out.println(cols.size()); > > Set c = cols.keySet(); > > Iterator it = c.iterator(); > > while (it.hasNext()) { > > String cn = (String) it.next(); > > System.out.println(cn); > > //Byt/eArrayOutputStream baos = new > ByteArrayOutputStream(); > > /DataOutputStream dos = new DataOutputStream(baos); > > > //cres.getColumnSerializer().serialize(cres.getColumn(cn), > > dos); > > //dos.flush(); > > //System.out.println(dos.size()); > > //System.out.println(dos.toString()); > > > System.out.println(cres.getColumn(cn).value().toString()); > > } > > > > //System.out.println(cres.getColumn("firstname").value().toString()); > > } catch (Exception e) { > > System.out.println(e.getMessage()); > > } > > > > In summary, it's a very simple code that inserts a row (key "partner0") > with > > two columns: firstname (value "John"), lastname (value "Doe") to the > > Standard1 column family. When I execute the test, I got the following > > output: > > > > [testng] 1245082940509 > > [testng] Row(partner0 [ColumnFamily(Standard1 > > [firstname:false:4@1245082940509, lastname:false:3@1245082940509]))] > > [testng] 2 > > [testng] lastname > > [testng] [B@dcb03b > > [testng] firstname > > [testng] [B@b60b93 > > > > Everything looks fine, the columns were inserted. However, the retrieved > > values were [B@dcb03b for lastname and [B@b60b93 for firstname, instead > of > > what's inserted by the code ("Doe", "John"). > > > > Anyone could give a clue as to why this happened? > > > > Thanks! > > > > Ivan > > > --0016364eef740577cc046c65b955 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thank you so much for the tip, it works!

= On Mon, Jun 15, 2009 at 12:34 PM, Jonathan Ellis <jbellis@gmail.com> wrote:
byte[].toString is not the inverse of String.getBytes; you need to use
new String(byte[]) for that.

fyi, the characters you see are

[: this is an array
B: of bytes
dcb03b: memory address

this will let you recognize such output in the future :)

-Jonathan

On Mon, Jun 15, 2009 at 11:26 AM, Ivan Chang<ivan.chang@medigy.com> wrote:
> I modified some test cases in the Cassandra distribution.=A0 Specifica= lly in
> the unit test package I modified ServerTest.java, basically just tried= to
> insert some columns and retrieve them.=A0 Here's part of the code:=
>
> =A0=A0=A0 =A0=A0=A0 RowMutation rm =3D new RowMutation("Table1&qu= ot;, "partner0");
> =A0=A0=A0 =A0=A0=A0 ColumnFamily cf =3D new ColumnFamily("Standar= d1", "Standard");
> =A0=A0=A0 =A0=A0=A0 long now =3D Calendar.getInstance().getTimeInMilli= s();
> =A0=A0=A0 =A0=A0=A0 System.out.println(now);
> =A0=A0=A0 =A0=A0=A0 cf.addColumn("firstname", "John&quo= t;.getBytes(), now);
> =A0=A0=A0 =A0=A0=A0 cf.addColumn("lastname", "Doe"= .getBytes(), now);
> =A0=A0=A0 =A0=A0=A0 rm.add(cf);
> =A0=A0=A0 =A0=A0=A0 try {
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 rm.apply();
> =A0=A0=A0 =A0=A0=A0 } catch (Exception e) {
> =A0=A0=A0 =A0=A0=A0 }
>
> =A0=A0=A0 =A0=A0=A0 Table table =3D Table.open("Table1"); >
> =A0=A0=A0 =A0=A0=A0 try {
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Row result =3D table.getRow("partne= r0", "Standard1");
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 System.out.println(result.toString()); > =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 ColumnFamily cres =3D result.getColumnFa= mily("Standard1");
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Map cols =3D cres.getColumns();
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 System.out.println(cols.size());
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Set c =3D cols.keySet();
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Iterator it =3D c.iterator();
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 while (it.hasNext()) {
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 String cn =3D (String) it.next= ();
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 System.out.println(cn);
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //Byt/eArrayOutputStream baos = =3D new ByteArrayOutputStream();
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 /DataOutputStream dos =3D new = DataOutputStream(baos);
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //cres.getColumnSerializer().s= erialize(cres.getColumn(cn),
> dos);
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //dos.flush();
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //System.out.println(dos.size(= ));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 //System.out.println(dos.toStr= ing());
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 System.out.println(cres.getCol= umn(cn).value().toString());
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }
>
> //System.out.println(cres.getColumn("firstname").value().toS= tring());
> =A0=A0=A0 =A0=A0=A0 } catch (Exception e) {
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 System.out.println(e.getMessage());
> =A0=A0=A0 =A0=A0=A0 }
>
> In summary, it's a very simple code that inserts a row (key "= partner0") with
> two columns: firstname (value "John"), lastname (value "= ;Doe") to the
> Standard1 column family.=A0 When I execute the test, I got the followi= ng
> output:
>
> =A0=A0 [testng] 1245082940509
> =A0=A0 [testng] Row(partner0 [ColumnFamily(Standard1
> [firstname:false:4@1245082940509, lastname:false:3@1245082940509]))] > =A0=A0 [testng] 2
> =A0=A0 [testng] lastname
> =A0=A0 [testng] [B@dcb03b
> =A0=A0 [testng] firstname
> =A0=A0 [testng] [B@b60b93
>
> Everything looks fine, the columns were inserted.=A0 However, the retr= ieved
> values were [B@dcb03b for lastname and [B@b60b93 for firstname, instea= d of
> what's inserted by the code ("Doe", "John"). >
> Anyone could give a clue as to why this happened?
>
> Thanks!
>
> Ivan
>

--0016364eef740577cc046c65b955--