phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: Adapt column mapping sequence for Phoenix column family support
Date Mon, 03 Oct 2016 17:59:57 GMT
Repository: phoenix
Updated Branches:
  refs/heads/calcite 1ef5a298f -> 17888a272


Adapt column mapping sequence for Phoenix column family support


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

Branch: refs/heads/calcite
Commit: 17888a2720c4314d0f8c5287b5fe7ca838509c39
Parents: 1ef5a29
Author: maryannxue <maryann.xue@gmail.com>
Authored: Mon Oct 3 10:59:49 2016 -0700
Committer: maryannxue <maryann.xue@gmail.com>
Committed: Mon Oct 3 10:59:49 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/calcite/BaseCalciteIT.java   | 18 ++++-
 .../phoenix/calcite/CalciteLocalIndexIT.java    |  6 +-
 .../apache/phoenix/calcite/TableMapping.java    | 75 ++++++++++----------
 3 files changed, 56 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/17888a27/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 e192dc6..05d825d 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,6 +39,7 @@ 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;
@@ -168,12 +169,27 @@ public class BaseCalciteIT extends BaseHBaseManagedTimeIT {
         }
 
         public Sql explainIs(String expected) throws SQLException {
+            return checkExplain(expected, true);
+        }
+
+        public Sql explainMatches(String expected) throws SQLException {
+            return checkExplain(expected, false);
+        }
+
+        private Sql checkExplain(String expected, boolean exact) throws SQLException {
             final Statement statement = start.getConnection().createStatement();
             final ResultSet resultSet = statement.executeQuery(start.getExplainPlanString()
+ " " + sql);
             String explain = QueryUtil.getExplainPlan(resultSet);
             resultSet.close();
             statement.close();
-            Assert.assertEquals(explain, expected);
+            if (exact) {
+                Assert.assertEquals(explain, expected);
+            } else {
+                Assert.assertTrue(
+                        "Explain plan \"" + explain
+                        + "\" does not match \"" + expected + "\"",
+                        explain.matches(expected));
+            }
             return this;
         }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/17888a27/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 02cf2a1..7b6c279 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
@@ -65,9 +65,9 @@ public class CalciteLocalIndexIT extends BaseCalciteIndexIT {
                        "      PhoenixTableScan(table=[[phoenix, IDX_FULL]])\n")*/
             .close();
         start(true, 1000f).sql("select a_string, b_string from aTable where a_string = 'a'")
-            .explainIs("PhoenixToEnumerableConverter\n" +
-                       "  PhoenixServerProject(A_STRING=[$0], B_STRING=[$3])\n" +
-                       "    PhoenixTableScan(table=[[phoenix, IDX1]], filter=[=($0, 'a')])\n")
+            .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'")
             .explainIs("PhoenixToEnumerableConverter\n" +

http://git-wip-us.apache.org/repos/asf/phoenix/blob/17888a27/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java
index a8dd9d2..a00facf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/TableMapping.java
@@ -6,7 +6,6 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -31,6 +30,7 @@ import org.apache.phoenix.index.IndexMaintainer;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.schema.ColumnRef;
 import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PColumnFamily;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTable;
@@ -42,7 +42,6 @@ import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.IndexUtil;
-import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.SchemaUtil;
 
 import com.google.common.collect.Lists;
@@ -74,25 +73,8 @@ public class TableMapping {
             this.mappedColumns = Lists.newArrayList();
             this.mappedColumns.addAll(getMappedColumns(tableRef.getTable()));
             this.extendedColumnsOffset = mappedColumns.size();
-            Set<String> names = Sets.newHashSet();
-            for (PColumn column : this.mappedColumns) {
-                names.add(column.getName().getString());
-            }
-            PTable dataTable = dataTableRef.getTable();
-            List<PColumn> projectedColumns = new ArrayList<PColumn>();
-            for (PColumn sourceColumn : dataTable.getColumns()) {
-                if (!SchemaUtil.isPKColumn(sourceColumn)) {
-                    String colName = IndexUtil.getIndexColumnName(sourceColumn);
-                    if (!names.contains(colName)) {
-                        ColumnRef sourceColumnRef =
-                                new ColumnRef(dataTableRef, sourceColumn.getPosition());
-                        PColumn column = new ProjectedColumn(PNameFactory.newName(colName),
-                                sourceColumn.getFamilyName(), projectedColumns.size(),
-                                sourceColumn.isNullable(), sourceColumnRef);
-                        projectedColumns.add(column);
-                    }
-                }            
-            }
+            final PTable dataTable = dataTableRef.getTable();
+            final List<PColumn> projectedColumns = getDataTableMappedColumns(dataTableRef,
mappedColumns);
             this.mappedColumns.addAll(projectedColumns);
             PTable extendedTable = PTableImpl.makePTable(dataTable.getTenantId(),
                     TupleProjectionCompiler.PROJECTED_TABLE_SCHEMA, dataTable.getName(),
@@ -108,7 +90,7 @@ public class TableMapping {
             this.extendedTableRef = new TableRef(extendedTable);
         }
     }
-    
+
     public TableRef getTableRef() {
         return tableRef;
     }
@@ -342,28 +324,43 @@ public class TableMapping {
     }
     
     private static List<PColumn> getMappedColumns(PTable pTable) {
-        if (pTable.getBucketNum() == null
-                && !pTable.isMultiTenant()
-                && pTable.getViewIndexId() == null) {
-            return pTable.getColumns();
+        int initPosition =
+                  (pTable.getBucketNum() ==null ? 0 : 1)
+                + (pTable.isMultiTenant() ? 1 : 0)
+                + (pTable.getViewIndexId() == null ? 0 : 1);
+        List<PColumn> columns = Lists.newArrayListWithExpectedSize(pTable.getColumns().size()
- initPosition);
+        for (int i = initPosition; i < pTable.getPKColumns().size(); i++) {
+            columns.add(pTable.getPKColumns().get(i));
         }
-        
-        List<PColumn> columns = Lists.newArrayList(pTable.getColumns());
-        if (pTable.getViewIndexId() != null) {
-            for (Iterator<PColumn> iter = columns.iterator(); iter.hasNext();) {
-                if (iter.next().getName().getString().equals(MetaDataUtil.getViewIndexIdColumnName()))
{
-                    iter.remove();
-                    break;
-                }
+        for (PColumnFamily family : pTable.getColumnFamilies()) {
+            for (PColumn column : family.getColumns()) {
+                columns.add(column);
             }
         }
-        if (pTable.isMultiTenant()) {
-            columns.remove(pTable.getBucketNum() == null ? 0 : 1);
+        
+        return columns;
+    }
+    
+    private static List<PColumn> getDataTableMappedColumns(TableRef dataTableRef, List<PColumn>
mappedColumns) {
+        Set<String> names = Sets.newHashSet();
+        for (PColumn column : mappedColumns) {
+            names.add(column.getName().getString());
         }
-        if (pTable.getBucketNum() != null) {
-            columns.remove(0);
+        List<PColumn> projectedColumns = new ArrayList<PColumn>();
+        for (PColumnFamily cf : dataTableRef.getTable().getColumnFamilies()) {
+            for (PColumn sourceColumn : cf.getColumns()) {
+                String colName = IndexUtil.getIndexColumnName(sourceColumn);
+                if (!names.contains(colName)) {
+                    ColumnRef sourceColumnRef =
+                            new ColumnRef(dataTableRef, sourceColumn.getPosition());
+                    PColumn column = new ProjectedColumn(PNameFactory.newName(colName),
+                            cf.getName(), projectedColumns.size(),
+                            sourceColumn.isNullable(), sourceColumnRef);
+                    projectedColumns.add(column);
+                }
+            }            
         }
         
-        return columns;
+        return projectedColumns;
     }
 }


Mime
View raw message