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 2015/04/29 05:25:25 UTC

phoenix git commit: Replace dummy implementation with PTable.getStatistics()

Repository: phoenix
Updated Branches:
  refs/heads/calcite 2d0834592 -> 977d78c16


Replace dummy implementation with PTable.getStatistics()


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

Branch: refs/heads/calcite
Commit: 977d78c16fa937cc64382c93216714e2959933e8
Parents: 2d08345
Author: maryannxue <we...@intel.com>
Authored: Tue Apr 28 23:25:09 2015 -0400
Committer: maryannxue <we...@intel.com>
Committed: Tue Apr 28 23:25:09 2015 -0400

----------------------------------------------------------------------
 .../java/org/apache/phoenix/calcite/CalciteTest.java   |  8 ++++++++
 .../java/org/apache/phoenix/calcite/PhoenixTable.java  | 13 ++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/977d78c1/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
index 7b9c30d..620a375 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
@@ -16,6 +16,7 @@ import java.sql.*;
 import java.util.List;
 import java.util.Map;
 
+import static org.apache.phoenix.util.TestUtil.JOIN_CUSTOMER_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_ITEM_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_ORDER_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_SUPPLIER_TABLE_FULL_NAME;
@@ -225,6 +226,13 @@ public class CalciteTest extends BaseClientManagedTimeIT {
         ensureTableCreated(url, ATABLE_NAME);
         initATableValues(getOrganizationId(), null, url);
         initJoinTableValues(url, null, null);
+        final Connection connection = DriverManager.getConnection(url);
+        connection.createStatement().execute("UPDATE STATISTICS ATABLE");
+        connection.createStatement().execute("UPDATE STATISTICS " + JOIN_CUSTOMER_TABLE_FULL_NAME);
+        connection.createStatement().execute("UPDATE STATISTICS " + JOIN_ITEM_TABLE_FULL_NAME);
+        connection.createStatement().execute("UPDATE STATISTICS " + JOIN_SUPPLIER_TABLE_FULL_NAME);
+        connection.createStatement().execute("UPDATE STATISTICS " + JOIN_ORDER_TABLE_FULL_NAME);
+        connection.close();
     }
     
     @Test public void testTableScan() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/977d78c1/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 e9378af..ea52edf 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
@@ -1,6 +1,7 @@
 package org.apache.phoenix.calcite;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptTable;
@@ -25,6 +26,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.stats.GuidePostsInfo;
 import org.apache.phoenix.schema.types.PDataType;
 
 import com.google.common.base.Preconditions;
@@ -93,9 +95,14 @@ public class PhoenixTable extends AbstractTable implements TranslatableTable {
         return new Statistic() {
             @Override
             public Double getRowCount() {
-                // TODO
-                String tableName = pTable.getTableName().getString();
-                return tableName.equals("ItemTable") ? 70d : tableName.equals("SupplierTable") ? 60d : 100d;
+                int rowCount = 0;
+                for (Map.Entry<byte[], GuidePostsInfo> entry : pTable.getTableStats().getGuidePosts().entrySet()) {
+                    rowCount += entry.getValue().getRowCount();
+                }
+                
+                // Return an non-zero value to make the query plans stable.
+                // TODO remove "* 10.0" which is for test purpose.
+                return rowCount > 0 ? rowCount * 10.0 : 100.0;
             }
 
             @Override