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

    https://github.com/apache/phoenix/pull/355#discussion_r220424066
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
    @@ -3300,6 +3281,134 @@ private void mutateStringProperty(String tenantId, 
String schemaName, String tab
             }
         }
     
    +    public MutationState modifyColumn(ModifyColumnStatement statement) 
throws SQLException {
    +        PTable table = FromCompiler.getResolver(statement, 
connection).getTables().get(0).getTable();
    +        ColumnDef columnDef = statement.getColumnDef();
    +        ColumnName columnName =columnDef.getColumnDefName();
    +
    +        // we can not modify index table/system table and project table.
    +        if (table.getType() != PTableType.TABLE && table.getType() != 
PTableType.VIEW) {
    +            throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.DISALLOW_MODIFY_TABLE_TYPE).build().buildException();
    +        }
    +
    +        PColumn oldColumn = null;
    +        for (PColumn column : table.getColumns()) {
    +            if (column.getFamilyName() == null) {
    +                if 
(column.getName().getString().equals(columnName.getColumnName())) {
    +                    oldColumn = column;
    +                }
    +            } else {
    +                if 
(column.getName().getString().equals(columnName.getColumnName()) &&
    +                        ((columnName.getFamilyName() != null && 
column.getFamilyName().getString().equals(columnName.getFamilyName())) ||
    +                                (columnName.getFamilyName() == null && 
column.getFamilyName().getString().equals(QueryConstants.DEFAULT_COLUMN_FAMILY))))
 {
    +                    oldColumn = column;
    +                    break;
    +                }
    +            }
    +        }
    +
    +        if (oldColumn == null) {
    +            throw new 
ColumnNotFoundException(table.getSchemaName().getString(), 
table.getTableName().getString(),
    +                    columnName.getFamilyName(), 
columnName.getColumnName());
    +        }
    +
    +        // Comparision of row keys were affected when we changed max 
length of pk columns to pad more placeholder,
    +        // so we can not modify length of the PK column.
    +        if (oldColumn.isRowTimestamp() || 
SchemaUtil.isPKColumn(oldColumn)) {
    +            throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.DISALLOW_MODIFY_TIMESTAMP_OR_PK_COLUMN).build().buildException();
    +        }
    +
    --- End diff --
    
    Also add a check if the column is from a view that it is not derived (i.e. 
inherited from the parent table). You should thrown an exception in this case.


---

Reply via email to