phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [2/4] phoenix git commit: PHOENIX-2961 select on a composite primary key fails when DESC is set in the table
Date Tue, 14 Jun 2016 01:07:06 GMT
PHOENIX-2961 select on a composite primary key fails when DESC is set in the table


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ffa404f8
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ffa404f8
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ffa404f8

Branch: refs/heads/4.x-HBase-0.98
Commit: ffa404f886752e7f5177bb61f8f3a42b07499862
Parents: 604b98b
Author: James Taylor <jamestaylor@apache.org>
Authored: Mon Jun 13 13:46:47 2016 -0700
Committer: James Taylor <jamestaylor@apache.org>
Committed: Mon Jun 13 18:10:03 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/HashJoinMoreIT.java  | 47 ++++++++++++++++++++
 .../org/apache/phoenix/compile/ScanRanges.java  |  2 +-
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffa404f8/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
index 128baf3..481e4af 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java
@@ -875,4 +875,51 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT {
             conn.close();
         }
     }
+    
+    @Test
+    public void testBug2961() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(true);
+        
+        conn.createStatement().execute("CREATE TABLE test2961 (\n" + 
+                "ACCOUNT_ID VARCHAR NOT NULL,\n" + 
+                "BUCKET_ID VARCHAR NOT NULL,\n" + 
+                "OBJECT_ID VARCHAR NOT NULL,\n" + 
+                "OBJECT_VERSION VARCHAR NOT NULL,\n" + 
+                "LOC VARCHAR,\n" + 
+                "CONSTRAINT PK PRIMARY KEY (ACCOUNT_ID, BUCKET_ID, OBJECT_ID, OBJECT_VERSION
DESC))");
+        conn.createStatement().execute("UPSERT INTO test2961  (ACCOUNT_ID, BUCKET_ID, OBJECT_ID,
OBJECT_VERSION, LOC) VALUES ('acct1', 'bucket1', 'obj1', '1111', 'loc1')");
+        ResultSet rs = conn.createStatement().executeQuery("select ACCOUNT_ID, BUCKET_ID,
OBJECT_VERSION  from test2961  WHERE ACCOUNT_ID = 'acct1' and BUCKET_ID = 'bucket1' and OBJECT_VERSION
= '1111'");
+        assertTrue(rs.next());
+        rs = conn.createStatement().executeQuery("select ACCOUNT_ID, BUCKET_ID, OBJECT_VERSION
 from test2961  WHERE ACCOUNT_ID = 'acct1' and BUCKET_ID = 'bucket1' and OBJECT_ID = 'obj1'");
+        assertTrue(rs.next());
+        rs = conn.createStatement().executeQuery("select ACCOUNT_ID, BUCKET_ID, OBJECT_VERSION
 from test2961  WHERE ACCOUNT_ID = 'acct1' and BUCKET_ID = 'bucket1' and OBJECT_VERSION =
'1111'  and OBJECT_ID = 'obj1'");
+        assertTrue(rs.next());
+
+        conn.createStatement().execute("UPSERT INTO test2961  (ACCOUNT_ID, BUCKET_ID, OBJECT_ID,
OBJECT_VERSION, LOC) VALUES ('acct1', 'bucket1', 'obj1', '2222', 'loc1')");
+        rs = conn.createStatement().executeQuery("SELECT  OBJ.ACCOUNT_ID, OBJ.BUCKET_ID,
OBJ.OBJECT_ID, OBJ.OBJECT_VERSION, OBJ.LOC "
+                + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, MAX(OBJECT_VERSION) AS
MAXVER"
+                + "       FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, OBJECT_ID) AS X "
+                + "       INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = OBJ.ACCOUNT_ID AND
X.BUCKET_ID = OBJ.BUCKET_ID AND X.OBJECT_ID = OBJ.OBJECT_ID AND X.MAXVER = OBJ.OBJECT_VERSION");
+        assertTrue(rs.next());
+        assertEquals("2222", rs.getString(4));
+        assertFalse(rs.next());
+        
+        rs = conn.createStatement().executeQuery("SELECT  OBJ.ACCOUNT_ID, OBJ.BUCKET_ID,
OBJ.OBJECT_ID, OBJ.OBJECT_VERSION, OBJ.LOC "
+                + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, MAX(OBJECT_VERSION) AS
MAXVER "
+                + "       FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, OBJECT_ID) AS X "
+                + "       INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = OBJ.ACCOUNT_ID AND
X.OBJECT_ID = OBJ.OBJECT_ID AND X.MAXVER = OBJ.OBJECT_VERSION");
+        assertTrue(rs.next());
+        assertEquals("2222", rs.getString(4));
+        assertFalse(rs.next());
+        
+        rs = conn.createStatement().executeQuery("SELECT  OBJ.ACCOUNT_ID, OBJ.BUCKET_ID,
OBJ.OBJECT_ID, OBJ.OBJECT_VERSION, OBJ.LOC "
+                + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, MAX(OBJECT_VERSION) AS
MAXVER "
+                + "       FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, OBJECT_ID) AS X "
+                + "       INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = OBJ.ACCOUNT_ID AND
X.BUCKET_ID = OBJ.BUCKET_ID AND  X.MAXVER = OBJ.OBJECT_VERSION");
+        assertTrue(rs.next());
+        assertEquals("2222", rs.getString(4));
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffa404f8/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
index 5edaead..6f0adb0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
@@ -103,7 +103,7 @@ public class ScanRanges {
             useSkipScan = keyRanges.size() > 1;
             // Treat as binary if descending because we've got a separator byte at the end
             // which is not part of the value.
-            if (keys.size() > 1 || SchemaUtil.getSeparatorByte(schema.rowKeyOrderOptimizable(),
false, schema.getField(0)) == QueryConstants.DESC_SEPARATOR_BYTE) {
+            if (keys.size() > 1 || SchemaUtil.getSeparatorByte(schema.rowKeyOrderOptimizable(),
false, schema.getField(schema.getFieldCount()-1)) == QueryConstants.DESC_SEPARATOR_BYTE) {
                 schema = SchemaUtil.VAR_BINARY_SCHEMA;
                 slotSpan = ScanUtil.SINGLE_COLUMN_SLOT_SPAN;
             } else {


Mime
View raw message