You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/07/30 07:32:30 UTC
git commit: PHOENIX-1131 PhoenixRuntime.encodePk needs to pad row key
values to max column length (Samarth Jain)
Repository: phoenix
Updated Branches:
refs/heads/3.0 3d4ecad36 -> 05b1ff4c6
PHOENIX-1131 PhoenixRuntime.encodePk needs to pad row key values to max column length (Samarth Jain)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/05b1ff4c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/05b1ff4c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/05b1ff4c
Branch: refs/heads/3.0
Commit: 05b1ff4c622041d0fa3741c298938945213a9bfa
Parents: 3d4ecad
Author: James Taylor <jt...@salesforce.com>
Authored: Tue Jul 29 22:35:44 2014 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Tue Jul 29 22:35:44 2014 -0700
----------------------------------------------------------------------
.../phoenix/end2end/PhoenixEncodeDecodeIT.java | 28 ++++++++++++++++++++
.../org/apache/phoenix/util/PhoenixRuntime.java | 5 +++-
2 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/05b1ff4c/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixEncodeDecodeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixEncodeDecodeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixEncodeDecodeIT.java
index fc01730..bdb0745 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixEncodeDecodeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixEncodeDecodeIT.java
@@ -177,6 +177,34 @@ public class PhoenixEncodeDecodeIT extends BaseHBaseManagedTimeIT {
assertEquals(Arrays.asList(decodedValues), Arrays.asList(retrievedValues));
}
+
+ @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));
+ }
private static Connection getTenantSpecificConnection() throws Exception {
Properties props = new Properties();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/05b1ff4c/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index 06bdf5a..fdcc02a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -414,7 +414,10 @@ public class PhoenixRuntime {
output.write(QueryConstants.SEPARATOR_BYTE);
}
type = pkColumns.get(i).getDataType();
- byte[] value = type.toBytes(values[i - offset]);
+
+ //for fixed width data types like CHAR and BINARY, we need to pad values to be of max length.
+ Object paddedObj = type.pad(values[i - offset], pkColumns.get(i).getMaxLength());
+ byte[] value = type.toBytes(paddedObj);
output.write(value);
}
return output.toByteArray();