[12/35] phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3e4aec1b Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3e4aec1b Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3e4aec1b Branch: refs/heads/calcite Commit: 3e4aec1bc440ad503d5058237e3b508392df9266 Parents: 45fbc41 Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Sat Oct 15 17:25:27 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/3e4aec1b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index 041e96d..b9162de 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends ParallelStatsDisabledIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateUniqueName(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +
phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/4.8-HBase-1.2 1cb359769 -> b52321d77 PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b52321d7 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b52321d7 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b52321d7 Branch: refs/heads/4.8-HBase-1.2 Commit: b52321d7769ea785a4336c36242497a47be711d3 Parents: 1cb3597 Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 17:25:00 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/b52321d7/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index c4e4665..c8eb95a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateRandomString(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +
phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/4.8-HBase-1.1 da21bca6d -> 3bd49e06e PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3bd49e06 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3bd49e06 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3bd49e06 Branch: refs/heads/4.8-HBase-1.1 Commit: 3bd49e06e907c89794a410e2e6451ee75c78c9ab Parents: da21bca Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 17:23:32 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/3bd49e06/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index c4e4665..c8eb95a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateRandomString(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +
phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/4.8-HBase-1.0 1afcb2e35 -> a28119d52 PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a28119d5 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a28119d5 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a28119d5 Branch: refs/heads/4.8-HBase-1.0 Commit: a28119d52ede8107c8237740678ea1ddd9ceb2c1 Parents: 1afcb2e Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 17:21:33 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/a28119d5/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index c4e4665..c8eb95a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateRandomString(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +
phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results (missing file)
Repository: phoenix Updated Branches: refs/heads/4.8-HBase-0.98 c394b4ee1 -> 0aafcd4f5 PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results (missing file) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0aafcd4f Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0aafcd4f Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0aafcd4f Branch: refs/heads/4.8-HBase-0.98 Commit: 0aafcd4f5553f7af44d5c048046f213d630b3e96 Parents: c394b4e Author: James Taylor Authored: Tue Oct 25 17:19:29 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 17:19:29 2016 -0700 -- .../src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/0aafcd4f/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index 3172a20..c8eb95a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -375,7 +375,7 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT { @Test public void testRVCOnDescWithLeadingPKEquality() throws Exception { final Connection conn = DriverManager.getConnection(getUrl()); -String fullTableName = generateUniqueName(); +String fullTableName = generateRandomString(); try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE " + fullTableName + "(\n" + "ORGANIZATION_ID CHAR(15) NOT NULL,\n" + @@ -435,7 +435,7 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT { @Test public void testSingleDescPKColumnComparison() throws Exception { final Connection conn = DriverManager.getConnection(getUrl()); -String fullTableName = generateUniqueName(); +String fullTableName = generateRandomString(); try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE " + fullTableName + "(\n" + "ORGANIZATION_ID CHAR(15) NOT NULL,\n" +
phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/4.8-HBase-0.98 04a76294b -> c394b4ee1 PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c394b4ee Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c394b4ee Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c394b4ee Branch: refs/heads/4.8-HBase-0.98 Commit: c394b4ee1e9f2de0a9d3dd1a77fbf653a69bbbeb Parents: 04a7629 Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 17:13:07 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/c394b4ee/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index c4e4665..3172a20 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends BaseHBaseManagedTimeTableReuseIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateUniqueName(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +
[1/4] phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.1 910fc34d9 -> 4cdbaf4f8 PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/4cdbaf4f Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/4cdbaf4f Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/4cdbaf4f Branch: refs/heads/4.x-HBase-1.1 Commit: 4cdbaf4f88e3e13ddd0377e594a00a735eacf75c Parents: 96b14f5 Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 17:05:33 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/4cdbaf4f/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index 041e96d..b9162de 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends ParallelStatsDisabledIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateUniqueName(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +a
[1/4] phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 2699265c7 -> 0dc0d7988 PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0dc0d798 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0dc0d798 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0dc0d798 Branch: refs/heads/4.x-HBase-0.98 Commit: 0dc0d7988ba7d9ecc2a74780bd64bf162f75bee5 Parents: 6027ee8 Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Tue Oct 25 16:41:01 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/0dc0d798/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index 041e96d..b9162de 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends ParallelStatsDisabledIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateUniqueName(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +
phoenix git commit: PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results
Repository: phoenix Updated Branches: refs/heads/master 45fbc4177 -> 3e4aec1bc PHOENIX-3382 Query using Row Value Constructor comprised of non leading PK columns returns incorrect results Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3e4aec1b Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3e4aec1b Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3e4aec1b Branch: refs/heads/master Commit: 3e4aec1bc440ad503d5058237e3b508392df9266 Parents: 45fbc41 Author: James Taylor Authored: Sat Oct 15 17:05:21 2016 -0700 Committer: James Taylor Committed: Sat Oct 15 17:25:27 2016 -0700 -- .../org/apache/phoenix/end2end/QueryMoreIT.java | 103 +++ .../apache/phoenix/compile/WhereOptimizer.java | 4 + .../phoenix/compile/WhereOptimizerTest.java | 61 +++ 3 files changed, 168 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/3e4aec1b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java -- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java index 041e96d..b9162de 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryMoreIT.java @@ -368,4 +368,107 @@ public class QueryMoreIT extends ParallelStatsDisabledIT { assertNull(rs.getBigDecimal(2, 10)); } } + +// FIXME: this repros PHOENIX-3382, but turned up two more issues: +// 1) PHOENIX-3383 Comparison between descending row keys used in RVC is reverse +// 2) PHOENIX-3384 Optimize RVC expressions for non leading row key columns +@Test +public void testRVCOnDescWithLeadingPKEquality() throws Exception { +final Connection conn = DriverManager.getConnection(getUrl()); +String fullTableName = generateUniqueName(); +try (Statement stmt = conn.createStatement()) { +stmt.execute("CREATE TABLE " + fullTableName + "(\n" + +"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + +"SCORE DOUBLE NOT NULL,\n" + +"ENTITY_ID CHAR(15) NOT NULL\n" + +"CONSTRAINT PAGE_SNAPSHOT_PK PRIMARY KEY (\n" + +"ORGANIZATION_ID,\n" + +"SCORE DESC,\n" + +"ENTITY_ID DESC\n" + +")\n" + +") MULTI_TENANT=TRUE"); +} + +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',3,'01')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'04')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',2,'03')"); +conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES ('org1',1,'02')"); +conn.commit(); + +// FIXME: PHOENIX-3383 +// This comparison is really backwards: it should be (score, entity_id) < (2, '04'), +// but because we're matching a descending key, our comparison has to be switched. +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (score, entity_id) > (2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("02", rs.getString(1)); +assertEquals(1.0, rs.getDouble(2), 0.001); +assertFalse(rs.next()); +} +// FIXME: PHOENIX-3384 +// It should not be necessary to specify organization_id in this query +try (Statement stmt = conn.createStatement()) { +final ResultSet rs = stmt.executeQuery("SELECT entity_id, score\n" + +"FROM " + fullTableName + "\n" + +"WHERE organization_id = 'org1'\n" + +"AND (organization_id, score, entity_id) > ('org1', 2, '04')\n" + +"ORDER BY score DESC, entity_id DESC\n" + +"LIMIT 3"); +assertTrue(rs.next()); +assertEquals("03", rs.getString(1)); +assertEquals(2.0, rs.getDouble(2), 0.001); +assertTrue(rs.next()); +assertEquals("0