use of org.apache.cassandra.thrift.InvalidRequestException in project eiger by wlloyd.
the class AlterTableStatement method getCfDef.
public CfDef getCfDef(String keyspace) throws ConfigurationException, InvalidRequestException {
CFMetaData meta = Schema.instance.getCFMetaData(keyspace, columnFamily);
CfDef cfDef = meta.toAvro();
ByteBuffer columnName = this.oType == OperationType.OPTS ? null : meta.comparator.fromString(this.columnName);
switch(oType) {
case ADD:
if (cfDef.key_alias != null && cfDef.key_alias.equals(columnName))
throw new InvalidRequestException("Invalid column name: " + this.columnName + ", because it equals to key_alias.");
cfDef.column_metadata.add(new ColumnDefinition(columnName, TypeParser.parse(validator), null, null, null).toAvro());
break;
case ALTER:
ColumnDefinition column = meta.getColumnDefinition(columnName);
if (column == null)
throw new InvalidRequestException(String.format("Column '%s' was not found in CF '%s'", this.columnName, columnFamily));
column.setValidator(TypeParser.parse(validator));
cfDef.column_metadata.add(column.toAvro());
break;
case DROP:
ColumnDef toDelete = null;
for (ColumnDef columnDef : cfDef.column_metadata) {
if (columnDef.name.equals(columnName)) {
toDelete = columnDef;
}
}
if (toDelete == null)
throw new InvalidRequestException(String.format("Column '%s' was not found in CF '%s'", this.columnName, columnFamily));
// it is impossible to use ColumnDefinition.deflate() in remove() method
// it will throw java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.avro.util.Utf8
// some where deep inside of Avro
cfDef.column_metadata.remove(toDelete);
break;
case OPTS:
if (cfProps == null)
throw new InvalidRequestException(String.format("ALTER COLUMNFAMILY WITH invoked, but no parameters found"));
cfProps.validate();
applyPropertiesToCfDef(cfDef, cfProps);
break;
}
return cfDef;
}
Aggregations