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

    https://github.com/apache/phoenix/pull/355#discussion_r224208120
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 ---
    @@ -4588,4 +4424,195 @@ private TableName getParentPhysicalTableName(PTable 
table) {
                                                                     
table.getTableName(), table.isNamespaceMapped())
                                                             .getBytes());
         }
    +
    +    private class TableBuilder {
    +        private Region region;
    +        private byte[] tableKey;
    +        private Integer clientVersion;
    +
    +        public TableBuilder setRegion(Region region) {
    +            this.region = region;
    +            return this;
    +        }
    +
    +        public TableBuilder setTableKey(byte[] tableKey) {
    +            this.tableKey = tableKey;
    +            return this;
    +        }
    +
    +        public TableBuilder setClientVersion(Integer clientVersion) {
    +            this.clientVersion = clientVersion;
    +            return this;
    +        }
    +
    +        public PTable run() throws Exception {
    +            Preconditions.checkNotNull(region);
    +            Preconditions.checkNotNull(tableKey);
    +            Preconditions.checkNotNull(clientVersion);
    +            ImmutableBytesPtr cacheKey = new ImmutableBytesPtr(tableKey);
    +            return buildTable(tableKey, cacheKey, region, 
HConstants.LATEST_TIMESTAMP, clientVersion,
    +                    false, false, null);
    +        }
    +    }
    +
    +
    +    /**
    +     * Indexes table and View will not be modify when the parent tables 
are modified, so modify has a simple logic in server side.
    +     * @param controller
    +     * @param request
    +     * @param done
    +     */
    +    @Override
    +    public void modifyColumn(RpcController controller, final 
MetaDataProtos.ModifyColumnRequest request,
    +            RpcCallback<MetaDataResponse> done) {
    +        try {
    +            final List<Mutation> metaData = 
ProtobufUtil.getMutations(request);
    +            final TableBuilder tableBuilder = new TableBuilder();
    +            MetaDataMutationResult result = 
mutateColumn(MutatateColumnType.MODIFY_COLUMN, metaData, new ColumnMutator() {
    +
    +                @Override
    +                public MetaDataMutationResult updateMutation(PTable table, 
byte[][] rowKeyMetaData,
    +                        List<Mutation> tableMetadata, Region region,
    +                        List<ImmutableBytesPtr> invalidateList, 
List<RowLock> locks,
    +                        long clientTimeStamp) throws IOException, 
SQLException {
    +
    +                    Preconditions.checkArgument(rowKeyMetaData.length == 
5);
    +                    byte[] tenantId = 
rowKeyMetaData[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
    +                    byte[] schemaName = 
rowKeyMetaData[PhoenixDatabaseMetaData.SCHEMA_NAME_INDEX];
    +                    byte[] tableName = 
rowKeyMetaData[PhoenixDatabaseMetaData.TABLE_NAME_INDEX];
    +                    byte[] key = SchemaUtil.getTableKey(tenantId, 
schemaName, tableName);
    +
    +                    PColumn column = null;
    +                    Cell dataTypeCell = null;
    +                    Cell columnSizeCell = null;
    +                    Cell decimalDigitCell = null;
    +                    List<byte[]> mutatedTableNames = new ArrayList<>();
    +                    byte[] familyName = 
QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
    +
    +                    try {
    +                        for (Mutation m : metaData) {
    +                            byte[][] rkmd = new byte[5][];
    +                            int pkCount = getVarChars(m.getRow(), rkmd);
    +
    +                            // Checking this put is for modifying a column
    +                            if (pkCount < COLUMN_NAME_INDEX || !(m 
instanceof Put)
    +                                    || 
rkmd[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX] == null) {
    +                                continue;
    +                            }
    +
    +                            List<Cell> cells;
    +                            if 
(rkmd[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX] != null) {
    +                                PColumnFamily family = 
table.getColumnFamily(rkmd[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]);
    +                                column = 
family.getPColumnForColumnNameBytes(rkmd[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]);
    +                                cells = 
m.getFamilyCellMap().get(column.getFamilyName().getBytes());
    +                            } else {
    +                                column = table.getPKColumn(new 
String(rkmd[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]));
    +                                cells = 
m.getFamilyCellMap().get(familyName);
    +                            }
    +
    +                            for (Cell cell : cells) {
    +                                if 
(Bytes.compareTo(CellUtil.cloneQualifier(cell), 
PhoenixDatabaseMetaData.DATA_TYPE_BYTES) == 0) {
    +                                    dataTypeCell = cell;
    +                                } else if 
(Bytes.compareTo(CellUtil.cloneQualifier(cell), 
PhoenixDatabaseMetaData.COLUMN_SIZE_BYTES) == 0) {
    +                                    columnSizeCell = cell;
    +                                } else if 
(Bytes.compareTo(CellUtil.cloneQualifier(cell), 
PhoenixDatabaseMetaData.DECIMAL_DIGITS_BYTES) == 0) {
    +                                    decimalDigitCell = cell;
    +                                }
    +                            }
    +                        }
    +
    +                        // After PHOENIX-3534, we don't store parent table 
column metadata along with the child metadata,
    +                        // so we don't need to propagate changes to the 
child views.
    +
    +                        if (!table.getIndexes().isEmpty()) {
    +                            PhoenixConnection connection = null;
    +                            try {
    +                                connection = 
QueryUtil.getConnectionOnServer(env.getConfiguration()).unwrap(PhoenixConnection.class);
    +                            } catch (ClassNotFoundException e) {
    +                            }
    +
    +                            for (PTable index : table.getIndexes()) {
    +                                byte[] tenantIdBytes = index.getTenantId() 
== null ?
    +                                                ByteUtil.EMPTY_BYTE_ARRAY :
    +                                                
index.getTenantId().getBytes();
    +                                byte[] schemaNameBytes = 
index.getSchemaName().getBytes();
    +                                byte[] indexName = 
index.getTableName().getBytes();
    +                                byte[] indexKey = 
SchemaUtil.getTableKey(tenantIdBytes, schemaNameBytes, indexName);
    +
    +                                IndexMaintainer indexMaintainer = 
index.getIndexMaintainer(table, connection);
    +                                boolean isColumnIndexed = 
indexMaintainer.getIndexedColumnInfo().contains(
    +                                                new 
Pair<>(column.getFamilyName().getString(), column.getName().getString()));
    +                                ColumnReference coveredColumn = 
indexMaintainer.getCoveredColumnsOfIndexTable(
    +                                                new 
ColumnReference(column.getFamilyName().getBytes(), 
column.getColumnQualifierBytes()));
    +
    +                                // Since the columns of fixed length which 
in present in primary key of index table will be converted
    +                                // to variable length when index tables 
are created, So we will not process indexed columns.
    +                                if (isColumnIndexed) {
    --- End diff --
    
    remove this boolean as its not used, just keep the comment about why we 
don't need to do anything for indexed columns.


---

Reply via email to