[1/2] phoenix git commit: PHOENIX-2090 Refine PhoenixTableScan.computeSelfCost() when scanRanges is available

2016-02-12 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 751d134be -> 8b68b1c4e


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b68b1c4/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
index f200a24..3f0f754 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
@@ -55,62 +55,71 @@ public class CalciteIndexIT extends BaseCalciteIT {
 initATableValues(getOrganizationId(), null, url);
 initSaltedTables(index);
 initMultiTenantTables(index);
-final Connection connection = DriverManager.getConnection(url);
+Connection connection = DriverManager.getConnection(url);
 connection.createStatement().execute("CREATE " + index + " IF NOT 
EXISTS IDX1 ON aTable (a_string) INCLUDE (b_string, x_integer)");
 connection.createStatement().execute("CREATE " + index + " IF NOT 
EXISTS IDX2 ON aTable (b_string) INCLUDE (a_string, y_integer)");
 connection.createStatement().execute("CREATE " + index + " IF NOT 
EXISTS IDX_FULL ON aTable (b_string) INCLUDE (a_string, a_integer, a_date, 
a_time, a_timestamp, x_decimal, x_long, x_integer, y_integer, a_byte, a_short, 
a_float, a_double, a_unsigned_float, a_unsigned_double)");
 connection.createStatement().execute("UPDATE STATISTICS ATABLE");
+connection.createStatement().execute("UPDATE STATISTICS " + 
NOSALT_TABLE_NAME);
 connection.createStatement().execute("UPDATE STATISTICS " + 
SALTED_TABLE_NAME);
-connection.createStatement().execute("UPDATE STATISTICS IDX_" + 
SALTED_TABLE_NAME);
-connection.createStatement().execute("UPDATE STATISTICS IDX1");
-connection.createStatement().execute("UPDATE STATISTICS IDX2");
-connection.createStatement().execute("UPDATE STATISTICS IDX_FULL");
+connection.createStatement().execute("UPDATE STATISTICS " + 
MULTI_TENANT_TABLE);
+connection.close();
+
+Properties props = new Properties();
+props.setProperty("TenantId", "10");
+connection = DriverManager.getConnection(url, props);
+connection.createStatement().execute("UPDATE STATISTICS " + 
MULTI_TENANT_VIEW1);
+connection.close();
+
+props.setProperty("TenantId", "20");
+connection = DriverManager.getConnection(url, props);
+connection.createStatement().execute("UPDATE STATISTICS " + 
MULTI_TENANT_VIEW2);
 connection.close();
 }
 
 @Test public void testIndex() throws Exception {
-start(true).sql("select * from aTable where b_string = 'b'")
+start(true, 1000f).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).sql("select x_integer from aTable")
+start(true, 1000f).sql("select x_integer from aTable")
 .explainIs("PhoenixToEnumerableConverter\n" +
"  PhoenixServerProject(X_INTEGER=[$4])\n" +
"PhoenixTableScan(table=[[phoenix, IDX1]])\n")
 .close();
-start(true).sql("select a_string from aTable order by a_string")
+start(true, 1000f).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).sql("select a_string from aTable order by organization_id")
+start(true, 1000f).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).sql("select a_integer from aTable order by a_string")
+start(true, 1000f).sql("select a_integer from aTable order by 
a_string")
 .explainIs("PhoenixToEnumerableConverter\n" +
"  PhoenixServerSort(sort0=[$1], 

[2/2] phoenix git commit: PHOENIX-2090 Refine PhoenixTableScan.computeSelfCost() when scanRanges is available

2016-02-12 Thread maryannxue
PHOENIX-2090 Refine PhoenixTableScan.computeSelfCost() when scanRanges is 
available


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

Branch: refs/heads/calcite
Commit: 8b68b1c4e8a68ac70c058e9d568d98af95073fc9
Parents: 751d134
Author: maryannxue 
Authored: Fri Feb 12 13:59:54 2016 -0500
Committer: maryannxue 
Committed: Fri Feb 12 13:59:54 2016 -0500

--
 .../apache/phoenix/calcite/BaseCalciteIT.java   | 102 
 .../org/apache/phoenix/calcite/CalciteIT.java   | 234 ++-
 .../apache/phoenix/calcite/CalciteIndexIT.java  | 155 ++--
 .../apache/phoenix/calcite/PhoenixTable.java|  68 +-
 .../calcite/metadata/PhoenixRelMdSize.java  |  75 ++
 .../metadata/PhoenixRelMetadataProvider.java|   1 +
 .../calcite/rel/PhoenixAbstractSort.java|  16 +-
 .../calcite/rel/PhoenixCompactClientSort.java   |   2 +-
 .../apache/phoenix/calcite/rel/PhoenixRel.java  |   7 +-
 .../phoenix/calcite/rel/PhoenixServerJoin.java  |   4 +-
 .../calcite/rel/PhoenixServerSemiJoin.java  |   4 +-
 .../phoenix/calcite/rel/PhoenixTableScan.java   |  86 +--
 .../coprocessor/MetaDataEndpointImpl.java   |  20 +-
 .../phoenix/schema/stats/StatisticsUtil.java|  18 +-
 .../phoenix/schema/stats/StatisticsWriter.java  |   2 +-
 15 files changed, 510 insertions(+), 284 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b68b1c4/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 9afddab..35c46e7 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
@@ -32,6 +32,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.text.DecimalFormat;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +40,7 @@ import java.util.Properties;
 
 import org.apache.calcite.avatica.util.ArrayImpl;
 import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.phoenix.calcite.rel.PhoenixRel;
 import org.apache.phoenix.end2end.BaseClientManagedTimeIT;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.TableAlreadyExistsException;
@@ -59,8 +61,8 @@ public class BaseCalciteIT extends BaseClientManagedTimeIT {
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
-public static Start start(boolean materializationEnabled) {
-return new Start(getConnectionProps(materializationEnabled));
+public static Start start(boolean materializationEnabled, float 
rowCountFactor) {
+return new Start(getConnectionProps(materializationEnabled, 
rowCountFactor));
 }
 
 public static Start start(Properties props) {
@@ -308,7 +310,7 @@ public class BaseCalciteIT extends BaseClientManagedTimeIT {
 return connection;
 }
 
-protected static Properties getConnectionProps(boolean 
enableMaterialization) {
+protected static Properties getConnectionProps(boolean 
enableMaterialization, float rowCountFactor) {
 Properties props = new Properties();
 props.setProperty(
 CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
@@ -316,6 +318,7 @@ public class BaseCalciteIT extends BaseClientManagedTimeIT {
 props.setProperty(
 CalciteConnectionProperty.CREATE_MATERIALIZATIONS.camelName(),
 Boolean.toString(false));
+props.setProperty(PhoenixRel.ROW_COUNT_FACTOR, 
Float.toString(rowCountFactor));
 return props;
 }
 
@@ -364,21 +367,13 @@ public class BaseCalciteIT extends 
BaseClientManagedTimeIT {
 PreparedStatement stmt = conn.prepareStatement(
 "UPSERT INTO " + NOSALT_TABLE_NAME
 + " VALUES(?, ?, ?, ?)");
-stmt.setInt(1, 1);
-stmt.setInt(2, 2);
-stmt.setInt(3, 3);
-stmt.setInt(4, 4);
-stmt.execute();
-stmt.setInt(1, 2);
-stmt.setInt(2, 3);
-stmt.setInt(3, 4);
-stmt.setInt(4, 5);
-stmt.execute();
-stmt.setInt(1, 3);
-stmt.setInt(2, 4);
-stmt.setInt(3, 5);
-stmt.setInt(4, 6);
-stmt.execute();
+   

phoenix git commit: PHOENIX-2090 Refine PhoenixTableScan.computeSelfCost() when scanRanges is available

2016-02-12 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 8b68b1c4e -> 52ba5d24d


PHOENIX-2090 Refine PhoenixTableScan.computeSelfCost() when scanRanges is 
available


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

Branch: refs/heads/calcite
Commit: 52ba5d24d6217b0f619f3dd143142ef86cbab02e
Parents: 8b68b1c
Author: maryannxue 
Authored: Fri Feb 12 21:43:12 2016 -0500
Committer: maryannxue 
Committed: Fri Feb 12 21:43:12 2016 -0500

--
 .../it/java/org/apache/phoenix/calcite/CalciteIndexIT.java  | 2 +-
 .../main/java/org/apache/phoenix/calcite/PhoenixTable.java  | 5 +
 .../phoenix/calcite/rel/PhoenixAbstractAggregate.java   | 3 ++-
 .../java/org/apache/phoenix/calcite/rel/PhoenixRel.java | 2 +-
 .../org/apache/phoenix/calcite/rel/PhoenixTableScan.java| 9 +++--
 5 files changed, 12 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
index 3f0f754..d1aea74 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
@@ -93,7 +93,7 @@ public class CalciteIndexIT extends BaseCalciteIT {
"  PhoenixServerProject(A_STRING=[$0])\n" +
"PhoenixTableScan(table=[[phoenix, IDX1]], 
scanOrder=[FORWARD])\n")
 .close();
-start(true, 1000f).sql("select a_string from aTable order by 
organization_id")
+start(true, 100f).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")

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
index 1539dcd..fea4c8a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
@@ -21,7 +21,6 @@ import org.apache.calcite.schema.impl.AbstractTable;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.phoenix.calcite.rel.PhoenixRel;
 import org.apache.phoenix.calcite.rel.PhoenixTableScan;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
@@ -185,9 +184,7 @@ public class PhoenixTable extends AbstractTable implements 
TranslatableTable {
 return new Statistic() {
 @Override
 public Double getRowCount() {
-float f = pc.getQueryServices().getProps().getFloat(
-PhoenixRel.ROW_COUNT_FACTOR, 1f);
-return (double) (rowCount * f);
+return (double) rowCount;
 }
 
 @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
index 9d76f59..de9f0c2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
@@ -105,6 +105,7 @@ abstract public class PhoenixAbstractAggregate extends 
Aggregate implements Phoe
 return planner.getCostFactory().makeInfiniteCost();
 
 double rowCount = mq.getRowCount(this);
+double bytesPerRow = mq.getAverageRowSize(this);
 if (isOrderedGroupBy) {
 rowCount = (rowCount * rowCount) / Util.nLogN(rowCount);
 }
@@ -117,7 +118,7 @@ abstract public