phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: PHOENIX-2259 SqlValidator exception if salted index is created on non-salted table
Date Tue, 15 Sep 2015 16:48:53 GMT
Repository: phoenix
Updated Branches:
  refs/heads/calcite df370f438 -> a8648f12d


PHOENIX-2259 SqlValidator exception if salted index is created on non-salted table


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

Branch: refs/heads/calcite
Commit: a8648f12dbe6efa01022a64035e65eaad32595b9
Parents: df370f4
Author: maryannxue <wei.xue@intel.com>
Authored: Tue Sep 15 12:48:41 2015 -0400
Committer: maryannxue <wei.xue@intel.com>
Committed: Tue Sep 15 12:48:41 2015 -0400

----------------------------------------------------------------------
 .../apache/phoenix/calcite/PhoenixSchema.java   |  5 ++---
 .../apache/phoenix/calcite/PhoenixTable.java    |  9 ++++++---
 .../calcite/rel/PhoenixRelImplementorImpl.java  | 20 ++++++++++----------
 .../phoenix/calcite/rel/PhoenixTableScan.java   |  5 ++---
 4 files changed, 20 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a8648f12/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index 55c9d6a..b0afbc7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -22,7 +22,6 @@ import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.util.IndexUtil;
 
@@ -194,8 +193,8 @@ public class PhoenixSchema implements Schema {
     protected void addMaterialization(PTable table, PTable index, List<String> path)
{
         StringBuffer sb = new StringBuffer();
         sb.append("SELECT");
-        for (PColumn column : index.getColumns()) {
-            if (column == SaltingUtil.SALTING_COLUMN) continue;
+        for (int i = PhoenixTable.getStartingColumnPosition(index); i < index.getColumns().size();
i++) {
+            PColumn column = index.getColumns().get(i);
             String indexColumnName = column.getName().getString();
             String dataColumnName = IndexUtil.getDataColumnName(indexColumnName);
             sb.append(",").append("\"").append(dataColumnName).append("\"");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/a8648f12/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 92ed628..2cfe345 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
@@ -24,7 +24,6 @@ import org.apache.phoenix.calcite.rel.PhoenixTableScan;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PTable;
-import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.stats.GuidePostsInfo;
 import org.apache.phoenix.schema.types.PDataType;
@@ -43,6 +42,10 @@ public class PhoenixTable extends AbstractTable implements TranslatableTable
{
   public final ImmutableBitSet pkBitSet;
   public final RelCollation collation;
   public final PhoenixConnection pc;
+  
+  public static int getStartingColumnPosition(PTable pTable) {
+      return (pTable.getBucketNum() == null ? 0 : 1) + (pTable.isMultiTenant() ? 1 : 0) +
(pTable.getViewIndexId() == null ? 0 : 1);
+  }
 
   public PhoenixTable(PhoenixConnection pc, PTable pTable) {
       this.pc = Preconditions.checkNotNull(pc);
@@ -67,8 +70,8 @@ public class PhoenixTable extends AbstractTable implements TranslatableTable
{
     @Override
     public RelDataType getRowType(RelDataTypeFactory typeFactory) {
         final RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
-        for (PColumn pColumn : pTable.getColumns()) {
-            if (pColumn == SaltingUtil.SALTING_COLUMN) continue;
+        for (int i = getStartingColumnPosition(pTable); i < pTable.getColumns().size();
i++) {
+            PColumn pColumn = pTable.getColumns().get(i);
             final PDataType baseType = 
                     pColumn.getDataType().isArrayType() ?
                             PDataType.fromTypeId(pColumn.getDataType().getSqlType() - PDataType.ARRAY_TYPE_BASE)


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a8648f12/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java
index 8b3919b..ad5fde7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRelImplementorImpl.java
@@ -7,6 +7,7 @@ import java.util.Stack;
 
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.phoenix.calcite.CalciteUtils;
+import org.apache.phoenix.calcite.PhoenixTable;
 import org.apache.phoenix.calcite.rel.PhoenixRel.ImplementorContext;
 import org.apache.phoenix.compile.ColumnProjector;
 import org.apache.phoenix.compile.ExpressionProjector;
@@ -29,7 +30,6 @@ import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableImpl;
 import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.types.PDataType;
 
@@ -52,7 +52,7 @@ public class PhoenixRelImplementorImpl implements PhoenixRel.Implementor
{
 
 	@Override
 	public ColumnExpression newColumnExpression(int index) {
-	    int pos = this.tableRef.getTable().getBucketNum() == null ? index : (index + 1);
+	    int pos = index + PhoenixTable.getStartingColumnPosition(this.tableRef.getTable());
 		ColumnRef colRef = new ColumnRef(this.tableRef, pos);
 		return colRef.newColumnExpression();
 	}
@@ -61,7 +61,7 @@ public class PhoenixRelImplementorImpl implements PhoenixRel.Implementor
{
     @Override
     public Expression newFieldAccessExpression(String variableId, int index, PDataType type)
{
         TableRef variableDef = runtimeContext.getCorrelateVariableDef(variableId);
-        int pos = variableDef.getTable().getBucketNum() == null ? index : (index + 1);
+        int pos = index + PhoenixTable.getStartingColumnPosition(variableDef.getTable());
         Expression fieldAccessExpr = new ColumnRef(variableDef, pos).newColumnExpression();
         return new CorrelateVariableFieldAccessExpression(runtimeContext, variableId, fieldAccessExpr);
     }
@@ -99,9 +99,9 @@ public class PhoenixRelImplementorImpl implements PhoenixRel.Implementor
{
     @Override
     public PTable createProjectedTable() {
         List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
-        for (PColumn column : getTableRef().getTable().getColumns()) {
-            if (!getCurrentContext().retainPKColumns && column == SaltingUtil.SALTING_COLUMN)
continue;
-            sourceColumnRefs.add(new ColumnRef(getTableRef(), column.getPosition()));
+        int start = getCurrentContext().retainPKColumns ? 0 : PhoenixTable.getStartingColumnPosition(getTableRef().getTable());
+        for (int i = start; i < getTableRef().getTable().getColumns().size(); i++) {
+            sourceColumnRefs.add(new ColumnRef(getTableRef(), getTableRef().getTable().getColumns().get(i).getPosition()));
         }
         
         try {
@@ -114,10 +114,10 @@ public class PhoenixRelImplementorImpl implements PhoenixRel.Implementor
{
     @Override
     public RowProjector createRowProjector() {
         List<ColumnProjector> columnProjectors = Lists.<ColumnProjector>newArrayList();
-        int pos = 0;
-        for (PColumn column : getTableRef().getTable().getColumns()) {
-            if (column == SaltingUtil.SALTING_COLUMN) continue;
-            Expression expr = newColumnExpression(pos++); // Do not use column.position()
here.
+        int start = PhoenixTable.getStartingColumnPosition(getTableRef().getTable());
+        for (int i = start; i < getTableRef().getTable().getColumns().size(); i++) {
+            PColumn column = getTableRef().getTable().getColumns().get(i);
+            Expression expr = newColumnExpression(i - start); // Do not use column.position()
here.
             columnProjectors.add(new ExpressionProjector(column.getName().getString(), getTableRef().getTable().getName().getString(),
expr, false));
         }
         // TODO get estimate row size

http://git-wip-us.apache.org/repos/asf/phoenix/blob/a8648f12/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
index b10e594..4d7445a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
@@ -44,7 +44,6 @@ import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
-import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.SchemaUtil;
@@ -223,8 +222,8 @@ public class PhoenixTableScan extends TableScan implements PhoenixRel
{
         KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0);
         List<Expression> exprs = Lists.<Expression> newArrayList();
         TableRef tableRef = implementor.getTableRef();
-        for (PColumn column : tableRef.getTable().getColumns()) {
-            if (column == SaltingUtil.SALTING_COLUMN) continue;
+        for (int i = PhoenixTable.getStartingColumnPosition(tableRef.getTable()); i <
tableRef.getTable().getColumns().size(); i++) {
+            PColumn column = tableRef.getTable().getColumns().get(i);
             if (!SchemaUtil.isPKColumn(column) || !implementor.getCurrentContext().retainPKColumns)
{
                 Expression expr = new ColumnRef(tableRef, column.getPosition()).newColumnExpression();
                 exprs.add(expr);


Mime
View raw message