[03/50] [abbrv] phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-11-04 Thread samarth
PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/encodecolumns2
Commit: 9ebd0921952501618f3e87fc02fba09ba779d1ef
Parents: 0dc0d79
Author: James Taylor 
Authored: Tue Oct 25 21:25:03 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 21:26:49 2016 -0700

--
 .../phoenix/end2end/index/ViewIndexIT.java  | 39 +---
 1 file changed, 34 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9ebd0921/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 99c8d2b..46aefff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -23,6 +23,7 @@ import static 
org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.Date;
@@ -44,6 +45,7 @@ import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -296,11 +298,10 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 assertEquals(expectedCount, rs.getInt(1));
 // Ensure that index is being used
 rs = stmt.executeQuery("EXPLAIN SELECT COUNT(*) FROM " + 
fullTableName);
-// Uses index and finds correct number of rows
-assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName)))
 + " [-32768,'123451234512345']\n" + 
-"SERVER FILTER BY FIRST KEY ONLY\n" + 
-"SERVER AGGREGATE INTO SINGLE ROW",
-QueryUtil.getExplainPlan(rs));
+if (fullBaseName != null) {
+// Uses index and finds correct number of rows
+assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 
PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName);
 
+}
 
 // Force it not to use index and still finds correct number of rows
 rs = stmt.executeQuery("SELECT /*+ NO_INDEX */ * FROM " + 
fullTableName);
@@ -369,13 +370,41 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 tsConn.commit();
 assertRowCount(tsConn, tsViewFullName, baseFullName, 8);
 
+// Use different connection for delete
 Connection tsConn2 = DriverManager.getConnection(getUrl(), 
tsProps);
 tsConn2.createStatement().execute("DELETE FROM " + tsViewFullName 
+ " WHERE DOUBLE1 > 7.5 AND DOUBLE1 < 9.5");
 tsConn2.commit();
 assertRowCount(tsConn2, tsViewFullName, baseFullName, 6);
 
+tsConn2.createStatement().execute("DROP VIEW " + tsViewFullName);
+// Should drop view and index and remove index data
+conn.createStatement().execute("DROP VIEW " + viewFullName);
+// Deletes table data (but wouldn't update index)
+conn.setAutoCommit(true);
+conn.createStatement().execute("DELETE FROM " + baseFullName);
+Connection tsConn3 = DriverManager.getConnection(getUrl(), 
tsProps);
+try {
+tsConn3.createStatement().execute("SELECT * FROM " + 
tsViewFullName + " LIMIT 1");
+fail("Expected table not to be found");
+} catch (TableNotFoundException e) {
+
+}
+conn.createStatement().execute(
+"CREATE VIEW " + viewFullName + " (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" +
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + "CONSTRAINT PKVIEW PRIMARY 
KEY\n" + "(\n" +
+  

[02/50] [abbrv] phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-11-04 Thread samarth
PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/encodecolumns2
Commit: 9b851d5c605c0fdcb8ce89ed4da09fe78fd79023
Parents: 2699265
Author: James Taylor 
Authored: Wed Oct 12 16:11:26 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 16:41:01 2016 -0700

--
 .../phoenix/compile/QueryCompilerTest.java  | 64 +++-
 1 file changed, 63 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b851d5c/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 7697d8c..2439ac9 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -457,6 +457,29 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 return plan.getContext().getScan();
 }
 
+private QueryPlan getQueryPlan(String query) throws SQLException {
+return getQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query) throws SQLException {
+return getOptimizedQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query, List binds) 
throws SQLException {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+try {
+PhoenixPreparedStatement statement = 
conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
+for (Object bind : binds) {
+statement.setObject(1, bind);
+}
+QueryPlan plan = statement.optimizeQuery(query);
+return plan;
+} finally {
+conn.close();
+}
+}
+
 private QueryPlan getQueryPlan(String query, List binds) throws 
SQLException {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
 Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -2263,7 +2286,7 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
 try {
 conn.createStatement().execute(
-"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY 
KEY, v1 VARCHAR) GUIDE_POST_WIDTH = -1");
+"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY KEY, v1 
VARCHAR) GUIDE_POSTS_WIDTH = -1");
 fail();
 } catch (SQLException e) {
 assertEquals("Unexpected Exception",
@@ -2443,4 +2466,43 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 conn.close();
 }
 }
+
+@Test
+public void testIndexOnViewWithChildView() throws SQLException {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+conn.createStatement().execute("CREATE TABLE 
PLATFORM_ENTITY.GLOBAL_TABLE (\n" + 
+"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + 
+"KEY_PREFIX CHAR(3) NOT NULL,\n" + 
+"CREATED_DATE DATE,\n" + 
+"CREATED_BY CHAR(15),\n" + 
+"CONSTRAINT PK PRIMARY KEY (\n" + 
+"ORGANIZATION_ID,\n" + 
+"KEY_PREFIX\n" + 
+")\n" + 
+") VERSIONS=1, IMMUTABLE_ROWS=true, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE VIEW 
PLATFORM_ENTITY.GLOBAL_VIEW  (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" + 
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + 
+"CONSTRAINT PKVIEW PRIMARY KEY\n" + 
+"(\n" + 
+"INT1\n" + 
+")\n" + 
+")\n" + 
+"AS SELECT * FROM PLATFORM_ENTITY.GLOBAL_TABLE WHERE 
KEY_PREFIX = '123'");
+conn.createStatement().execute("CREATE INDEX GLOBAL_INDEX\n" + 
+"ON PLATFORM_ENTITY.GLOBAL_VIEW (TEXT1 DESC, IN

[19/35] phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-28 Thread maryannxue
PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/calcite
Commit: 202b8eb1eda29db01006cdeefd8199f0bd360692
Parents: a5bcb3e
Author: James Taylor 
Authored: Tue Oct 25 21:25:03 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 21:26:01 2016 -0700

--
 .../phoenix/end2end/index/ViewIndexIT.java  | 39 +---
 1 file changed, 34 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/202b8eb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 99c8d2b..46aefff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -23,6 +23,7 @@ import static 
org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.Date;
@@ -44,6 +45,7 @@ import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -296,11 +298,10 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 assertEquals(expectedCount, rs.getInt(1));
 // Ensure that index is being used
 rs = stmt.executeQuery("EXPLAIN SELECT COUNT(*) FROM " + 
fullTableName);
-// Uses index and finds correct number of rows
-assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName)))
 + " [-32768,'123451234512345']\n" + 
-"SERVER FILTER BY FIRST KEY ONLY\n" + 
-"SERVER AGGREGATE INTO SINGLE ROW",
-QueryUtil.getExplainPlan(rs));
+if (fullBaseName != null) {
+// Uses index and finds correct number of rows
+assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 
PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName);
 
+}
 
 // Force it not to use index and still finds correct number of rows
 rs = stmt.executeQuery("SELECT /*+ NO_INDEX */ * FROM " + 
fullTableName);
@@ -369,13 +370,41 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 tsConn.commit();
 assertRowCount(tsConn, tsViewFullName, baseFullName, 8);
 
+// Use different connection for delete
 Connection tsConn2 = DriverManager.getConnection(getUrl(), 
tsProps);
 tsConn2.createStatement().execute("DELETE FROM " + tsViewFullName 
+ " WHERE DOUBLE1 > 7.5 AND DOUBLE1 < 9.5");
 tsConn2.commit();
 assertRowCount(tsConn2, tsViewFullName, baseFullName, 6);
 
+tsConn2.createStatement().execute("DROP VIEW " + tsViewFullName);
+// Should drop view and index and remove index data
+conn.createStatement().execute("DROP VIEW " + viewFullName);
+// Deletes table data (but wouldn't update index)
+conn.setAutoCommit(true);
+conn.createStatement().execute("DELETE FROM " + baseFullName);
+Connection tsConn3 = DriverManager.getConnection(getUrl(), 
tsProps);
+try {
+tsConn3.createStatement().execute("SELECT * FROM " + 
tsViewFullName + " LIMIT 1");
+fail("Expected table not to be found");
+} catch (TableNotFoundException e) {
+
+}
+conn.createStatement().execute(
+"CREATE VIEW " + viewFullName + " (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" +
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + "CONSTRAINT PKVIEW PRIMARY 
KEY\n" + "(\n" +
+"

[09/35] phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-28 Thread maryannxue
PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/calcite
Commit: 89cea911c1b5429363d32cbdeac3dadddccd5465
Parents: 6884528
Author: James Taylor 
Authored: Wed Oct 12 16:11:26 2016 -0700
Committer: James Taylor 
Committed: Wed Oct 12 16:11:26 2016 -0700

--
 .../phoenix/compile/QueryCompilerTest.java  | 64 +++-
 1 file changed, 63 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/89cea911/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 7697d8c..2439ac9 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -457,6 +457,29 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 return plan.getContext().getScan();
 }
 
+private QueryPlan getQueryPlan(String query) throws SQLException {
+return getQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query) throws SQLException {
+return getOptimizedQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query, List binds) 
throws SQLException {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+try {
+PhoenixPreparedStatement statement = 
conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
+for (Object bind : binds) {
+statement.setObject(1, bind);
+}
+QueryPlan plan = statement.optimizeQuery(query);
+return plan;
+} finally {
+conn.close();
+}
+}
+
 private QueryPlan getQueryPlan(String query, List binds) throws 
SQLException {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
 Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -2263,7 +2286,7 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
 try {
 conn.createStatement().execute(
-"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY 
KEY, v1 VARCHAR) GUIDE_POST_WIDTH = -1");
+"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY KEY, v1 
VARCHAR) GUIDE_POSTS_WIDTH = -1");
 fail();
 } catch (SQLException e) {
 assertEquals("Unexpected Exception",
@@ -2443,4 +2466,43 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 conn.close();
 }
 }
+
+@Test
+public void testIndexOnViewWithChildView() throws SQLException {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+conn.createStatement().execute("CREATE TABLE 
PLATFORM_ENTITY.GLOBAL_TABLE (\n" + 
+"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + 
+"KEY_PREFIX CHAR(3) NOT NULL,\n" + 
+"CREATED_DATE DATE,\n" + 
+"CREATED_BY CHAR(15),\n" + 
+"CONSTRAINT PK PRIMARY KEY (\n" + 
+"ORGANIZATION_ID,\n" + 
+"KEY_PREFIX\n" + 
+")\n" + 
+") VERSIONS=1, IMMUTABLE_ROWS=true, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE VIEW 
PLATFORM_ENTITY.GLOBAL_VIEW  (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" + 
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + 
+"CONSTRAINT PKVIEW PRIMARY KEY\n" + 
+"(\n" + 
+"INT1\n" + 
+")\n" + 
+")\n" + 
+"AS SELECT * FROM PLATFORM_ENTITY.GLOBAL_TABLE WHERE 
KEY_PREFIX = '123'");
+conn.createStatement().execute("CREATE INDEX GLOBAL_INDEX\n" + 
+"ON PLATFORM_ENTITY.GLOBAL_VIEW (TEXT1 DESC, INT1)\n" 

phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-25 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 4cdbaf4f8 -> fc7bb297e


PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/4.x-HBase-1.1
Commit: fc7bb297eced4303f2e92c62d4a9821ba922bcc9
Parents: 4cdbaf4
Author: James Taylor 
Authored: Tue Oct 25 21:25:03 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 21:28:13 2016 -0700

--
 .../phoenix/end2end/index/ViewIndexIT.java  | 39 +---
 1 file changed, 34 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/fc7bb297/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 99c8d2b..46aefff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -23,6 +23,7 @@ import static 
org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.Date;
@@ -44,6 +45,7 @@ import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -296,11 +298,10 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 assertEquals(expectedCount, rs.getInt(1));
 // Ensure that index is being used
 rs = stmt.executeQuery("EXPLAIN SELECT COUNT(*) FROM " + 
fullTableName);
-// Uses index and finds correct number of rows
-assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName)))
 + " [-32768,'123451234512345']\n" + 
-"SERVER FILTER BY FIRST KEY ONLY\n" + 
-"SERVER AGGREGATE INTO SINGLE ROW",
-QueryUtil.getExplainPlan(rs));
+if (fullBaseName != null) {
+// Uses index and finds correct number of rows
+assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 
PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName);
 
+}
 
 // Force it not to use index and still finds correct number of rows
 rs = stmt.executeQuery("SELECT /*+ NO_INDEX */ * FROM " + 
fullTableName);
@@ -369,13 +370,41 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 tsConn.commit();
 assertRowCount(tsConn, tsViewFullName, baseFullName, 8);
 
+// Use different connection for delete
 Connection tsConn2 = DriverManager.getConnection(getUrl(), 
tsProps);
 tsConn2.createStatement().execute("DELETE FROM " + tsViewFullName 
+ " WHERE DOUBLE1 > 7.5 AND DOUBLE1 < 9.5");
 tsConn2.commit();
 assertRowCount(tsConn2, tsViewFullName, baseFullName, 6);
 
+tsConn2.createStatement().execute("DROP VIEW " + tsViewFullName);
+// Should drop view and index and remove index data
+conn.createStatement().execute("DROP VIEW " + viewFullName);
+// Deletes table data (but wouldn't update index)
+conn.setAutoCommit(true);
+conn.createStatement().execute("DELETE FROM " + baseFullName);
+Connection tsConn3 = DriverManager.getConnection(getUrl(), 
tsProps);
+try {
+tsConn3.createStatement().execute("SELECT * FROM " + 
tsViewFullName + " LIMIT 1");
+fail("Expected table not to be found");
+} catch (TableNotFoundException e) {
+
+}
+conn.createStatement().execute(
+"CREATE VIEW " + viewFullName + " (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" +
+"IS_BOOLEAN BOOLEAN,\n" + 
+

phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-25 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 0dc0d7988 -> 9ebd09219


PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 9ebd0921952501618f3e87fc02fba09ba779d1ef
Parents: 0dc0d79
Author: James Taylor 
Authored: Tue Oct 25 21:25:03 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 21:26:49 2016 -0700

--
 .../phoenix/end2end/index/ViewIndexIT.java  | 39 +---
 1 file changed, 34 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9ebd0921/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 99c8d2b..46aefff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -23,6 +23,7 @@ import static 
org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.Date;
@@ -44,6 +45,7 @@ import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -296,11 +298,10 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 assertEquals(expectedCount, rs.getInt(1));
 // Ensure that index is being used
 rs = stmt.executeQuery("EXPLAIN SELECT COUNT(*) FROM " + 
fullTableName);
-// Uses index and finds correct number of rows
-assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName)))
 + " [-32768,'123451234512345']\n" + 
-"SERVER FILTER BY FIRST KEY ONLY\n" + 
-"SERVER AGGREGATE INTO SINGLE ROW",
-QueryUtil.getExplainPlan(rs));
+if (fullBaseName != null) {
+// Uses index and finds correct number of rows
+assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 
PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName);
 
+}
 
 // Force it not to use index and still finds correct number of rows
 rs = stmt.executeQuery("SELECT /*+ NO_INDEX */ * FROM " + 
fullTableName);
@@ -369,13 +370,41 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 tsConn.commit();
 assertRowCount(tsConn, tsViewFullName, baseFullName, 8);
 
+// Use different connection for delete
 Connection tsConn2 = DriverManager.getConnection(getUrl(), 
tsProps);
 tsConn2.createStatement().execute("DELETE FROM " + tsViewFullName 
+ " WHERE DOUBLE1 > 7.5 AND DOUBLE1 < 9.5");
 tsConn2.commit();
 assertRowCount(tsConn2, tsViewFullName, baseFullName, 6);
 
+tsConn2.createStatement().execute("DROP VIEW " + tsViewFullName);
+// Should drop view and index and remove index data
+conn.createStatement().execute("DROP VIEW " + viewFullName);
+// Deletes table data (but wouldn't update index)
+conn.setAutoCommit(true);
+conn.createStatement().execute("DELETE FROM " + baseFullName);
+Connection tsConn3 = DriverManager.getConnection(getUrl(), 
tsProps);
+try {
+tsConn3.createStatement().execute("SELECT * FROM " + 
tsViewFullName + " LIMIT 1");
+fail("Expected table not to be found");
+} catch (TableNotFoundException e) {
+
+}
+conn.createStatement().execute(
+"CREATE VIEW " + viewFullName + " (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" +
+"IS_BOOLEAN BOOLEAN,\n" + 
+  

phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-25 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/master a5bcb3ea9 -> 202b8eb1e


PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/master
Commit: 202b8eb1eda29db01006cdeefd8199f0bd360692
Parents: a5bcb3e
Author: James Taylor 
Authored: Tue Oct 25 21:25:03 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 21:26:01 2016 -0700

--
 .../phoenix/end2end/index/ViewIndexIT.java  | 39 +---
 1 file changed, 34 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/202b8eb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 99c8d2b..46aefff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -23,6 +23,7 @@ import static 
org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.Date;
@@ -44,6 +45,7 @@ import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -296,11 +298,10 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 assertEquals(expectedCount, rs.getInt(1));
 // Ensure that index is being used
 rs = stmt.executeQuery("EXPLAIN SELECT COUNT(*) FROM " + 
fullTableName);
-// Uses index and finds correct number of rows
-assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName)))
 + " [-32768,'123451234512345']\n" + 
-"SERVER FILTER BY FIRST KEY ONLY\n" + 
-"SERVER AGGREGATE INTO SINGLE ROW",
-QueryUtil.getExplainPlan(rs));
+if (fullBaseName != null) {
+// Uses index and finds correct number of rows
+assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 
PARALLEL 1-WAY RANGE SCAN OVER " + 
Bytes.toString(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(fullBaseName);
 
+}
 
 // Force it not to use index and still finds correct number of rows
 rs = stmt.executeQuery("SELECT /*+ NO_INDEX */ * FROM " + 
fullTableName);
@@ -369,13 +370,41 @@ public class ViewIndexIT extends ParallelStatsDisabledIT {
 tsConn.commit();
 assertRowCount(tsConn, tsViewFullName, baseFullName, 8);
 
+// Use different connection for delete
 Connection tsConn2 = DriverManager.getConnection(getUrl(), 
tsProps);
 tsConn2.createStatement().execute("DELETE FROM " + tsViewFullName 
+ " WHERE DOUBLE1 > 7.5 AND DOUBLE1 < 9.5");
 tsConn2.commit();
 assertRowCount(tsConn2, tsViewFullName, baseFullName, 6);
 
+tsConn2.createStatement().execute("DROP VIEW " + tsViewFullName);
+// Should drop view and index and remove index data
+conn.createStatement().execute("DROP VIEW " + viewFullName);
+// Deletes table data (but wouldn't update index)
+conn.setAutoCommit(true);
+conn.createStatement().execute("DELETE FROM " + baseFullName);
+Connection tsConn3 = DriverManager.getConnection(getUrl(), 
tsProps);
+try {
+tsConn3.createStatement().execute("SELECT * FROM " + 
tsViewFullName + " LIMIT 1");
+fail("Expected table not to be found");
+} catch (TableNotFoundException e) {
+
+}
+conn.createStatement().execute(
+"CREATE VIEW " + viewFullName + " (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" +
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR

[4/4] phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-25 Thread jamestaylor
PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 21befa2dc22b805ff1da8212e3c4f4679843dd9f
Parents: 910fc34
Author: James Taylor 
Authored: Wed Oct 12 16:11:26 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 17:05:33 2016 -0700

--
 .../phoenix/compile/QueryCompilerTest.java  | 64 +++-
 1 file changed, 63 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/21befa2d/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 7697d8c..2439ac9 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -457,6 +457,29 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 return plan.getContext().getScan();
 }
 
+private QueryPlan getQueryPlan(String query) throws SQLException {
+return getQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query) throws SQLException {
+return getOptimizedQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query, List binds) 
throws SQLException {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+try {
+PhoenixPreparedStatement statement = 
conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
+for (Object bind : binds) {
+statement.setObject(1, bind);
+}
+QueryPlan plan = statement.optimizeQuery(query);
+return plan;
+} finally {
+conn.close();
+}
+}
+
 private QueryPlan getQueryPlan(String query, List binds) throws 
SQLException {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
 Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -2263,7 +2286,7 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
 try {
 conn.createStatement().execute(
-"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY 
KEY, v1 VARCHAR) GUIDE_POST_WIDTH = -1");
+"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY KEY, v1 
VARCHAR) GUIDE_POSTS_WIDTH = -1");
 fail();
 } catch (SQLException e) {
 assertEquals("Unexpected Exception",
@@ -2443,4 +2466,43 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 conn.close();
 }
 }
+
+@Test
+public void testIndexOnViewWithChildView() throws SQLException {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+conn.createStatement().execute("CREATE TABLE 
PLATFORM_ENTITY.GLOBAL_TABLE (\n" + 
+"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + 
+"KEY_PREFIX CHAR(3) NOT NULL,\n" + 
+"CREATED_DATE DATE,\n" + 
+"CREATED_BY CHAR(15),\n" + 
+"CONSTRAINT PK PRIMARY KEY (\n" + 
+"ORGANIZATION_ID,\n" + 
+"KEY_PREFIX\n" + 
+")\n" + 
+") VERSIONS=1, IMMUTABLE_ROWS=true, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE VIEW 
PLATFORM_ENTITY.GLOBAL_VIEW  (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" + 
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + 
+"CONSTRAINT PKVIEW PRIMARY KEY\n" + 
+"(\n" + 
+"INT1\n" + 
+")\n" + 
+")\n" + 
+"AS SELECT * FROM PLATFORM_ENTITY.GLOBAL_TABLE WHERE 
KEY_PREFIX = '123'");
+conn.createStatement().execute("CREATE INDEX GLOBAL_INDEX\n" + 
+"ON PLATFORM_ENTITY.GLOBAL_VIEW (TEXT1 DESC, INT

[4/4] phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-25 Thread jamestaylor
PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 9b851d5c605c0fdcb8ce89ed4da09fe78fd79023
Parents: 2699265
Author: James Taylor 
Authored: Wed Oct 12 16:11:26 2016 -0700
Committer: James Taylor 
Committed: Tue Oct 25 16:41:01 2016 -0700

--
 .../phoenix/compile/QueryCompilerTest.java  | 64 +++-
 1 file changed, 63 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b851d5c/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 7697d8c..2439ac9 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -457,6 +457,29 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 return plan.getContext().getScan();
 }
 
+private QueryPlan getQueryPlan(String query) throws SQLException {
+return getQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query) throws SQLException {
+return getOptimizedQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query, List binds) 
throws SQLException {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+try {
+PhoenixPreparedStatement statement = 
conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
+for (Object bind : binds) {
+statement.setObject(1, bind);
+}
+QueryPlan plan = statement.optimizeQuery(query);
+return plan;
+} finally {
+conn.close();
+}
+}
+
 private QueryPlan getQueryPlan(String query, List binds) throws 
SQLException {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
 Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -2263,7 +2286,7 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
 try {
 conn.createStatement().execute(
-"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY 
KEY, v1 VARCHAR) GUIDE_POST_WIDTH = -1");
+"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY KEY, v1 
VARCHAR) GUIDE_POSTS_WIDTH = -1");
 fail();
 } catch (SQLException e) {
 assertEquals("Unexpected Exception",
@@ -2443,4 +2466,43 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 conn.close();
 }
 }
+
+@Test
+public void testIndexOnViewWithChildView() throws SQLException {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+conn.createStatement().execute("CREATE TABLE 
PLATFORM_ENTITY.GLOBAL_TABLE (\n" + 
+"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + 
+"KEY_PREFIX CHAR(3) NOT NULL,\n" + 
+"CREATED_DATE DATE,\n" + 
+"CREATED_BY CHAR(15),\n" + 
+"CONSTRAINT PK PRIMARY KEY (\n" + 
+"ORGANIZATION_ID,\n" + 
+"KEY_PREFIX\n" + 
+")\n" + 
+") VERSIONS=1, IMMUTABLE_ROWS=true, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE VIEW 
PLATFORM_ENTITY.GLOBAL_VIEW  (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" + 
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + 
+"CONSTRAINT PKVIEW PRIMARY KEY\n" + 
+"(\n" + 
+"INT1\n" + 
+")\n" + 
+")\n" + 
+"AS SELECT * FROM PLATFORM_ENTITY.GLOBAL_TABLE WHERE 
KEY_PREFIX = '123'");
+conn.createStatement().execute("CREATE INDEX GLOBAL_INDEX\n" + 
+"ON PLATFORM_ENTITY.GLOBAL_VIEW (TEXT1 DESC, IN

phoenix git commit: PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use parent VIEW indexes

2016-10-12 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/master 688452879 -> 89cea911c


PHOENIX-3370 VIEW derived from another VIEW with WHERE on a TABLE doesn't use 
parent VIEW indexes


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

Branch: refs/heads/master
Commit: 89cea911c1b5429363d32cbdeac3dadddccd5465
Parents: 6884528
Author: James Taylor 
Authored: Wed Oct 12 16:11:26 2016 -0700
Committer: James Taylor 
Committed: Wed Oct 12 16:11:26 2016 -0700

--
 .../phoenix/compile/QueryCompilerTest.java  | 64 +++-
 1 file changed, 63 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/89cea911/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 7697d8c..2439ac9 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -457,6 +457,29 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 return plan.getContext().getScan();
 }
 
+private QueryPlan getQueryPlan(String query) throws SQLException {
+return getQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query) throws SQLException {
+return getOptimizedQueryPlan(query, Collections.emptyList());
+}
+
+private QueryPlan getOptimizedQueryPlan(String query, List binds) 
throws SQLException {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+try {
+PhoenixPreparedStatement statement = 
conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
+for (Object bind : binds) {
+statement.setObject(1, bind);
+}
+QueryPlan plan = statement.optimizeQuery(query);
+return plan;
+} finally {
+conn.close();
+}
+}
+
 private QueryPlan getQueryPlan(String query, List binds) throws 
SQLException {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
 Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -2263,7 +2286,7 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
 try {
 conn.createStatement().execute(
-"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY 
KEY, v1 VARCHAR) GUIDE_POST_WIDTH = -1");
+"CREATE TABLE t (k VARCHAR NOT NULL PRIMARY KEY, v1 
VARCHAR) GUIDE_POSTS_WIDTH = -1");
 fail();
 } catch (SQLException e) {
 assertEquals("Unexpected Exception",
@@ -2443,4 +2466,43 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 conn.close();
 }
 }
+
+@Test
+public void testIndexOnViewWithChildView() throws SQLException {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+conn.createStatement().execute("CREATE TABLE 
PLATFORM_ENTITY.GLOBAL_TABLE (\n" + 
+"ORGANIZATION_ID CHAR(15) NOT NULL,\n" + 
+"KEY_PREFIX CHAR(3) NOT NULL,\n" + 
+"CREATED_DATE DATE,\n" + 
+"CREATED_BY CHAR(15),\n" + 
+"CONSTRAINT PK PRIMARY KEY (\n" + 
+"ORGANIZATION_ID,\n" + 
+"KEY_PREFIX\n" + 
+")\n" + 
+") VERSIONS=1, IMMUTABLE_ROWS=true, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE VIEW 
PLATFORM_ENTITY.GLOBAL_VIEW  (\n" + 
+"INT1 BIGINT NOT NULL,\n" + 
+"DOUBLE1 DECIMAL(12, 3),\n" + 
+"IS_BOOLEAN BOOLEAN,\n" + 
+"TEXT1 VARCHAR,\n" + 
+"CONSTRAINT PKVIEW PRIMARY KEY\n" + 
+"(\n" + 
+"INT1\n" + 
+")\n" + 
+")\n" + 
+"AS SELECT * FROM PLATFORM_ENTITY.GLOBAL_TABLE WHERE 
KEY_PREFIX = '123'");
+conn.createStatement().execute("CREATE INDEX GLOBAL_INDEX