[ 
https://issues.apache.org/jira/browse/PHOENIX-1535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14253018#comment-14253018
 ] 

James Taylor commented on PHOENIX-1535:
---------------------------------------

Thanks for the patch, [~maryannxue]. The server-side looks to be an 
improvement. Here's some miscellaneous feedback:
- Would it be possible to not have to pass through another boolean flag here? 
The ColumnRef will be of type LocalIndexDataColumnRef and the TableRef can be 
specialized if necessary too. Maybe we can pass through a ColumnRef instead of 
a PColumn?
{code}
         private void addProjectedColumn(List<PColumn> projectedColumns, 
List<Expression> sourceExpressions,
-                ListMultimap<String, String> columnNameMap, PColumn 
sourceColumn, PName familyName, boolean hasSaltingColumn) 
+                ListMultimap<String, String> columnNameMap, PColumn 
sourceColumn, PName familyName, boolean hasSaltingColumn, 
+                boolean isLocalIndexColumnRef, StatementContext context) 
         throws SQLException {
             if (sourceColumn == SALTING_COLUMN)
                 return;
@@ -756,7 +763,7 @@ public class JoinCompiler {
             PTable table = tableRef.getTable();
             String schemaName = table.getSchemaName().getString();
             String tableName = table.getTableName().getString();
-            String colName = sourceColumn.getName().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);
             
@@ -769,7 +776,9 @@ public class JoinCompiler {
             PColumnImpl column = new PColumnImpl(name, familyName, 
sourceColumn.getDataType(), 
                     sourceColumn.getMaxLength(), sourceColumn.getScale(), 
sourceColumn.isNullable(), 
                     position, sourceColumn.getSortOrder(), 
sourceColumn.getArraySize(), sourceColumn.getViewConstant(), 
sourceColumn.isViewReferenced());
-            Expression sourceExpression = new ColumnRef(tableRef, 
sourceColumn.getPosition()).newColumnExpression();
+            Expression sourceExpression = isLocalIndexColumnRef ? 
+                      NODE_FACTORY.column(TableName.create(schemaName, 
tableName), "\"" + colName + "\"", null).accept(new 
ExpressionCompiler(context)) 
+                    : new ColumnRef(tableRef, 
sourceColumn.getPosition()).newColumnExpression();
{code}
- For this anonymous RegionScanner impl, would deriving from BaseRegionScanner 
help eliminate some of this code?
{code}
+    protected RegionScanner getWrappedScanner(final 
ObserverContext<RegionCoprocessorEnvironment> c,
+            final RegionScanner s, final Set<KeyValueColumnExpression> 
arrayKVRefs,
+            final Expression[] arrayFuncRefs, final int offset, final Scan 
scan,
+            final ColumnReference[] dataColumns, final TupleProjector 
tupleProjector,
+            final HRegion dataRegion, final IndexMaintainer indexMaintainer,
+            final byte[][] viewConstants, final KeyValueSchema kvSchema, 
+            final ValueBitSet kvSchemaBitSet, final ImmutableBytesWritable 
ptr) {
+        return new RegionScanner() {
{code}

> Secondary local index casues Undefined column error with queries involving 
> joins
> --------------------------------------------------------------------------------
>
>                 Key: PHOENIX-1535
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1535
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.2
>         Environment: HBase 0.98.6; CDH-5.2.0-1.cdh5.2.0.p0.36
>            Reporter: Joyce Lau
>         Attachments: 1535.incomplete.patch, 1535.patch, 1535.v2.patch
>
>
> Create 2 tables with a local index
> create table tab1 (col1 bigint, col2 bigint, col3 bigint, constraint pk_tab1 
> primary key (col1));
> create table tab2 (col1 bigint, col2 bigint, col3 bigint, constraint pk_tab1 
> primary key (col1));
> create local index ind_tab1 on tab1(col2);
> Executing a query with a condition on the local index column and select a 
> column not in the index results in an error:
> explain
> select tab1.col3
> from tab1 join tab2 on tab1.col1 = tab2.col1
> where tab1.col2 = 1
> =======
> Error: ERROR 504 (42703): Undefined column. columnName=0:COL3
> SQLState:  42703
> ErrorCode: 504
> =======
> Select * is ok:
> explain select tab1.* from tab1 where tab1.col2 = 1
> If I drop the local index, the first query runs successfully.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to