You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "James Taylor (JIRA)" <ji...@apache.org> on 2014/07/30 07:28:39 UTC
[jira] [Commented] (PHOENIX-1131) PhoenixRuntime.encodePk needs to
pad row key values to max column length
[ https://issues.apache.org/jira/browse/PHOENIX-1131?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14078919#comment-14078919 ]
James Taylor commented on PHOENIX-1131:
---------------------------------------
Looks great, [~samarthjain]. Thanks for the quick turnaround on this!
> PhoenixRuntime.encodePk needs to pad row key values to max column length
> ------------------------------------------------------------------------
>
> Key: PHOENIX-1131
> URL: https://issues.apache.org/jira/browse/PHOENIX-1131
> Project: Phoenix
> Issue Type: Bug
> Affects Versions: 5.0.0, 3.1, 4.1
> Reporter: Samarth Jain
> Assignee: Samarth Jain
> Attachments: PHOENIX-1131-3.0.patch
>
>
> {code}
> @Test
> public void testEncodeDecodePaddingPks() throws Exception {
> Connection conn = DriverManager.getConnection(getUrl());
> conn.createStatement().execute(
> "CREATE TABLE T(pk1 CHAR(15) not null, pk2 CHAR(15) not null, v1 DATE " +
> "CONSTRAINT pk PRIMARY KEY (pk1, pk2))");
>
> PreparedStatement stmt = conn.prepareStatement("UPSERT INTO T (pk1, pk2, v1) VALUES (?, ?, ?)");
> stmt.setString(1, "def");
> stmt.setString(2, "eid");
> stmt.setDate(3, new Date(100));
> stmt.executeUpdate();
> conn.commit();
> stmt = conn.prepareStatement("SELECT pk1, pk2 FROM T");
> Object[] retrievedValues = new Object[2];
> ResultSet rs = stmt.executeQuery();
> rs.next();
> retrievedValues[0] = rs.getString(1);
> retrievedValues[1] = rs.getString(2);
>
> byte[] value = PhoenixRuntime.encodePK(conn, "T", retrievedValues);
> Object[] decodedValues = PhoenixRuntime.decodePK(conn, "T", value);
> assertEquals(Arrays.asList(decodedValues), Arrays.asList(retrievedValues));
> }
>
> Exception thrown:
> java.lang.ArrayIndexOutOfBoundsException: 14
> at org.apache.phoenix.util.StringUtil.getFirstNonBlankCharIdxFromEnd(StringUtil.java:184)
> at org.apache.phoenix.util.StringUtil.getUnpaddedCharLength(StringUtil.java:205)
> at org.apache.phoenix.schema.PDataType$2.toObject(PDataType.java:229)
> at org.apache.phoenix.schema.PDataType.toObject(PDataType.java:6901)
> at org.apache.phoenix.schema.PDataType.toObject(PDataType.java:6905)
> at org.apache.phoenix.schema.PDataType.toObject(PDataType.java:6933)
> at org.apache.phoenix.schema.PDataType.toObject(PDataType.java:6925)
> at org.apache.phoenix.util.PhoenixRuntime.decodePK(PhoenixRuntime.java:453)
> at org.apache.phoenix.end2end.PhoenixEncodeDecodeIT.testEncodeDecodePaddingPks(PhoenixEncodeDecodeIT.java:204)
>
> {code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)