Github user twdsilva commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/248#discussion_r116659570
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 ---
    @@ -535,19 +539,115 @@ public void getTable(RpcController controller, 
GetTableRequest request,
                     // Subtract one because we add one due to timestamp 
granularity in Windows
                     builder.setMutationTime(minNonZerodisableIndexTimestamp - 
1);
                 }
    -
    +            if (PTableType.VIEW.equals(table.getType())) {
    +                table = combineColumns(table, tenantId, schemaName, 
tableName, request.getClientTimestamp());
    +            }
                 if (table.getTimeStamp() != tableTimeStamp) {
                     builder.setTable(PTableImpl.toProto(table));
                 }
                 done.run(builder.build());
    -            return;
             } catch (Throwable t) {
                logger.error("getTable failed", t);
                 ProtobufUtil.setControllerException(controller,
                     
ServerUtil.createIOException(SchemaUtil.getTableName(schemaName, tableName), 
t));
             }
         }
     
    +    private PTable combineColumns(PTable table, byte[] tenantId, byte[] 
schemaName, byte[] tableName, long timestamp)
    +        throws SQLException, IOException {
    +        // here you combine columns from the parent tables
    +        // the logic is as follows, if the PColumn is in the 
EXCLUDED_COLUMNS remove it,
    +        // otherwise priority of keeping duplicate columns is child -> 
parent
    +        List<byte[]> listOBytes = Lists.newArrayList();
    +        TableViewFinderResult viewFinderResult = new 
TableViewFinderResult();
    +        findAllParentViews(tenantId, schemaName, tableName, 
viewFinderResult);
    +        for (Result aResult : viewFinderResult.getResults()) {
    +            byte[][] rowViewKeyMetaData = new byte[5][];
    +            getVarChars(aResult.getRow(), 5, rowViewKeyMetaData);
    +            byte[] resultTenantId = 
rowViewKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX];
    +            byte[] resultSchema = 
SchemaUtil.getSchemaNameFromFullName(rowViewKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]).getBytes();
    +            byte[] resultTable = 
SchemaUtil.getTableNameFromFullName(rowViewKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]).getBytes();
    +            byte[] rowKeyInQuestion = 
SchemaUtil.getTableKey(resultTenantId, resultSchema, resultTable);
    +            listOBytes.add(rowKeyInQuestion);
    +        }
    +        List<PColumn> allColumns = Lists.newArrayList();
    +        List<PColumn> excludedColumns = Lists.newArrayList();
    +        // add my own columns first in reverse order
    +        List<PColumn> myColumns = table.getColumns();
    +        for (int i = myColumns.size() - 1; i >= 0; i--) {
    +            PColumn pColumn = myColumns.get(i);
    +            if (pColumn.isExcluded()) {
    +                excludedColumns.add(pColumn);
    +            } else {
    +                allColumns.add(pColumn);
    +            }
    +
    +        }
    +        // now go up from child to parent all the way to the base table:
    +        for (int i = 0; i < listOBytes.size(); i++) {
    +            byte[] tableInQuestion = listOBytes.get(i);
    +            PTable pTable = this.doGetTable(tableInQuestion, timestamp);
    +            if (pTable == null) {
    +                throw new TableNotFoundException("fill in with valuable 
info");
    --- End diff --
    
    fix the exception message


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to