Thank you so much for the tip, it works!
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. 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
>