Github user twdsilva commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/355#discussion_r220420512
--- 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)) {
--- End diff --
What happens if you are changing a column that is present in the primary
key of an index table?
---