phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11.2 6b693e93f -> ce7fae412


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-cdh5.11.2
Commit: ce7fae41268dc464e1dd236fb83d557c1d107e7a
Parents: 6b693e9
Author: maryannxue 
Authored: Thu Feb 8 12:52:59 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:52:59 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce7fae41/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce7fae41/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null && 

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 ea57ee008 -> 63fa82e63


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 63fa82e6374a03f0d243820b1e135cc88e185381
Parents: ea57ee0
Author: maryannxue 
Authored: Thu Feb 8 12:51:16 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:51:16 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/63fa82e6/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63fa82e6/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index fcac335..ea32b9f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -532,9 +532,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null && 

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 260278532 -> 587f78de2


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 587f78de2f0c5b204523ed5116301566bb6559c9
Parents: 2602785
Author: maryannxue 
Authored: Thu Feb 8 12:50:31 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:50:31 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/587f78de/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/587f78de/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null && 

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 a642a5577 -> 48d1df3dd


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 48d1df3dd6b7316ed56b46d5a0471525dc8709e5
Parents: a642a55
Author: maryannxue 
Authored: Thu Feb 8 12:50:07 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:50:07 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/48d1df3d/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/48d1df3d/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null && 

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 507f2b8ee -> 7bf3a5753


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-1.3
Commit: 7bf3a575339ff0003ddf1cce48b7484bc352337f
Parents: 507f2b8
Author: maryannxue 
Authored: Thu Feb 8 12:49:35 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:49:35 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bf3a575/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bf3a575/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null && 

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 d1ad1f585 -> a7bb5c44c


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/5.x-HBase-2.0
Commit: a7bb5c44c6b6b8ac5ec5c26555602280bf0680df
Parents: d1ad1f5
Author: maryannxue 
Authored: Thu Feb 8 12:40:29 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:40:29 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a7bb5c44/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/a7bb5c44/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index a0c0971..af9d183 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -530,9 +530,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null && 

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master ba8bcefc9 -> 82bbfdb1d


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/master
Commit: 82bbfdb1d547664513274b2450fff2104bd6b234
Parents: ba8bcef
Author: maryannxue 
Authored: Thu Feb 8 12:38:52 2018 -0800
Committer: maryannxue 
Committed: Thu Feb 8 12:38:52 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/82bbfdb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/82bbfdb1/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side if a table has 
global mutable secondary indexes on it
 boolean hasGlobalMutableIndexes = 
SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
+boolean hasWhereSubquery = select.getWhere() != null &&