PHOENIX-1489 Access column values positionally from client
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3f829751 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3f829751 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3f829751 Branch: refs/heads/calcite Commit: 3f829751dd5158c526e5c5bd3da61dde1c6e4194 Parents: 0440aca Author: maryannxue <wei....@intel.com> Authored: Tue Mar 3 12:12:49 2015 -0500 Committer: maryannxue <wei....@intel.com> Committed: Tue Mar 3 12:12:49 2015 -0500 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/HashJoinIT.java | 55 ++-- .../phoenix/end2end/HashJoinLocalIndexIT.java | 6 +- .../org/apache/phoenix/end2end/SubqueryIT.java | 30 +-- .../end2end/SubqueryUsingSortMergeJoinIT.java | 32 +-- .../index/GlobalIndexOptimizationIT.java | 22 +- .../phoenix/end2end/index/LocalIndexIT.java | 4 +- .../phoenix/compile/ExpressionCompiler.java | 2 +- .../apache/phoenix/compile/FromCompiler.java | 87 ++++++- .../apache/phoenix/compile/JoinCompiler.java | 258 ++++--------------- .../apache/phoenix/compile/OrderByCompiler.java | 2 +- .../phoenix/compile/ProjectionCompiler.java | 58 +++-- .../apache/phoenix/compile/QueryCompiler.java | 115 +++++---- .../compile/TupleProjectionCompiler.java | 214 +++++++++++++++ .../apache/phoenix/compile/UpsertCompiler.java | 4 +- .../apache/phoenix/compile/WhereCompiler.java | 2 +- .../coprocessor/BaseScannerRegionObserver.java | 21 +- .../GroupedAggregateRegionObserver.java | 11 +- .../coprocessor/HashJoinRegionScanner.java | 72 +++--- .../phoenix/coprocessor/ScanRegionObserver.java | 9 +- .../UngroupedAggregateRegionObserver.java | 10 +- .../apache/phoenix/execute/TupleProjector.java | 18 +- .../org/apache/phoenix/join/HashJoinInfo.java | 25 +- .../apache/phoenix/optimize/QueryOptimizer.java | 19 +- .../org/apache/phoenix/schema/ColumnRef.java | 2 +- .../phoenix/schema/LocalIndexDataColumnRef.java | 9 +- .../apache/phoenix/schema/MetaDataClient.java | 2 +- .../org/apache/phoenix/schema/PTableType.java | 2 +- .../apache/phoenix/schema/ProjectedColumn.java | 59 +++++ .../org/apache/phoenix/schema/TableRef.java | 8 +- .../phoenix/compile/WhereCompilerTest.java | 6 +- 30 files changed, 691 insertions(+), 473 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java index e915b36..596e5e9 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java @@ -219,7 +219,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " SERVER FILTER BY QUANTITY < 5000\n" + " PARALLEL INNER-JOIN TABLE 1\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"O.item_id\")", + " DYNAMIC SERVER FILTER BY \"I.item_id\" IN (\"O.item_id\")", /* * testSelfJoin() * SELECT i2.item_id, i1.name FROM joinItemTable i1 @@ -230,7 +230,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"I2.item_id\")", + " DYNAMIC SERVER FILTER BY \"I1.item_id\" IN (\"I2.item_id\")", /* * testSelfJoin() * SELECT i1.name, i2.name FROM joinItemTable i1 @@ -242,7 +242,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { "CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"I2.supplier_id\")", + " DYNAMIC SERVER FILTER BY \"I1.item_id\" IN (\"I2.supplier_id\")", /* * testStarJoin() * SELECT order_id, c.name, i.name iname, quantity, o.date @@ -271,7 +271,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_CUSTOMER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"O.item_id\")", + " DYNAMIC SERVER FILTER BY \"I.item_id\" IN (\"O.item_id\")", /* * testSubJoin() * SELECT * FROM joinCustomerTable c @@ -296,7 +296,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " SERVER FILTER BY NAME != 'T3'\n" + " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"customer_id\" IN (\"O.customer_id\")", + " DYNAMIC SERVER FILTER BY \"C.customer_id\" IN (\"O.customer_id\")", /* * testJoinWithSubqueryAndAggregation() * SELECT i.name, sum(quantity) FROM joinOrderTable o @@ -416,7 +416,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + " PARALLEL INNER-JOIN TABLE 1(DELAYED EVALUATION)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"supplier_id\" IN (\"I.supplier_id\")\n" + + " DYNAMIC SERVER FILTER BY \"S.supplier_id\" IN (\"I.supplier_id\")\n" + " JOIN-SCANNER 4 ROW LIMIT", /* * testJoinWithKeyRangeOptimization() @@ -440,7 +440,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY COL0 IN (RHS.COL2)", + " DYNAMIC SERVER FILTER BY LHS.COL0 IN (RHS.COL2)", /* * testJoinWithKeyRangeOptimization() * SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2 @@ -452,7 +452,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY (COL0, COL1) IN ((RHS.COL1, RHS.COL2))", + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1) IN ((RHS.COL1, RHS.COL2))", /* * testJoinWithKeyRangeOptimization() * SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2 @@ -464,7 +464,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY (COL0, COL1, COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1, LHS.COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", /* * testJoinWithSetMaxRows() * statement.setMaxRows(4); @@ -478,7 +478,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { "CLIENT 4 ROW LIMIT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"O.item_id\")\n" + + " DYNAMIC SERVER FILTER BY \"I.item_id\" IN (\"O.item_id\")\n" + " JOIN-SCANNER 4 ROW LIMIT", }}); testCases.add(new String[][] { @@ -608,7 +608,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"I2.:item_id\")", + " DYNAMIC SERVER FILTER BY \"I1.item_id\" IN (\"I2.:item_id\")", /* * testSelfJoin() * SELECT i1.name, i2.name FROM joinItemTable i1 @@ -677,7 +677,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " SERVER FILTER BY \"NAME\" != 'T3'\n" + " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"customer_id\" IN (\"O.customer_id\")", + " DYNAMIC SERVER FILTER BY \"C.customer_id\" IN (\"O.customer_id\")", /* * testJoinWithSubqueryAndAggregation() * SELECT i.name, sum(quantity) FROM joinOrderTable o @@ -798,7 +798,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_SCHEMA + ".idx_item\n" + " PARALLEL INNER-JOIN TABLE 1(DELAYED EVALUATION)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"supplier_id\" IN (\"I.0:supplier_id\")\n" + + " DYNAMIC SERVER FILTER BY \"S.supplier_id\" IN (\"I.0:supplier_id\")\n" + " JOIN-SCANNER 4 ROW LIMIT", /* * testJoinWithKeyRangeOptimization() @@ -822,7 +822,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY COL0 IN (RHS.COL2)", + " DYNAMIC SERVER FILTER BY LHS.COL0 IN (RHS.COL2)", /* * testJoinWithKeyRangeOptimization() * SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2 @@ -834,7 +834,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY (COL0, COL1) IN ((RHS.COL1, RHS.COL2))", + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1) IN ((RHS.COL1, RHS.COL2))", /* * testJoinWithKeyRangeOptimization() * SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2 @@ -846,7 +846,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY (COL0, COL1, COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1, LHS.COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", /* * testJoinWithSetMaxRows() * statement.setMaxRows(4); @@ -918,9 +918,8 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { */ "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + "" + JOIN_ITEM_TABLE_DISPLAY_NAME+" [-32768]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY [\"I.0:NAME\"]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY [\"I.0:NAME\"]\n" + "CLIENT MERGE SORT\n" + - "CLIENT SORTED BY [\"I.0:NAME\"]\n" + " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME, /* @@ -989,7 +988,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + "" + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + " [-32768]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"O.item_id\")", + " DYNAMIC SERVER FILTER BY \"I.:item_id\" IN (\"O.item_id\")", /* * testSelfJoin() * SELECT i2.item_id, i1.name FROM joinItemTable i1 @@ -1001,7 +1000,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY RANGE SCAN OVER "+ MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX +""+ JOIN_ITEM_TABLE_DISPLAY_NAME +" [-32768]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"I2.:item_id\")", + " DYNAMIC SERVER FILTER BY \"I1.item_id\" IN (\"I2.:item_id\")", /* * testSelfJoin() * SELECT i1.name, i2.name FROM joinItemTable i1 @@ -1015,7 +1014,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX +""+ JOIN_ITEM_TABLE_DISPLAY_NAME +" [-32768]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"I2.0:supplier_id\")", + " DYNAMIC SERVER FILTER BY \"I1.:item_id\" IN (\"I2.0:supplier_id\")", /* * testStarJoin() * SELECT order_id, c.name, i.name iname, quantity, o.date @@ -1051,7 +1050,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + "" + JOIN_CUSTOMER_TABLE_DISPLAY_NAME+" [-32768]\n"+ " SERVER FILTER BY FIRST KEY ONLY\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"O.item_id\")", + " DYNAMIC SERVER FILTER BY \"I.:item_id\" IN (\"O.item_id\")", /* * testSubJoin() * SELECT * FROM joinCustomerTable c @@ -1077,7 +1076,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT MERGE SORT\n" + " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"customer_id\" IN (\"O.customer_id\")", + " DYNAMIC SERVER FILTER BY \"C.customer_id\" IN (\"O.customer_id\")", /* * testJoinWithSubqueryAndAggregation() * SELECT i.name, sum(quantity) FROM joinOrderTable o @@ -1203,7 +1202,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 1(DELAYED EVALUATION)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"supplier_id\" IN (\"I.0:supplier_id\")\n" + + " DYNAMIC SERVER FILTER BY \"S.supplier_id\" IN (\"I.0:supplier_id\")\n" + " JOIN-SCANNER 4 ROW LIMIT", /* * testJoinWithKeyRangeOptimization() @@ -1227,7 +1226,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY COL0 IN (RHS.COL2)", + " DYNAMIC SERVER FILTER BY LHS.COL0 IN (RHS.COL2)", /* * testJoinWithKeyRangeOptimization() * SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2 @@ -1239,7 +1238,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY (COL0, COL1) IN ((RHS.COL1, RHS.COL2))", + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1) IN ((RHS.COL1, RHS.COL2))", /* * testJoinWithKeyRangeOptimization() * SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2 @@ -1251,7 +1250,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY (COL0, COL1, COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1, LHS.COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", /* * testJoinWithSetMaxRows() * statement.setMaxRows(4); @@ -1267,7 +1266,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT { "CLIENT 4 ROW LIMIT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN (\"O.item_id\")\n" + + " DYNAMIC SERVER FILTER BY \"I.:item_id\" IN (\"O.item_id\")\n" + " JOIN-SCANNER 4 ROW LIMIT", }}); return testCases; http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinLocalIndexIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinLocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinLocalIndexIT.java index 2d0cc72..645d21b 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinLocalIndexIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinLocalIndexIT.java @@ -105,17 +105,17 @@ public class HashJoinLocalIndexIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " [-32768,*] - [-32768,'T6']\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"supplier_id\" IN (\"I.0:supplier_id\")", + " DYNAMIC SERVER FILTER BY \"S.:supplier_id\" IN (\"I.supplier_id\")", "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + " [-32768,'S1']\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY [\"S.0:PHONE\"]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY [\"S.PHONE\"]\n" + "CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " [-32768,*] - [-32768,'T6']\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"supplier_id\" IN (\"I.0:supplier_id\")", + " DYNAMIC SERVER FILTER BY \"S.:supplier_id\" IN (\"I.supplier_id\")", "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + " [-32768,*] - [-32768,'S3']\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java index 7bc97e7..f655e0a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java @@ -113,7 +113,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + " \\['000000000000001'\\] - \\[\\*\\]\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\\$\\d+.\\$\\d+\\)", + " DYNAMIC SERVER FILTER BY \"I.item_id\" IN \\(\\$\\d+.\\$\\d+\\)", "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + "\n" + " SERVER SORTED BY [I.NAME]\n" + @@ -129,7 +129,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { "CLIENT MERGE SORT\n" + " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\", NAME\\]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\".+.item_id\", .+.NAME\\]\n" + " CLIENT MERGE SORT\n" + " PARALLEL ANTI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + @@ -137,17 +137,17 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " CLIENT MERGE SORT\n" + " PARALLEL LEFT-JOIN TABLE 1\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\", NAME\\]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\".+.item_id\", .+.NAME\\]\n" + " CLIENT MERGE SORT\n" + " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + + " DYNAMIC SERVER FILTER BY \"" + JOIN_ITEM_TABLE_DISPLAY_NAME + ".item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + " AFTER-JOIN SERVER FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+ IS NOT NULL\\)", "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + - " SERVER SORTED BY [NAME]\n" + + " SERVER SORTED BY [I.NAME]\n" + "CLIENT MERGE SORT\n" + " PARALLEL ANTI-JOIN TABLE 0 (SKIP MERGE)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + @@ -165,9 +165,9 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\"O.item_id\"\\)\n" + + " DYNAMIC SERVER FILTER BY \"I.item_id\" IN \\(\"O.item_id\"\\)\n" + " AFTER-JOIN SERVER FILTER BY \\(I.NAME = 'T2' OR O.QUANTITY > \\$\\d+.\\$\\d+\\)\n" + - " DYNAMIC SERVER FILTER BY \"customer_id\" IN \\(\\$\\d+.\\$\\d+\\)" + " DYNAMIC SERVER FILTER BY \"" + JOIN_CUSTOMER_TABLE_DISPLAY_NAME + ".customer_id\" IN \\(\\$\\d+.\\$\\d+\\)" }}); testCases.add(new String[][] { { @@ -200,7 +200,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + " PARALLEL ANTI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + @@ -209,7 +209,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " PARALLEL LEFT-JOIN TABLE 1\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + " PARALLEL SEMI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + @@ -255,7 +255,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + " \\['000000000000001'\\] - \\[\\*\\]\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\\$\\d+.\\$\\d+\\)", + " DYNAMIC SERVER FILTER BY \"I.:item_id\" IN \\(\\$\\d+.\\$\\d+\\)", "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_SUPPLIER_TABLE_DISPLAY_NAME + " [-32768]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + @@ -274,7 +274,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " PARALLEL LEFT-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " \\[-32768\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + " PARALLEL ANTI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + @@ -283,13 +283,13 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " PARALLEL LEFT-JOIN TABLE 1\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " \\[-32768\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + " PARALLEL SEMI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + + " DYNAMIC SERVER FILTER BY \"" + JOIN_SCHEMA + ".idx_item.:item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + " AFTER-JOIN SERVER FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+ IS NOT NULL\\)", "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " [-32768]\n" + @@ -314,9 +314,9 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\"O.item_id\"\\)\n" + + " DYNAMIC SERVER FILTER BY \"I.:item_id\" IN \\(\"O.item_id\"\\)\n" + " AFTER-JOIN SERVER FILTER BY \\(\"I.0:NAME\" = 'T2' OR O.QUANTITY > \\$\\d+.\\$\\d+\\)\n" + - " DYNAMIC SERVER FILTER BY \"customer_id\" IN \\(\\$\\d+.\\$\\d+\\)" + " DYNAMIC SERVER FILTER BY \"" + JOIN_SCHEMA + ".idx_customer.:customer_id\" IN \\(\\$\\d+.\\$\\d+\\)" }}); return testCases; } http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java index f931bae..59f75e5 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java @@ -130,9 +130,9 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { " CLIENT MERGE SORT\n" + " AND\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\", NAME\\]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\".+.item_id\", .+.NAME\\]\n" + " CLIENT MERGE SORT\n" + - " CLIENT SORTED BY \\[\"item_id\", NAME\\]\n" + + " CLIENT SORTED BY \\[\".+.item_id\", .+.NAME\\]\n" + " PARALLEL ANTI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"]\\\n" + @@ -140,14 +140,14 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { " CLIENT SORTED BY \\[.*.CO_ITEM_ID, .*.CO_ITEM_NAME\\]\n" + "AND\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\", NAME\\]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\".+.item_id\", .+.NAME\\]\n" + " CLIENT MERGE SORT\n" + - " CLIENT SORTED BY \\[\"item_id\", NAME\\]\n" + + " CLIENT SORTED BY \\[\".+.item_id\", .+.NAME\\]\n" + " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + + " DYNAMIC SERVER FILTER BY \"" + JOIN_ITEM_TABLE_DISPLAY_NAME + ".item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + "CLIENT FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+ IS NOT NULL\\)", "SORT-MERGE-JOIN \\(SEMI\\) TABLES\n" + @@ -163,7 +163,7 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\"O.item_id\"\\)\n" + + " DYNAMIC SERVER FILTER BY \"I.item_id\" IN \\(\"O.item_id\"\\)\n" + " AFTER-JOIN SERVER FILTER BY \\(I.NAME = 'T2' OR O.QUANTITY > \\$\\d+.\\$\\d+\\)", }}); testCases.add(new String[][] { @@ -197,9 +197,9 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { " AND\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " CLIENT SORTED BY \\[\"item_id\", \"NAME\"\\]\n" + + " CLIENT SORTED BY \\[\".+.:item_id\", \".+.0:NAME\"\\]\n" + " PARALLEL ANTI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + @@ -208,9 +208,9 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { "AND\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " CLIENT SORTED BY \\[\"item_id\", \"NAME\"\\]\n" + + " CLIENT SORTED BY \\[\".+.:item_id\", \".+.0:NAME\"\\]\n" + " PARALLEL SEMI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + @@ -267,9 +267,9 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { " AND\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " \\[-32768\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " CLIENT SORTED BY \\[\"item_id\", \"NAME\"\\]\n" + + " CLIENT SORTED BY \\[\".+.:item_id\", \".+.0:NAME\"\\]\n" + " PARALLEL ANTI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + @@ -278,14 +278,14 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { "AND\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX + JOIN_ITEM_TABLE_DISPLAY_NAME + " \\[-32768\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\"NAME\", \"item_id\"\\]\n" + + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY \\[\".+.0:NAME\", \".+.:item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " CLIENT SORTED BY \\[\"item_id\", \"NAME\"\\]\n" + + " CLIENT SORTED BY \\[\".+.:item_id\", \".+.0:NAME\"\\]\n" + " PARALLEL SEMI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" + " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + + " DYNAMIC SERVER FILTER BY \"" + JOIN_SCHEMA + ".idx_item.:item_id\" IN \\(\\$\\d+.\\$\\d+\\)\n" + "CLIENT FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+ IS NOT NULL\\)", "SORT-MERGE-JOIN \\(SEMI\\) TABLES\n" + @@ -305,7 +305,7 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT { " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[\"item_id\"\\]\n" + " CLIENT MERGE SORT\n" + - " DYNAMIC SERVER FILTER BY \"item_id\" IN \\(\"O.item_id\"\\)\n" + + " DYNAMIC SERVER FILTER BY \"I.:item_id\" IN \\(\"O.item_id\"\\)\n" + " AFTER-JOIN SERVER FILTER BY \\(\"I.0:NAME\" = 'T2' OR O.QUANTITY > \\$\\d+.\\$\\d+\\)", }}); return testCases; http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java index 7fb879e..07d87b7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java @@ -113,7 +113,7 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " \\['a'\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \\(\"T_ID\", \"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"T.T_ID\", \"T.K1\", \"T.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; String actual = QueryUtil.getExplainPlan(rs); assertTrue("Expected:\n" + expected + "\nbut got\n" + actual, Pattern.matches(expected, actual)); @@ -138,7 +138,7 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " \\['a'\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \\(\"T_ID\", \"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"T.T_ID\", \"T.K1\", \"T.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; actual = QueryUtil.getExplainPlan(rs); assertTrue("Expected:\n" + expected + "\nbut got\n" + actual, Pattern.matches(expected, actual)); @@ -163,12 +163,12 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { expected = "CLIENT PARALLEL \\d-WAY FULL SCAN OVER " + TestUtil.DEFAULT_DATA_TABLE_NAME + "\n" + " SERVER FILTER BY K3 > 1\n" + - " SERVER SORTED BY \\[V1, T_ID\\]\n" + + " SERVER SORTED BY \\[T.V1, T.T_ID\\]\n" + "CLIENT MERGE SORT\n" + " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " \\[\\*\\] - \\['z'\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \\(\"T_ID\", \"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"T.T_ID\", \"T.K1\", \"T.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; actual = QueryUtil.getExplainPlan(rs); assertTrue("Expected:\n" + expected + "\nbut got\n" + actual, Pattern.matches(expected, actual)); @@ -198,12 +198,12 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { expected = "CLIENT PARALLEL \\d-WAY FULL SCAN OVER " + TestUtil.DEFAULT_DATA_TABLE_NAME + "\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[T_ID, V1, K3\\]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[T.T_ID, T.V1, T.K3\\]\n" + "CLIENT MERGE SORT\n" + " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " \\[\\*\\] - \\['z'\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \\(\"T_ID\", \"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"T.T_ID\", \"T.K1\", \"T.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; actual = QueryUtil.getExplainPlan(rs); assertTrue("Expected:\n" + expected + "\nbut got\n" + actual, Pattern.matches(expected, actual)); @@ -231,13 +231,13 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { rs = conn1.createStatement().executeQuery("EXPLAIN " + query); expected = "CLIENT PARALLEL \\d-WAY FULL SCAN OVER T\n" + - " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[V1\\]\n" + + " SERVER AGGREGATE INTO DISTINCT ROWS BY \\[T.V1\\]\n" + "CLIENT MERGE SORT\n" + - "CLIENT SORTED BY \\[V1\\]\n" + + "CLIENT SORTED BY \\[T.V1\\]\n" + " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER I \\[\\*\\] - \\['z'\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \\(\"T_ID\", \"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"T.T_ID\", \"T.K1\", \"T.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; actual = QueryUtil.getExplainPlan(rs); assertTrue("Expected:\n" + expected + "\nbut got\n" + actual, Pattern.matches(expected, actual)); @@ -275,7 +275,7 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER I \\['tid1','a'\\]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + - " DYNAMIC SERVER FILTER BY \\(\"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"T.K1\", \"T.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; assertTrue("Expected:\n" + expected + "\ndid not match\n" + actual, Pattern.matches(expected, actual)); rs = conn1.createStatement().executeQuery(query); @@ -323,7 +323,7 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT { " SKIP-SCAN-JOIN TABLE 0\n" + " CLIENT PARALLEL 1-WAY SKIP SCAN ON 2 KEYS OVER _IDX_T \\[-32768,1\\] - \\[-32768,2\\]\n" + " SERVER FILTER BY FIRST KEY ONLY AND \"K2\" IN \\(3,4\\)\n" + - " DYNAMIC SERVER FILTER BY \\(\"T_ID\", \"K1\", \"K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; + " DYNAMIC SERVER FILTER BY \\(\"V.T_ID\", \"V.K1\", \"V.K2\"\\) IN \\(\\(\\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+, \\$\\d+.\\$\\d+\\)\\)"; assertTrue("Expected:\n" + expected + "\ndid not match\n" + actual, Pattern.matches(expected,actual)); rs = conn1.createStatement().executeQuery(query); http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java index 4080730..a7b7655 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java @@ -323,7 +323,7 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { assertEquals( "CLIENT PARALLEL " + numRegions + "-WAY RANGE SCAN OVER " + MetaDataUtil.getLocalIndexTableName(TestUtil.DEFAULT_DATA_TABLE_NAME) + " [-32768,*] - [-32768,'z']\n" + " SERVER FILTER BY FIRST KEY ONLY\n" - + " SERVER SORTED BY [K3]\n" + + + " SERVER SORTED BY [\"K3\"]\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs = conn1.createStatement().executeQuery(query); @@ -471,7 +471,7 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { "CLIENT PARALLEL " + numRegions + "-WAY RANGE SCAN OVER " + MetaDataUtil.getLocalIndexTableName(TestUtil.DEFAULT_DATA_TABLE_NAME)+" [-32768,*] - [-32768,'z']\n" + " SERVER FILTER BY FIRST KEY ONLY\n" - + " SERVER AGGREGATE INTO DISTINCT ROWS BY [\"V1\", \"T_ID\", K3]\n" + "CLIENT MERGE SORT", + + " SERVER AGGREGATE INTO DISTINCT ROWS BY [\"V1\", \"T_ID\", \"K3\"]\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs = conn1.createStatement().executeQuery(query); http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java index 81e4059..52c67f1 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java @@ -572,7 +572,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio * indexed columns. Without this check present we wrongly and unnecessarily * end up creating a RoundExpression. */ - if (context.getResolver().getTables().get(0).getTable().getType() != PTableType.INDEX) { + if (context.getCurrentTable().getTable().getType() != PTableType.INDEX) { expr = convertToRoundExpressionIfNeeded(fromDataType, targetDataType, children); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java index 1a605b7..a57250e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java @@ -21,8 +21,10 @@ import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.HTableInterface; @@ -40,6 +42,7 @@ import org.apache.phoenix.parse.FamilyWildcardParseNode; import org.apache.phoenix.parse.JoinTableNode; import org.apache.phoenix.parse.NamedTableNode; import org.apache.phoenix.parse.ParseNode; +import org.apache.phoenix.parse.ParseNodeFactory; import org.apache.phoenix.parse.SelectStatement; import org.apache.phoenix.parse.SingleTableStatement; import org.apache.phoenix.parse.TableName; @@ -65,15 +68,19 @@ import org.apache.phoenix.schema.PTable; import org.apache.phoenix.schema.PTableImpl; import org.apache.phoenix.schema.PTableKey; import org.apache.phoenix.schema.PTableType; +import org.apache.phoenix.schema.ProjectedColumn; import org.apache.phoenix.schema.SortOrder; import org.apache.phoenix.schema.TableNotFoundException; import org.apache.phoenix.schema.TableRef; +import org.apache.phoenix.schema.PTable.IndexType; import org.apache.phoenix.util.Closeables; +import org.apache.phoenix.util.IndexUtil; import org.apache.phoenix.util.LogUtil; import org.apache.phoenix.util.SchemaUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ListMultimap; @@ -178,7 +185,6 @@ public class FromCompiler { public static ColumnResolver getResolverForCompiledDerivedTable(PhoenixConnection connection, TableRef tableRef, RowProjector projector) throws SQLException { List<PColumn> projectedColumns = new ArrayList<PColumn>(); - List<Expression> sourceExpressions = new ArrayList<Expression>(); PTable table = tableRef.getTable(); for (PColumn column : table.getColumns()) { Expression sourceExpression = projector.getColumnProjector(column.getPosition()).getExpression(); @@ -186,7 +192,6 @@ public class FromCompiler { sourceExpression.getDataType(), sourceExpression.getMaxLength(), sourceExpression.getScale(), sourceExpression.isNullable(), column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr()); projectedColumns.add(projectedColumn); - sourceExpressions.add(sourceExpression); } PTable t = PTableImpl.makePTable(table, projectedColumns); return new SingleTableColumnResolver(connection, new TableRef(tableRef.getTableAlias(), t, tableRef.getLowerBoundTimeStamp(), tableRef.hasDynamicCols())); @@ -207,6 +212,10 @@ public class FromCompiler { SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, statement.getTable(), false); return visitor; } + + public static ColumnResolver getResolverForProjectedTable(PTable projectedTable) { + return new ProjectedTableColumnResolver(projectedTable); + } private static class SingleTableColumnResolver extends BaseColumnResolver { private final List<TableRef> tableRefs; @@ -401,8 +410,8 @@ public class FromCompiler { } private static class MultiTableColumnResolver extends BaseColumnResolver implements TableNodeVisitor<Void> { - private final ListMultimap<String, TableRef> tableMap; - private final List<TableRef> tables; + protected final ListMultimap<String, TableRef> tableMap; + protected final List<TableRef> tables; private MultiTableColumnResolver(PhoenixConnection connection, int tsAddition) { super(connection, tsAddition); @@ -571,4 +580,74 @@ public class FromCompiler { } } + + private static class ProjectedTableColumnResolver extends MultiTableColumnResolver { + private final boolean isLocalIndex; + private final List<TableRef> theTableRefs; + private final Map<ColumnRef, Integer> columnRefMap; + + private ProjectedTableColumnResolver(PTable projectedTable) { + super(null, 0); + Preconditions.checkArgument(projectedTable.getType() == PTableType.PROJECTED); + this.isLocalIndex = projectedTable.getIndexType() == IndexType.LOCAL; + this.columnRefMap = new HashMap<ColumnRef, Integer>(); + long ts = Long.MAX_VALUE; + for (int i = projectedTable.getBucketNum() == null ? 0 : 1; i < projectedTable.getColumns().size(); i++) { + PColumn column = projectedTable.getColumns().get(i); + ColumnRef colRef = ((ProjectedColumn) column).getSourceColumnRef(); + TableRef tableRef = colRef.getTableRef(); + if (!tables.contains(tableRef)) { + String alias = tableRef.getTableAlias(); + if (alias != null) { + this.tableMap.put(alias, tableRef); + } + String name = tableRef.getTable().getName().getString(); + if (alias == null || !alias.equals(name)) { + tableMap.put(name, tableRef); + } + tables.add(tableRef); + if (tableRef.getLowerBoundTimeStamp() < ts) { + ts = tableRef.getLowerBoundTimeStamp(); + } + } + this.columnRefMap.put(new ColumnRef(tableRef, colRef.getColumnPosition()), column.getPosition()); + } + this.theTableRefs = ImmutableList.of(new TableRef(ParseNodeFactory.createTempAlias(), projectedTable, ts, false)); + } + + @Override + public List<TableRef> getTables() { + return theTableRefs; + } + + @Override + public ColumnRef resolveColumn(String schemaName, String tableName, String colName) throws SQLException { + ColumnRef colRef; + try { + colRef = super.resolveColumn(schemaName, tableName, colName); + } catch (ColumnNotFoundException e) { + // This could be a ColumnRef for local index data column. + TableRef tableRef = isLocalIndex ? super.getTables().get(0) : super.resolveTable(schemaName, tableName); + if (tableRef.getTable().getIndexType() == IndexType.LOCAL) { + try { + TableRef parentTableRef = super.resolveTable( + tableRef.getTable().getSchemaName().getString(), + tableRef.getTable().getParentTableName().getString()); + colRef = new ColumnRef(parentTableRef, + IndexUtil.getDataColumnFamilyName(colName), + IndexUtil.getDataColumnName(colName)); + } catch (TableNotFoundException te) { + throw e; + } + } else { + throw e; + } + } + Integer position = columnRefMap.get(colRef); + if (position == null) + throw new ColumnNotFoundException(colName); + + return new ColumnRef(theTableRefs.get(0), position); + } + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java index c29ea23..98b7edb 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java @@ -17,8 +17,6 @@ */ package org.apache.phoenix.compile; -import static org.apache.phoenix.schema.SaltingUtil.SALTING_COLUMN; - import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; @@ -35,7 +33,6 @@ import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.util.Pair; import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.exception.SQLExceptionInfo; -import org.apache.phoenix.execute.TupleProjector; import org.apache.phoenix.expression.AndExpression; import org.apache.phoenix.expression.CoerceExpression; import org.apache.phoenix.expression.Expression; @@ -67,18 +64,18 @@ import org.apache.phoenix.parse.TableNode; import org.apache.phoenix.parse.TableNodeVisitor; import org.apache.phoenix.parse.TableWildcardParseNode; import org.apache.phoenix.parse.WildcardParseNode; -import org.apache.phoenix.schema.AmbiguousColumnException; import org.apache.phoenix.schema.ColumnNotFoundException; import org.apache.phoenix.schema.ColumnRef; +import org.apache.phoenix.schema.LocalIndexDataColumnRef; import org.apache.phoenix.schema.MetaDataEntityNotFoundException; import org.apache.phoenix.schema.PColumn; -import org.apache.phoenix.schema.PColumnImpl; import org.apache.phoenix.schema.PName; import org.apache.phoenix.schema.PNameFactory; import org.apache.phoenix.schema.PTable; import org.apache.phoenix.schema.PTable.IndexType; import org.apache.phoenix.schema.PTableImpl; import org.apache.phoenix.schema.PTableType; +import org.apache.phoenix.schema.ProjectedColumn; import org.apache.phoenix.schema.TableRef; import org.apache.phoenix.schema.types.PBoolean; import org.apache.phoenix.schema.types.PDataType; @@ -95,8 +92,7 @@ import org.apache.phoenix.schema.types.PVarchar; import org.apache.phoenix.util.IndexUtil; import org.apache.phoenix.util.SchemaUtil; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -722,24 +718,19 @@ public class JoinCompiler { } } - public ProjectedPTableWrapper createProjectedTable(boolean retainPKColumns, StatementContext context) throws SQLException { + public PTable createProjectedTable(boolean retainPKColumns, StatementContext context) throws SQLException { assert(!isSubselect()); - List<PColumn> projectedColumns = new ArrayList<PColumn>(); - List<Expression> sourceExpressions = new ArrayList<Expression>(); - ListMultimap<String, String> columnNameMap = ArrayListMultimap.<String, String>create(); + List<ColumnRef> sourceColumns = new ArrayList<ColumnRef>(); PTable table = tableRef.getTable(); - boolean hasSaltingColumn = retainPKColumns && table.getBucketNum() != null; if (retainPKColumns) { for (PColumn column : table.getPKColumns()) { - addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap, - column, column.getFamilyName(), hasSaltingColumn, false, context); + sourceColumns.add(new ColumnRef(tableRef, column.getPosition())); } } if (isWildCardSelect()) { for (PColumn column : table.getColumns()) { if (!retainPKColumns || !SchemaUtil.isPKColumn(column)) { - addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap, - column, PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), hasSaltingColumn, false, context); + sourceColumns.add(new ColumnRef(tableRef, column.getPosition())); } } } else { @@ -748,76 +739,27 @@ public class JoinCompiler { if (e.getValue() != ColumnRefType.PREFILTER && columnRef.getTableRef().equals(tableRef) && (!retainPKColumns || !SchemaUtil.isPKColumn(columnRef.getColumn()))) { - PColumn column = columnRef.getColumn(); - addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap, - column, PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), hasSaltingColumn, - columnRef instanceof LocalIndexColumnRef, context); + if (columnRef instanceof LocalIndexColumnRef) { + sourceColumns.add(new LocalIndexDataColumnRef(context, IndexUtil.getIndexColumnName(columnRef.getColumn()))); + } else { + sourceColumns.add(columnRef); + } } } } - PTable t = PTableImpl.makePTable(table.getTenantId(), PNameFactory.newName(PROJECTED_TABLE_SCHEMA), table.getName(), PTableType.JOIN, - table.getIndexState(), table.getTimeStamp(), table.getSequenceNumber(), table.getPKName(), - retainPKColumns ? table.getBucketNum() : null, projectedColumns, table.getParentSchemaName(), - table.getParentTableName(), table.getIndexes(), table.isImmutableRows(), Collections.<PName>emptyList(), null, null, - table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), - table.getIndexType()); - return new ProjectedPTableWrapper(t, columnNameMap, sourceExpressions); - } - - private void addProjectedColumn(List<PColumn> projectedColumns, List<Expression> sourceExpressions, - ListMultimap<String, String> columnNameMap, PColumn sourceColumn, PName familyName, boolean hasSaltingColumn, - boolean isLocalIndexColumnRef, StatementContext context) - throws SQLException { - if (sourceColumn == SALTING_COLUMN) - return; - - int position = projectedColumns.size() + (hasSaltingColumn ? 1 : 0); - PTable table = tableRef.getTable(); - String schemaName = table.getSchemaName().getString(); - String tableName = table.getTableName().getString(); - String colName = isLocalIndexColumnRef ? IndexUtil.getIndexColumnName(sourceColumn) : sourceColumn.getName().getString(); - String fullName = getProjectedColumnName(schemaName, tableName, colName); - String aliasedName = tableRef.getTableAlias() == null ? fullName : getProjectedColumnName(null, tableRef.getTableAlias(), colName); - - columnNameMap.put(colName, aliasedName); - if (!fullName.equals(aliasedName)) { - columnNameMap.put(fullName, aliasedName); - } - - PName name = PNameFactory.newName(aliasedName); - PColumnImpl column = new PColumnImpl(name, familyName, sourceColumn.getDataType(), - sourceColumn.getMaxLength(), sourceColumn.getScale(), sourceColumn.isNullable(), - position, sourceColumn.getSortOrder(), sourceColumn.getArraySize(), sourceColumn.getViewConstant(), sourceColumn.isViewReferenced(), sourceColumn.getExpressionStr()); - Expression sourceExpression = isLocalIndexColumnRef ? - NODE_FACTORY.column(TableName.create(schemaName, tableName), "\"" + colName + "\"", null).accept(new ExpressionCompiler(context)) - : new ColumnRef(tableRef, sourceColumn.getPosition()).newColumnExpression(); - projectedColumns.add(column); - sourceExpressions.add(sourceExpression); + return TupleProjectionCompiler.createProjectedTable(tableRef, sourceColumns, retainPKColumns); } - public ProjectedPTableWrapper createProjectedTable(RowProjector rowProjector) throws SQLException { + public PTable createProjectedTable(RowProjector rowProjector) throws SQLException { assert(isSubselect()); - List<PColumn> projectedColumns = new ArrayList<PColumn>(); - List<Expression> sourceExpressions = new ArrayList<Expression>(); - ListMultimap<String, String> columnNameMap = ArrayListMultimap.<String, String>create(); + TableRef tableRef = FromCompiler.getResolverForCompiledDerivedTable(statement.getConnection(), this.tableRef, rowProjector).getTables().get(0); + List<ColumnRef> sourceColumns = new ArrayList<ColumnRef>(); PTable table = tableRef.getTable(); for (PColumn column : table.getColumns()) { - String colName = getProjectedColumnName(null, tableRef.getTableAlias(), column.getName().getString()); - Expression sourceExpression = rowProjector.getColumnProjector(column.getPosition()).getExpression(); - PColumnImpl projectedColumn = new PColumnImpl(PNameFactory.newName(colName), PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), - sourceExpression.getDataType(), sourceExpression.getMaxLength(), sourceExpression.getScale(), sourceExpression.isNullable(), - column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr()); - projectedColumns.add(projectedColumn); - sourceExpressions.add(sourceExpression); + sourceColumns.add(new ColumnRef(tableRef, column.getPosition())); } - PTable t = PTableImpl.makePTable(table.getTenantId(), PNameFactory.newName(PROJECTED_TABLE_SCHEMA), table.getName(), PTableType.JOIN, - table.getIndexState(), table.getTimeStamp(), table.getSequenceNumber(), table.getPKName(), - null, projectedColumns, table.getParentSchemaName(), - table.getParentTableName(), table.getIndexes(), table.isImmutableRows(), Collections.<PName>emptyList(), null, null, - table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), - table.getViewIndexId(), table.getIndexType()); - return new ProjectedPTableWrapper(t, columnNameMap, sourceExpressions); + return TupleProjectionCompiler.createProjectedTable(tableRef, sourceColumns, false); } } @@ -1120,7 +1062,6 @@ public class JoinCompiler { } } - private static final String PROJECTED_TABLE_SCHEMA = "."; // for creation of new statements private static final ParseNodeFactory NODE_FACTORY = new ParseNodeFactory(); @@ -1215,7 +1156,7 @@ public class JoinCompiler { } JoinTable join = compile(statement, select, resolver); if (groupByTableRef != null || orderByTableRef != null) { - QueryCompiler compiler = new QueryCompiler(statement, select, resolver); + QueryCompiler compiler = new QueryCompiler(statement, select, resolver, false); List<Object> binds = statement.getParameters(); StatementContext ctx = new StatementContext(statement, resolver, new Scan(), new SequenceManager(statement)); QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, false, false, null); @@ -1329,147 +1270,34 @@ public class JoinCompiler { return NODE_FACTORY.select(from, hintNode, false, selectList, where, groupBy, null, orderBy, null, 0, groupBy != null, hasSequence); } - public class PTableWrapper { - protected PTable table; - protected ListMultimap<String, String> columnNameMap; - - protected PTableWrapper(PTable table, ListMultimap<String, String> columnNameMap) { - this.table = table; - this.columnNameMap = columnNameMap; - } - - public PTable getTable() { - return table; - } - - public ListMultimap<String, String> getColumnNameMap() { - return columnNameMap; - } - - public List<String> getMappedColumnName(String name) { - return columnNameMap.get(name); - } - - public ColumnResolver createColumnResolver() { - return new JoinedTableColumnResolver(this, origResolver); - } - - public PTableWrapper mergeProjectedTables(PTableWrapper rWrapper, JoinType type) throws SQLException { - PTable left = this.getTable(); - PTable right = rWrapper.getTable(); - List<PColumn> merged = Lists.<PColumn> newArrayList(); - if (type != JoinType.Full) { - merged.addAll(left.getColumns()); - } else { - for (PColumn c : left.getColumns()) { - if (SchemaUtil.isPKColumn(c)) { - merged.add(c); - } else { - PColumnImpl column = new PColumnImpl(c.getName(), c.getFamilyName(), c.getDataType(), - c.getMaxLength(), c.getScale(), true, c.getPosition(), - c.getSortOrder(), c.getArraySize(), c.getViewConstant(), c.isViewReferenced(), c.getExpressionStr()); - merged.add(column); - } - } + public static PTable joinProjectedTables(PTable left, PTable right, JoinType type) throws SQLException { + Preconditions.checkArgument(left.getType() == PTableType.PROJECTED); + Preconditions.checkArgument(right.getType() == PTableType.PROJECTED); + List<PColumn> merged = Lists.<PColumn> newArrayList(); + if (type == JoinType.Full) { + for (PColumn c : left.getColumns()) { + merged.add(new ProjectedColumn(c.getName(), c.getFamilyName(), + c.getPosition(), true, ((ProjectedColumn) c).getSourceColumnRef())); } - int position = merged.size(); - for (PColumn c : right.getColumns()) { - if (!SchemaUtil.isPKColumn(c)) { - PColumnImpl column = new PColumnImpl(c.getName(), - PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), c.getDataType(), - c.getMaxLength(), c.getScale(), type == JoinType.Inner ? c.isNullable() : true, position++, - c.getSortOrder(), c.getArraySize(), c.getViewConstant(), c.isViewReferenced(), c.getExpressionStr()); - merged.add(column); - } - } - if (left.getBucketNum() != null) { - merged.remove(0); + } else { + merged.addAll(left.getColumns()); + } + int position = merged.size(); + for (PColumn c : right.getColumns()) { + if (!SchemaUtil.isPKColumn(c)) { + PColumn column = new ProjectedColumn(c.getName(), c.getFamilyName(), + position++, type == JoinType.Inner ? c.isNullable() : true, + ((ProjectedColumn) c).getSourceColumnRef()); + merged.add(column); } - PTable t = PTableImpl.makePTable(left.getTenantId(), left.getSchemaName(), - PNameFactory.newName(SchemaUtil.getTableName(left.getName().getString(), right.getName().getString())), left.getType(), left.getIndexState(), left.getTimeStamp(), left.getSequenceNumber(), left.getPKName(), left.getBucketNum(), merged, - left.getParentSchemaName(), left.getParentTableName(), left.getIndexes(), left.isImmutableRows(), Collections.<PName>emptyList(), null, null, PTable.DEFAULT_DISABLE_WAL, left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(), left.getIndexType()); - - ListMultimap<String, String> mergedMap = ArrayListMultimap.<String, String>create(); - mergedMap.putAll(this.getColumnNameMap()); - mergedMap.putAll(rWrapper.getColumnNameMap()); - - return new PTableWrapper(t, mergedMap); } - } - - public class ProjectedPTableWrapper extends PTableWrapper { - private List<Expression> sourceExpressions; - - protected ProjectedPTableWrapper(PTable table, ListMultimap<String, String> columnNameMap, List<Expression> sourceExpressions) { - super(table, columnNameMap); - this.sourceExpressions = sourceExpressions; - } - - public Expression getSourceExpression(PColumn column) { - return sourceExpressions.get(column.getPosition() - (table.getBucketNum() == null ? 0 : 1)); - } - - public TupleProjector createTupleProjector() { - return new TupleProjector(this); + if (left.getBucketNum() != null) { + merged.remove(0); } - } - - public static class JoinedTableColumnResolver implements ColumnResolver { - private PTableWrapper table; - private ColumnResolver tableResolver; - private TableRef tableRef; - - private JoinedTableColumnResolver(PTableWrapper table, ColumnResolver tableResolver) { - this.table = table; - this.tableResolver = tableResolver; - this.tableRef = new TableRef(ParseNodeFactory.createTempAlias(), table.getTable(), 0, false); - } - - public PTableWrapper getPTableWrapper() { - return table; - } - - public TableRef getTableRef() { - return tableRef; - } - - @Override - public List<TableRef> getTables() { - return tableResolver.getTables(); - } - - @Override - public TableRef resolveTable(String schemaName, String tableName) - throws SQLException { - return tableResolver.resolveTable(schemaName, tableName); - } - - @Override - public ColumnRef resolveColumn(String schemaName, String tableName, - String colName) throws SQLException { - String name = getProjectedColumnName(schemaName, tableName, colName); - try { - PColumn column = tableRef.getTable().getColumn(name); - return new ColumnRef(tableRef, column.getPosition()); - } catch (ColumnNotFoundException e) { - List<String> names = table.getMappedColumnName(name); - if (names.size() == 1) { - PColumn column = tableRef.getTable().getColumn(names.get(0)); - return new ColumnRef(tableRef, column.getPosition()); - } - - if (names.size() > 1) { - throw new AmbiguousColumnException(name); - } - - throw e; - } - } - } - - private static String getProjectedColumnName(String schemaName, String tableName, - String colName) { - return SchemaUtil.getColumnName(SchemaUtil.getTableName(schemaName, tableName), colName); + + return PTableImpl.makePTable(left.getTenantId(), left.getSchemaName(), + PNameFactory.newName(SchemaUtil.getTableName(left.getName().getString(), right.getName().getString())), left.getType(), left.getIndexState(), left.getTimeStamp(), left.getSequenceNumber(), left.getPKName(), left.getBucketNum(), merged, + left.getParentSchemaName(), left.getParentTableName(), left.getIndexes(), left.isImmutableRows(), Collections.<PName>emptyList(), null, null, PTable.DEFAULT_DISABLE_WAL, left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(), left.getIndexType()); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f829751/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java index 444b05e..215f59e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java @@ -123,7 +123,7 @@ public class OrderByCompiler { // REV_ROW_KEY_ORDER_BY scan would not take effect for a projected table, so don't return it for such table types. if (context.getConnection().getQueryServices().getProps().getBoolean(QueryServices.USE_REVERSE_SCAN_ATTRIB, QueryServicesOptions.DEFAULT_USE_REVERSE_SCAN) && !context.getScanRanges().useSkipScanFilter() - && context.getCurrentTable().getTable().getType() != PTableType.JOIN + && context.getCurrentTable().getTable().getType() != PTableType.PROJECTED && context.getCurrentTable().getTable().getType() != PTableType.SUBQUERY) { return OrderBy.REV_ROW_KEY_ORDER_BY; }