git commit: PHOENIX-1131 PhoenixRuntime.encodePk needs to pad row key values to max column length (Samarth Jain)

2014-07-29 Thread jamestaylor
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 jtay...@salesforce.com
Authored: Tue Jul 29 22:35:44 2014 -0700
Committer: James Taylor jtay...@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();



git commit: PHOENIX-1131 PhoenixRuntime.encodePk needs to pad row key values to max column length (Samarth Jain)

2014-07-29 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/4.0 6a6a9c0f2 - 85d91bde7


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/85d91bde
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/85d91bde
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/85d91bde

Branch: refs/heads/4.0
Commit: 85d91bde7f2ffe39774e484ab41f64513789077c
Parents: 6a6a9c0
Author: James Taylor jtay...@salesforce.com
Authored: Tue Jul 29 22:35:44 2014 -0700
Committer: James Taylor jtay...@salesforce.com
Committed: Tue Jul 29 22:36:38 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/85d91bde/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/85d91bde/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 b73185f..0f5e863 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
@@ -417,7 +417,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();



git commit: PHOENIX-1131 PhoenixRuntime.encodePk needs to pad row key values to max column length (Samarth Jain)

2014-07-29 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/master 382f901a6 - eeac05afa


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/eeac05af
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/eeac05af
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/eeac05af

Branch: refs/heads/master
Commit: eeac05afa257a7e733298a5680efede4abcd5355
Parents: 382f901
Author: James Taylor jtay...@salesforce.com
Authored: Tue Jul 29 22:35:44 2014 -0700
Committer: James Taylor jtay...@salesforce.com
Committed: Tue Jul 29 22:38:34 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/eeac05af/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/eeac05af/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 a52cd95..af4c9e0 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
@@ -415,7 +415,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();