You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by divye sheth <di...@gmail.com> on 2015/07/02 12:24:00 UTC

MD5 hash function in Phoenix

Hi Team,

I have a table which is has four columns all strings, and there is a
primary key which is MD5(four columns).

Now theoretically, if the values of all the four columns are same the MD5
hash should be the same. But thats not in my case. I have indeed verified
that there is no difference in the data.

But somehow phoenix inserts a new row all together rather than updating the
same, since the MD5 should be the same.

Is my understanding correct? I am accessing phoenix using jdbc.

Thanks
Divye Sheth

Re: MD5 hash function in Phoenix

Posted by James Taylor <ja...@apache.org>.
Hi Divye,
Our MD5 function accepts only a single argument, not four. Would it be
possible for you to post some sample code? The code for our MD5 built-in is
in org.apache.phoenix.expression.function.MD5Function if you want to take a
look with tests in org.apache.phoenix.end2end.MD5FunctionIT.

FWIW, If you have a composite primary key, you can use our row value
constructor syntax to concatenate the columns together like the example
shown below.

  @Test
  public void testRetrieveCompositeKey() throws Exception {
      String testString = "FOOBAR";

      Connection conn = DriverManager.getConnection(getUrl());
      String ddl = "CREATE TABLE IF NOT EXISTS MD5_RETRIEVE_TEST (k1
CHAR(3) NOT NULL, k2 CHAR(3) NOT NULL, CONSTRAINT PK PRIMARY KEY (K1,K2))";
      conn.createStatement().execute(ddl);
      String dml = "UPSERT INTO MD5_RETRIEVE_TEST VALUES('FOO','BAR')";
      conn.createStatement().execute(dml);
      conn.commit();

      ResultSet rs = conn.createStatement().executeQuery("SELECT
MD5((K1,K2)) FROM MD5_RETRIEVE_TEST");
      assertTrue(rs.next());
      byte[] first =
MessageDigest.getInstance("MD5").digest(testString.getBytes());
      byte[] second = rs.getBytes(1);
      assertArrayEquals(first, second);
      assertFalse(rs.next());
  }

Thanks,
James



On Thu, Jul 2, 2015 at 3:24 AM, divye sheth <di...@gmail.com> wrote:

> Hi Team,
>
> I have a table which is has four columns all strings, and there is a
> primary key which is MD5(four columns).
>
> Now theoretically, if the values of all the four columns are same the MD5
> hash should be the same. But thats not in my case. I have indeed verified
> that there is no difference in the data.
>
> But somehow phoenix inserts a new row all together rather than updating
> the same, since the MD5 should be the same.
>
> Is my understanding correct? I am accessing phoenix using jdbc.
>
> Thanks
> Divye Sheth
>