You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2016/10/06 19:37:09 UTC

[1/4] phoenix git commit: Add PhoenixSchema.clear(); Change CalciteLocalIndexIT test method by sharing connections throughout one test case.

Repository: phoenix
Updated Branches:
  refs/heads/calcite 66f20ca9d -> 68717c054


Add PhoenixSchema.clear(); Change CalciteLocalIndexIT test method by sharing connections throughout one test case.


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

Branch: refs/heads/calcite
Commit: 78c13b778e9f4d353ee537dffab69a2e71464c52
Parents: 66f20ca
Author: maryannxue <ma...@gmail.com>
Authored: Mon Oct 3 16:44:46 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Mon Oct 3 16:44:46 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/calcite/BaseCalciteIT.java   |   8 +-
 .../phoenix/calcite/CalciteLocalIndexIT.java    | 184 +++++++++----------
 .../calcite/jdbc/PhoenixCalciteFactory.java     |  11 +-
 .../apache/phoenix/calcite/PhoenixSchema.java   |   8 +-
 4 files changed, 108 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/78c13b77/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
index 05d825d..9891bd0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
@@ -428,9 +428,11 @@ public class BaseCalciteIT extends BaseHBaseManagedTimeIT {
 
     protected static Properties getConnectionProps(boolean enableMaterialization, float rowCountFactor) {
         Properties props = new Properties();
-        props.setProperty(
-                CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
-                Boolean.toString(enableMaterialization));
+        if (!enableMaterialization) {
+            props.setProperty(
+                    CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
+                    Boolean.toString(enableMaterialization));
+        }
         props.setProperty(
                 CalciteConnectionProperty.CREATE_MATERIALIZATIONS.camelName(),
                 Boolean.toString(false));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/78c13b77/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteLocalIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteLocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteLocalIndexIT.java
index 7b6c279..0c03715 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteLocalIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteLocalIndexIT.java
@@ -31,114 +31,105 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
     }
     
     @Test public void testIndex() throws Exception {
-        start(true, 1000f).sql("select * from aTable where b_string = 'b'")
+        final Start start1000 = start(true, 1000f);
+        final Start start1000000 = start(true, 1000000f);
+
+        start1000.sql("select * from aTable where b_string = 'b'")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(ORGANIZATION_ID=[$1], ENTITY_ID=[$2], A_STRING=[$3], B_STRING=[$0], A_INTEGER=[$4], A_DATE=[$5], A_TIME=[$6], A_TIMESTAMP=[$7], X_DECIMAL=[$8], X_LONG=[$9], X_INTEGER=[$10], Y_INTEGER=[$11], A_BYTE=[$12], A_SHORT=[$13], A_FLOAT=[$14], A_DOUBLE=[$15], A_UNSIGNED_FLOAT=[$16], A_UNSIGNED_DOUBLE=[$17])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, IDX_FULL]], filter=[=($0, 'b')])\n")
-            .close();
-        start(true, 1000f).sql("select x_integer from aTable")
+                       "    PhoenixTableScan(table=[[phoenix, IDX_FULL]], filter=[=($0, 'b')])\n");
+        start1000.sql("select x_integer from aTable")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(X_INTEGER=[$10])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
+                       "    PhoenixTableScan(table=[[phoenix, ATABLE]])\n");
             /*.explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(X_INTEGER=[$4])\n" +
                        "    PhoenixTableScan(table=[[phoenix, IDX1]])\n")*/
-            .close();
-        start(true, 1000f).sql("select a_string from aTable order by a_string")
+        start1000.sql("select a_string from aTable order by a_string")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(A_STRING=[$0])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, IDX1]], scanOrder=[FORWARD])\n")
-            .close();
-        start(true, 1000000f).sql("select a_string from aTable order by organization_id")
+                       "    PhoenixTableScan(table=[[phoenix, IDX1]], scanOrder=[FORWARD])\n");
+        start1000000.sql("select a_string from aTable order by organization_id")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(A_STRING=[$2], ORGANIZATION_ID=[$0])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, ATABLE]], scanOrder=[FORWARD])\n")
-            .close();
-        start(true, 1000f).sql("select a_integer from aTable order by a_string")
+                       "    PhoenixTableScan(table=[[phoenix, ATABLE]], scanOrder=[FORWARD])\n");
+        start1000.sql("select a_integer from aTable order by a_string")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerSort(sort0=[$1], dir0=[ASC])\n" +
                        "    PhoenixServerProject(A_INTEGER=[$4], A_STRING=[$2])\n" +
-                       "      PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
+                       "      PhoenixTableScan(table=[[phoenix, ATABLE]])\n");
             /*.explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerSort(sort0=[$1], dir0=[ASC])\n" +
                        "    PhoenixServerProject(A_INTEGER=[$4], A_STRING=[$3])\n" +
                        "      PhoenixTableScan(table=[[phoenix, IDX_FULL]])\n")*/
-            .close();
-        start(true, 1000f).sql("select a_string, b_string from aTable where a_string = 'a'")
+        start1000.sql("select a_string, b_string from aTable where a_string = 'a'")
             .explainMatches("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject\\((0:)?A_STRING=\\[\\$0\\], (0:)?B_STRING=\\[\\$3\\]\\)\n" +
-                       "    PhoenixTableScan\\(table=\\[\\[phoenix, IDX1\\]\\], filter=\\[=\\(\\$0, 'a'\\)\\]\\)\n")
-            .close();
-        start(true, 1000f).sql("select a_string, b_string from aTable where b_string = 'b'")
+                       "    PhoenixTableScan\\(table=\\[\\[phoenix, IDX1\\]\\], filter=\\[=\\(\\$0, 'a'\\)\\]\\)\n");
+        start1000.sql("select a_string, b_string from aTable where b_string = 'b'")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(A_STRING=[$3], B_STRING=[$0])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, IDX2]], filter=[=($0, 'b')])\n")
-            .close();
-        start(true, 1000f).sql("select a_string, b_string, x_integer, y_integer from aTable where b_string = 'b'")
+                       "    PhoenixTableScan(table=[[phoenix, IDX2]], filter=[=($0, 'b')])\n");
+        start1000.sql("select a_string, b_string, x_integer, y_integer from aTable where b_string = 'b'")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(A_STRING=[$3], B_STRING=[$0], X_INTEGER=[$10], Y_INTEGER=[$11])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, IDX_FULL]], filter=[=($0, 'b')])\n")
-            .close();
-        start(true, 1000f).sql("select a_string, count(*) from aTable group by a_string")
+                       "    PhoenixTableScan(table=[[phoenix, IDX_FULL]], filter=[=($0, 'b')])\n");
+        start1000.sql("select a_string, count(*) from aTable group by a_string")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerAggregate(group=[{0}], EXPR$1=[COUNT()], isOrdered=[true])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, IDX1]], scanOrder=[FORWARD])\n")
-            .close();
+                       "    PhoenixTableScan(table=[[phoenix, IDX1]], scanOrder=[FORWARD])\n");
+
+        start1000.close();
+        start1000000.close();
     }
     
     @Test public void testSaltedIndex() throws Exception {
-        start(true, 1f).sql("select count(*) from " + NOSALT_TABLE_NAME + " where col0 > 3")
+        final Start start1 = start(true, 1f);
+        start1.sql("select count(*) from " + NOSALT_TABLE_NAME + " where col0 > 3")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerAggregate(group=[{}], EXPR$0=[COUNT()])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDXSALTED_NOSALT_TEST_TABLE]], filter=[>(CAST($0):INTEGER, 3)])\n")
-                .resultIs(0, new Object[][]{{999L}})
-                .close();
-        start(true, 1f).sql("select mypk0, mypk1, col0 from " + NOSALT_TABLE_NAME + " where col0 <= 4")
+                .resultIs(0, new Object[][]{{999L}});
+        start1.sql("select mypk0, mypk1, col0 from " + NOSALT_TABLE_NAME + " where col0 <= 4")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(MYPK0=[$1], MYPK1=[$2], COL0=[CAST($0):INTEGER])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDXSALTED_NOSALT_TEST_TABLE]], filter=[<=(CAST($0):INTEGER, 4)])\n")
                 .resultIs(0, new Object[][] {
                         {2, 3, 4},
-                        {1, 2, 3}})
-                .close();
-        start(true, 1f).sql("select * from " + SALTED_TABLE_NAME + " where mypk0 < 3")
+                        {1, 2, 3}});
+        start1.sql("select * from " + SALTED_TABLE_NAME + " where mypk0 < 3")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixTableScan(table=[[phoenix, SALTED_TEST_TABLE]], filter=[<($0, 3)])\n")
                 .resultIs(0, new Object[][] {
                         {1, 2, 3, 4},
-                        {2, 3, 4, 5}})
-                .close();
-        start(true, 1f).sql("select count(*) from " + SALTED_TABLE_NAME + " where col0 > 3")
+                        {2, 3, 4, 5}});
+        start1.sql("select count(*) from " + SALTED_TABLE_NAME + " where col0 > 3")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerAggregate(group=[{}], EXPR$0=[COUNT()])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDX_SALTED_TEST_TABLE]], filter=[>(CAST($0):INTEGER, 3)])\n")
                 .sameResultAsPhoenixStandalone(0)
-                /*.resultIs(0, new Object[][]{{999L}})*/
-                .close();
-        start(true, 1f).sql("select mypk0, mypk1, col0 from " + SALTED_TABLE_NAME + " where col0 <= 4")
+                /*.resultIs(0, new Object[][]{{999L}})*/;
+        start1.sql("select mypk0, mypk1, col0 from " + SALTED_TABLE_NAME + " where col0 <= 4")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(MYPK0=[$1], MYPK1=[$2], COL0=[CAST($0):INTEGER])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDX_SALTED_TEST_TABLE]], filter=[<=(CAST($0):INTEGER, 4)])\n")
                 .resultIs(0, new Object[][] {
                         {2, 3, 4},
-                        {1, 2, 3}})
-                .close();
-        start(true, 1f).sql("select count(*) from " + SALTED_TABLE_NAME + " where col1 > 4")
+                        {1, 2, 3}});
+        start1.sql("select count(*) from " + SALTED_TABLE_NAME + " where col1 > 4")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerAggregate(group=[{}], EXPR$0=[COUNT()])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDXSALTED_SALTED_TEST_TABLE]], filter=[>(CAST($0):INTEGER, 4)])\n")
                 .sameResultAsPhoenixStandalone(0)
-                /*.resultIs(0, new Object[][]{{999L}})*/
-                .close();
-        start(true, 1f).sql("select * from " + SALTED_TABLE_NAME + " where col1 <= 5 order by col1")
+                /*.resultIs(0, new Object[][]{{999L}})*/;
+        start1.sql("select * from " + SALTED_TABLE_NAME + " where col1 <= 5 order by col1")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(MYPK0=[$1], MYPK1=[$2], COL0=[$3], COL1=[CAST($0):INTEGER])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDXSALTED_SALTED_TEST_TABLE]], filter=[<=(CAST($0):INTEGER, 5)], scanOrder=[FORWARD])\n")
                 .resultIs(new Object[][] {
                         {1, 2, 3, 4},
-                        {2, 3, 4, 5}})
-                .close();
-        start(true, 1f).sql("select * from " + SALTED_TABLE_NAME + " s1, " + SALTED_TABLE_NAME + " s2 where s1.mypk0 = s2.mypk0 and s1.mypk1 = s2.mypk1 and s1.mypk0 > 500 and s2.col1 < 505")
+                        {2, 3, 4, 5}});
+        start1.sql("select * from " + SALTED_TABLE_NAME + " s1, " + SALTED_TABLE_NAME + " s2 where s1.mypk0 = s2.mypk0 and s1.mypk1 = s2.mypk1 and s1.mypk0 > 500 and s2.col1 < 505")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixClientProject(MYPK0=[$4], MYPK1=[$5], COL0=[$6], COL1=[$7], MYPK00=[$0], MYPK10=[$1], COL00=[$2], COL10=[$3])\n" +
                            "    PhoenixServerJoin(condition=[AND(=($4, $0), =($5, $1))], joinType=[inner])\n" +
@@ -151,47 +142,53 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                            "    PhoenixServerProject(MYPK0=[$1], MYPK1=[$2], COL0=[$3], COL1=[CAST($0):INTEGER])\n" +
                            "      PhoenixTableScan(table=[[phoenix, IDXSALTED_SALTED_TEST_TABLE]], filter=[<(CAST($0):INTEGER, 505)])\n")*/
                 .resultIs(0, new Object[][] {
-                        {501, 502, 503, 504, 501, 502, 503, 504}})
-                .close();
+                        {501, 502, 503, 504, 501, 502, 503, 504}});
+        start1.close();
     }
     
     @Test public void testMultiTenant() throws Exception {
         Properties props = getConnectionProps(true, 1f);
-        start(props).sql("select * from " + MULTI_TENANT_TABLE + " where tenant_id = '10' and id <= '0004'")
+        final Start start = start(props);
+        props = getConnectionProps(true, 1f);
+        props.setProperty("TenantId", "15");
+        final Start startTenant15 = start(props);
+        props = getConnectionProps(true, 1f);
+        props.setProperty("TenantId", "10");
+        final Start startTenant10 = start(props);
+        props = getConnectionProps(true, 1f);
+        props.setProperty("TenantId", "20");
+        final Start startTenant20 = start(props);
+
+        start.sql("select * from " + MULTI_TENANT_TABLE + " where tenant_id = '10' and id <= '0004'")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixTableScan(table=[[phoenix, MULTITENANT_TEST_TABLE]], filter=[AND(=(CAST($0):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL, '10'), <=($1, '0004'))])\n")
                 .resultIs(0, new Object[][] {
                         {"10", "0002", 3, 4, 5},
                         {"10", "0003", 4, 5, 6},
-                        {"10", "0004", 5, 6, 7}})
-                .close();
+                        {"10", "0004", 5, 6, 7}});
         
-        start(props).sql("select * from " + MULTI_TENANT_TABLE + " where tenant_id = '20' and col1 < 8")
+        start.sql("select * from " + MULTI_TENANT_TABLE + " where tenant_id = '20' and col1 < 8")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(TENANT_ID=[$0], ID=[$2], COL0=[$3], COL1=[CAST($1):INTEGER], COL2=[$4])\n" +
-                           "    PhoenixTableScan(table=[[phoenix, IDX_MULTITENANT_TEST_TABLE]], filter=[AND(=(CAST($0):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL, '20'), <(CAST($1):INTEGER, 8))])\n")
+                           "    PhoenixTableScan(table=[[phoenix, IDX_MULTITENANT_TEST_TABLE]], filter=[AND(=(CAST($0):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL, '20'), <(CAST($1):INTEGER, 8))])\n");
 //                .resultIs(0, new Object[][] {
 //                        {"20", "0004", 5, 6, 7},
-//                        {"20", "0005", 6, 7, 8}})
-                .close();
+//                        {"20", "0005", 6, 7, 8}});
         
         try {
-            start(props).sql("select * from " + MULTI_TENANT_VIEW1)
-                .explainIs("")
-                .close();
+            start.sql("select * from " + MULTI_TENANT_VIEW1)
+                .explainIs("");
             fail("Should have got SQLException.");
         } catch (SQLException e) {
         }
         
-        props.setProperty("TenantId", "15");
-        start(props).sql("select * from " + MULTI_TENANT_TABLE + " where id = '0284'")
+        startTenant15.sql("select * from " + MULTI_TENANT_TABLE + " where id = '0284'")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixTableScan(table=[[phoenix, MULTITENANT_TEST_TABLE]], filter=[=(CAST($0):VARCHAR(4) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL, '0284')])\n")
                 .resultIs(0, new Object[][] {
-                        {"0284", 285, 286, 287}})
-                .close();
+                        {"0284", 285, 286, 287}});
         
-        start(props).sql("select * from " + MULTI_TENANT_TABLE + " where col1 > 1000")
+        startTenant15.sql("select * from " + MULTI_TENANT_TABLE + " where col1 > 1000")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ID=[$1], COL0=[$2], COL1=[CAST($0):INTEGER], COL2=[$3])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDX_MULTITENANT_TEST_TABLE]], filter=[>(CAST($0):INTEGER, 1000)])\n")
@@ -199,26 +196,22 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                         {"0999", 1000, 1001, 1002},
                         {"1000", 1001, 1002, 1003},
                         {"1001", 1002, 1003, 1004},
-                        {"1002", 1003, 1004, 1005}})
-                .close();
+                        {"1002", 1003, 1004, 1005}});
         
         try {
-            start(props).sql("select * from " + MULTI_TENANT_VIEW1)
-                .explainIs("")
-                .close();
+            startTenant15.sql("select * from " + MULTI_TENANT_VIEW1)
+                .explainIs("");
             fail("Should have got SQLException.");
         } catch (SQLException e) {
         }
 
-        props.setProperty("TenantId", "10");
-        start(props).sql("select * from " + MULTI_TENANT_VIEW1 + " where id = '0512'")
+        startTenant10.sql("select * from " + MULTI_TENANT_VIEW1 + " where id = '0512'")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixTableScan(table=[[phoenix, MULTITENANT_TEST_TABLE]], filter=[=(CAST($0):VARCHAR(4) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL, '0512')])\n")
                 .resultIs(0, new Object[][] {
-                        {"0512", 513, 514, 515}})
-                .close();
+                        {"0512", 513, 514, 515}});
         
-        start(props).sql("select * from " + MULTI_TENANT_TABLE + " where col1 <= 6")
+        startTenant10.sql("select * from " + MULTI_TENANT_TABLE + " where col1 <= 6")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ID=[$1], COL0=[$2], COL1=[CAST($0):INTEGER], COL2=[$3])\n" +
                            "    PhoenixTableScan(table=[[phoenix, IDX_MULTITENANT_TEST_TABLE]], filter=[<=(CAST($0):INTEGER, 6)])\n")
@@ -226,10 +219,9 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                 /*.resultIs(0, new Object[][] {
                         {"0002", 3, 4, 5},
                         {"0003", 4, 5, 6},
-                        {"0004", 5, 6, 7}})*/
-                .close();
+                        {"0004", 5, 6, 7}})*/;
         
-        start(props).sql("select id, col0 from " + MULTI_TENANT_VIEW1 + " where col0 >= 1000")
+        startTenant10.sql("select id, col0 from " + MULTI_TENANT_VIEW1 + " where col0 >= 1000")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ID=[$1], COL0=[CAST($0):INTEGER])\n" +
                            "    PhoenixTableScan(table=[[phoenix, S1, IDX_MULTITENANT_TEST_VIEW1]], filter=[>=(CAST($0):INTEGER, 1000)])\n")
@@ -237,36 +229,31 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                 /*.resultIs(0, new Object[][] {
                         {"0999", 1000},
                         {"1000", 1001},
-                        {"1001", 1002}})*/
-                .close();
+                        {"1001", 1002}})*/;
         
-        start(props).sql("select * from " + MULTI_TENANT_VIEW1 + " where col0 = 1000")
+        startTenant10.sql("select * from " + MULTI_TENANT_VIEW1 + " where col0 = 1000")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ID=[$1], COL0=[CAST($0):INTEGER], COL1=[$2], COL2=[$3])\n" +
                            "    PhoenixTableScan(table=[[phoenix, S1, IDX_MULTITENANT_TEST_VIEW1]], filter=[=(CAST($0):INTEGER, 1000)], extendedColumns=[{2, 3}])\n")
                 .sameResultAsPhoenixStandalone(0)
                 /*.resultIs(0, new Object[][] {
-                        {"0999", 1000, 1001, 1002}})*/
-                .close();
+                        {"0999", 1000, 1001, 1002}})*/;
         
-        start(props).sql("select id, col0, col2 from " + MULTI_TENANT_VIEW1 + " where col0 = 1000")
+        startTenant10.sql("select id, col0, col2 from " + MULTI_TENANT_VIEW1 + " where col0 = 1000")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ID=[$1], COL0=[CAST($0):INTEGER], COL2=[$3])\n" +
                            "    PhoenixTableScan(table=[[phoenix, S1, IDX_MULTITENANT_TEST_VIEW1]], filter=[=(CAST($0):INTEGER, 1000)], extendedColumns=[{3}])\n")
                 .sameResultAsPhoenixStandalone(0)
                 /*.resultIs(0, new Object[][] {
-                        {"0999", 1000, 1002}})*/
-                .close();
+                        {"0999", 1000, 1002}})*/;
 
-        props.setProperty("TenantId", "20");
-        start(props).sql("select * from " + MULTI_TENANT_VIEW2 + " where id = '0765'")
+        startTenant20.sql("select * from " + MULTI_TENANT_VIEW2 + " where id = '0765'")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixTableScan(table=[[phoenix, MULTITENANT_TEST_TABLE]], filter=[AND(>($3, 7), =(CAST($0):VARCHAR(4) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL, '0765'))])\n")
                 .resultIs(0, new Object[][] {
-                        {"0765", 766, 767, 768}})
-                .close();
+                        {"0765", 766, 767, 768}});
         
-        start(props).sql("select id, col0 from " + MULTI_TENANT_VIEW2 + " where col0 between 272 and 275")
+        startTenant20.sql("select id, col0 from " + MULTI_TENANT_VIEW2 + " where col0 between 272 and 275")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ID=[$1], COL0=[CAST($0):INTEGER])\n" +
                            "    PhoenixTableScan(table=[[phoenix, S2, IDX_MULTITENANT_TEST_VIEW2]], filter=[AND(>=(CAST($0):INTEGER, 272), <=(CAST($0):INTEGER, 275))])\n")
@@ -275,10 +262,9 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                         {"0271", 272},
                         {"0272", 273},
                         {"0273", 274},
-                        {"0274", 275}})*/
-                .close();
+                        {"0274", 275}})*/;
         
-        start(props).sql("select id, col0 from " + MULTI_TENANT_VIEW2 + " order by col0 limit 5")
+        startTenant20.sql("select id, col0 from " + MULTI_TENANT_VIEW2 + " order by col0 limit 5")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixLimit(fetch=[5])\n" +
                            "    PhoenixServerProject(ID=[$1], COL0=[CAST($0):INTEGER])\n" +
@@ -289,8 +275,12 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                         {"0006", 7},
                         {"0007", 8},
                         {"0008", 9},
-                        {"0009", 10}})*/
-                .close();
+                        {"0009", 10}})*/;
+
+        start.close();
+        startTenant15.close();
+        startTenant10.close();
+        startTenant20.close();        
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/78c13b77/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
index 6b00f04..054d7eb 100644
--- a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
+++ b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
@@ -131,9 +131,16 @@ public class PhoenixCalciteFactory extends CalciteFactory {
             hooks.add(Hook.PARSE_TREE.add(new Function<Object[], Object>() {
                 @Override
                 public Object apply(Object[] input) {
-                    // TODO Auto-generated method stub
+                    for (CalciteSchema schema : rootSchema.getSubSchemaMap().values()) {
+                        if (schema.schema instanceof PhoenixSchema) {
+                            ((PhoenixSchema) schema.schema).clear();
+                            for (CalciteSchema subSchema : schema.getSubSchemaMap().values()) {
+                                ((PhoenixSchema) subSchema.schema).clear();
+                            }
+                        }
+                    }
                     return null;
-                }            
+                }
             }));
 
             hooks.add(Hook.TRIMMED.add(new Function<RelNode, Object>() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/78c13b77/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index 8606588..2f42cfd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -215,7 +215,13 @@ public class PhoenixSchema implements Schema {
 
     @Override
     public boolean contentsHaveChangedSince(long lastCheck, long now) {
-        return false;
+        return lastCheck != now;
+    }
+    
+    public void clear() {
+        tables.clear();
+        views.clear();
+        viewTables.clear();
     }
     
     public void defineIndexesAsMaterializations() {


[3/4] phoenix git commit: Minimize life cycle of hooks

Posted by ma...@apache.org.
Minimize life cycle of hooks


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

Branch: refs/heads/calcite
Commit: 88dd213a958e7143ca4ca81c2e4d2fb2d367af3a
Parents: b41c0a8
Author: maryannxue <ma...@gmail.com>
Authored: Mon Oct 3 17:31:33 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Mon Oct 3 17:31:33 2016 -0700

----------------------------------------------------------------------
 .../calcite/jdbc/PhoenixCalciteFactory.java     | 53 ------------
 .../phoenix/calcite/PhoenixPrepareImpl.java     | 88 ++++++++++++++++++++
 2 files changed, 88 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/88dd213a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
index 054d7eb..776a06e 100644
--- a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
+++ b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
@@ -35,24 +35,14 @@ import org.apache.calcite.jdbc.CalciteFactory;
 import org.apache.calcite.jdbc.Driver;
 import org.apache.calcite.linq4j.Enumerable;
 import org.apache.calcite.linq4j.Ord;
-import org.apache.calcite.prepare.Prepare.Materialization;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.runtime.Hook;
-import org.apache.calcite.runtime.Hook.Closeable;
 import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.tools.Program;
-import org.apache.calcite.tools.Programs;
-import org.apache.calcite.util.Holder;
 import org.apache.phoenix.calcite.PhoenixSchema;
-import org.apache.phoenix.calcite.rel.PhoenixRel;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.execute.RuntimeContext;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 
-import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 public class PhoenixCalciteFactory extends CalciteFactory {
@@ -121,51 +111,11 @@ public class PhoenixCalciteFactory extends CalciteFactory {
     private static class PhoenixCalciteConnection extends CalciteConnectionImpl {
         private final Map<Meta.StatementHandle, ImmutableList<RuntimeContext>> runtimeContextMap =
                 new ConcurrentHashMap<Meta.StatementHandle, ImmutableList<RuntimeContext>>();
-        private final List<Closeable> hooks = Lists.newArrayList();
         
         public PhoenixCalciteConnection(Driver driver, AvaticaFactory factory, String url,
                 Properties info, final CalciteSchema rootSchema,
                 JavaTypeFactory typeFactory) {
             super(driver, factory, url, info, rootSchema, typeFactory);
-
-            hooks.add(Hook.PARSE_TREE.add(new Function<Object[], Object>() {
-                @Override
-                public Object apply(Object[] input) {
-                    for (CalciteSchema schema : rootSchema.getSubSchemaMap().values()) {
-                        if (schema.schema instanceof PhoenixSchema) {
-                            ((PhoenixSchema) schema.schema).clear();
-                            for (CalciteSchema subSchema : schema.getSubSchemaMap().values()) {
-                                ((PhoenixSchema) subSchema.schema).clear();
-                            }
-                        }
-                    }
-                    return null;
-                }
-            }));
-
-            hooks.add(Hook.TRIMMED.add(new Function<RelNode, Object>() {
-                @Override
-                public Object apply(RelNode root) {
-                    for (CalciteSchema schema : rootSchema.getSubSchemaMap().values()) {
-                        if (schema.schema instanceof PhoenixSchema) {
-                            ((PhoenixSchema) schema.schema).defineIndexesAsMaterializations();
-                            for (CalciteSchema subSchema : schema.getSubSchemaMap().values()) {
-                                ((PhoenixSchema) subSchema.schema).defineIndexesAsMaterializations();
-                            }
-                        }
-                    }
-                    return null;
-                }
-            }));
-
-            hooks.add(Hook.PROGRAM.add(new Function<org.apache.calcite.util.Pair<List<Materialization>, Holder<Program>>, Object>() {
-                @Override
-                public Object apply(
-                        org.apache.calcite.util.Pair<List<Materialization>, Holder<Program>> input) {
-                    input.getValue().set(Programs.standard(PhoenixRel.METADATA_PROVIDER));
-                    return null;
-                }
-            }));
         }
 
         public <T> Enumerable<T> enumerable(Meta.StatementHandle handle,
@@ -280,9 +230,6 @@ public class PhoenixCalciteFactory extends CalciteFactory {
                 public void call(PhoenixConnection conn) throws SQLException {
                     conn.close();
                 }});
-            for (Closeable hook : hooks) {
-                hook.close();
-            }
             super.close();
         }
         

http://git-wip-us.apache.org/repos/asf/phoenix/blob/88dd213a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
index 2d6a84c..b5461ce 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
@@ -1,5 +1,6 @@
 package org.apache.phoenix.calcite;
 
+import java.lang.reflect.Type;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.List;
@@ -7,16 +8,22 @@ import java.util.Map;
 
 import org.apache.calcite.adapter.enumerable.EnumerableRules;
 import org.apache.calcite.jdbc.CalcitePrepare;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.linq4j.Queryable;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptCostFactory;
 import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.plan.RelOptRule;
 import org.apache.calcite.prepare.CalcitePrepareImpl;
+import org.apache.calcite.prepare.Prepare.Materialization;
+import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.logical.LogicalSort;
 import org.apache.calcite.rel.rules.JoinCommuteRule;
 import org.apache.calcite.rel.rules.SortProjectTransposeRule;
 import org.apache.calcite.rel.rules.SortUnionTransposeRule;
 import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.runtime.Hook.Closeable;
 import org.apache.calcite.schema.SchemaPlus;
 import org.apache.calcite.sql.SqlColumnDefInPkConstraintNode;
 import org.apache.calcite.sql.SqlColumnDefNode;
@@ -30,6 +37,9 @@ import org.apache.calcite.sql.SqlOptionNode;
 import org.apache.calcite.sql.parser.SqlParser;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.parser.SqlParserUtil;
+import org.apache.calcite.tools.Program;
+import org.apache.calcite.tools.Programs;
+import org.apache.calcite.util.Holder;
 import org.apache.calcite.util.NlsString;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.calcite.parse.SqlCreateIndex;
@@ -82,6 +92,7 @@ import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.SortOrder;
 
+import com.google.common.base.Function;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Lists;
@@ -151,6 +162,83 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
         return planner;
     }
 
+    public <T> CalciteSignature<T> prepareQueryable(
+            Context context,
+            Queryable<T> queryable) {
+        List<Closeable> hooks = addHooks(
+                context.getRootSchema(),
+                context.config().materializationsEnabled());
+        try {
+            return super.prepareQueryable(context, queryable);
+        } finally {
+            for (Closeable hook : hooks) {
+                hook.close();
+            }
+        }
+    }
+
+    public <T> CalciteSignature<T> prepareSql(
+            Context context,
+            Query<T> query,
+            Type elementType,
+            long maxRowCount) {
+        List<Closeable> hooks = addHooks(
+                context.getRootSchema(),
+                context.config().materializationsEnabled());
+        try {
+            return super.prepareSql(context, query, elementType, maxRowCount);
+        } finally {
+            for (Closeable hook : hooks) {
+                hook.close();
+            }
+        }
+    }
+    
+    private List<Closeable> addHooks(final CalciteSchema rootSchema, boolean materializationEnabled) {
+        final List<Closeable> hooks = Lists.newArrayList();
+
+        hooks.add(Hook.PARSE_TREE.add(new Function<Object[], Object>() {
+            @Override
+            public Object apply(Object[] input) {
+                for (CalciteSchema schema : rootSchema.getSubSchemaMap().values()) {
+                    if (schema.schema instanceof PhoenixSchema) {
+                        ((PhoenixSchema) schema.schema).clear();
+                        for (CalciteSchema subSchema : schema.getSubSchemaMap().values()) {
+                            ((PhoenixSchema) subSchema.schema).clear();
+                        }
+                    }
+                }
+                return null;
+            }
+        }));
+
+        hooks.add(Hook.TRIMMED.add(new Function<RelNode, Object>() {
+            @Override
+            public Object apply(RelNode root) {
+                for (CalciteSchema schema : rootSchema.getSubSchemaMap().values()) {
+                    if (schema.schema instanceof PhoenixSchema) {
+                        ((PhoenixSchema) schema.schema).defineIndexesAsMaterializations();
+                        for (CalciteSchema subSchema : schema.getSubSchemaMap().values()) {
+                            ((PhoenixSchema) subSchema.schema).defineIndexesAsMaterializations();
+                        }
+                    }
+                }
+                return null;
+            }
+        }));
+
+        hooks.add(Hook.PROGRAM.add(new Function<org.apache.calcite.util.Pair<List<Materialization>, Holder<Program>>, Object>() {
+            @Override
+            public Object apply(
+                    org.apache.calcite.util.Pair<List<Materialization>, Holder<Program>> input) {
+                input.getValue().set(Programs.standard(PhoenixRel.METADATA_PROVIDER));
+                return null;
+            }
+        }));
+        
+        return hooks;
+    }
+
     @Override
     public void executeDdl(Context context, SqlNode node) {
         try {


[2/4] phoenix git commit: Remove warnings

Posted by ma...@apache.org.
Remove warnings


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

Branch: refs/heads/calcite
Commit: b41c0a81b7e78dff6df68be8865ae4cf9ec56ba7
Parents: 78c13b7
Author: maryannxue <ma...@gmail.com>
Authored: Mon Oct 3 16:46:27 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Mon Oct 3 16:46:27 2016 -0700

----------------------------------------------------------------------
 .../src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java       | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b41c0a81/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
index 9891bd0..75bce4c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/BaseCalciteIT.java
@@ -39,7 +39,6 @@ import java.text.DecimalFormat;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.regex.Pattern;
 
 import org.apache.calcite.avatica.util.ArrayImpl;
 import org.apache.calcite.config.CalciteConnectionProperty;


[4/4] phoenix git commit: Temporary fix for [PHOENIX-3357] Issue with column re-ordering in column family support for Calcite-Phoenix

Posted by ma...@apache.org.
Temporary fix for [PHOENIX-3357] Issue with column re-ordering in column family support for Calcite-Phoenix


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

Branch: refs/heads/calcite
Commit: 68717c05418e115c35fd5e27e18e4f9188450c25
Parents: 88dd213
Author: maryannxue <ma...@gmail.com>
Authored: Thu Oct 6 12:37:00 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Thu Oct 6 12:37:00 2016 -0700

----------------------------------------------------------------------
 .../src/it/java/org/apache/phoenix/end2end/OrderByIT.java      | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/68717c05/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
index 0f6641c..0e7b470 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
@@ -195,7 +195,7 @@ public class OrderByIT extends ParallelStatsDisabledIT {
                     "  (a_string varchar not null, cf1.a integer, cf1.b varchar, col1 integer, cf2.c varchar, cf2.d integer, col2 integer" +
                     "  CONSTRAINT pk PRIMARY KEY (a_string))\n";
             createTestTable(getUrl(), ddl);
-            String dml = "UPSERT INTO " + tableName + " VALUES(?,?,?,?,?,?,?)";
+            String dml = "UPSERT INTO " + tableName + "(a_string, a, b, col1, c, d, col2) VALUES(?,?,?,?,?,?,?)";
             PreparedStatement stmt = conn.prepareStatement(dml);
             stmt.setString(1, "a");
             stmt.setInt(2, 40);
@@ -223,7 +223,7 @@ public class OrderByIT extends ParallelStatsDisabledIT {
             stmt.execute();
             conn.commit();
 
-            String query = "select * from " + tableName + " order by 2, 5";
+            String query = "select a_string, a, b, col1, c, d, col2 from " + tableName + " order by 2, 5";
             ResultSet rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("c",rs.getString(1));
@@ -251,7 +251,7 @@ public class OrderByIT extends ParallelStatsDisabledIT {
             assertEquals(1,rs.getInt(7));         
             assertFalse(rs.next());  
 
-            query = "select * from " + tableName + " order by 7";
+            query = "select a_string, a, b, col1, c, d, col2 from " + tableName + " order by 7";
             rs = conn.createStatement().executeQuery(query);
             assertTrue(rs.next());
             assertEquals("a",rs.getString(1));