use of org.apache.cassandra.db.migration.avro.ColumnDef in project eiger by wlloyd.
the class DropIndexStatement method getUpdatedCFDef.
private CfDef getUpdatedCFDef(CfDef cfDef) throws InvalidRequestException {
for (ColumnDef column : cfDef.column_metadata) {
if (column.index_type != null && column.index_name != null && column.index_name.equals(index)) {
column.index_name = null;
column.index_type = null;
return cfDef;
}
}
return null;
}
use of org.apache.cassandra.db.migration.avro.ColumnDef in project eiger by wlloyd.
the class CFMetaData method fromAvro.
public static CFMetaData fromAvro(org.apache.cassandra.db.migration.avro.CfDef cf) {
AbstractType comparator;
AbstractType subcolumnComparator = null;
AbstractType validator;
AbstractType keyValidator;
try {
comparator = TypeParser.parse(cf.comparator_type.toString());
if (cf.subcomparator_type != null)
subcolumnComparator = TypeParser.parse(cf.subcomparator_type);
validator = TypeParser.parse(cf.default_validation_class);
keyValidator = TypeParser.parse(cf.key_validation_class);
} catch (Exception ex) {
throw new RuntimeException("Could not inflate CFMetaData for " + cf, ex);
}
Map<ByteBuffer, ColumnDefinition> column_metadata = new TreeMap<ByteBuffer, ColumnDefinition>(BytesType.instance);
for (ColumnDef aColumn_metadata : cf.column_metadata) {
ColumnDefinition cd = ColumnDefinition.fromAvro(aColumn_metadata);
if (cd.getIndexType() != null && cd.getIndexName() == null)
cd.setIndexName(getDefaultIndexName(cf.name.toString(), comparator, cd.name));
column_metadata.put(cd.name, cd);
}
CFMetaData newCFMD = new CFMetaData(cf.keyspace.toString(), cf.name.toString(), ColumnFamilyType.create(cf.column_type.toString()), comparator, subcolumnComparator, cf.id);
// Isn't AVRO supposed to handle stuff like this?
if (cf.min_compaction_threshold != null) {
newCFMD.minCompactionThreshold(cf.min_compaction_threshold);
}
if (cf.max_compaction_threshold != null) {
newCFMD.maxCompactionThreshold(cf.max_compaction_threshold);
}
if (cf.merge_shards_chance != null) {
newCFMD.mergeShardsChance(cf.merge_shards_chance);
}
if (cf.key_alias != null) {
newCFMD.keyAlias(cf.key_alias);
}
if (cf.compaction_strategy != null) {
try {
newCFMD.compactionStrategyClass = createCompactionStrategy(cf.compaction_strategy.toString());
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
}
if (cf.compaction_strategy_options != null) {
for (Map.Entry<CharSequence, CharSequence> e : cf.compaction_strategy_options.entrySet()) newCFMD.compactionStrategyOptions.put(e.getKey().toString(), e.getValue().toString());
}
CompressionParameters cp;
try {
cp = CompressionParameters.create(cf.compression_options);
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
Caching caching;
try {
caching = cf.caching == null ? Caching.KEYS_ONLY : Caching.fromString(cf.caching.toString());
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
return newCFMD.comment(cf.comment.toString()).readRepairChance(cf.read_repair_chance).replicateOnWrite(cf.replicate_on_write).gcGraceSeconds(cf.gc_grace_seconds).defaultValidator(validator).keyValidator(keyValidator).columnMetadata(column_metadata).compressionParameters(cp).bloomFilterFpChance(cf.bloom_filter_fp_chance).caching(caching);
}
use of org.apache.cassandra.db.migration.avro.ColumnDef in project eiger by wlloyd.
the class CFMetaData method toAvro.
// converts CFM to avro CfDef
public org.apache.cassandra.db.migration.avro.CfDef toAvro() {
org.apache.cassandra.db.migration.avro.CfDef cf = new org.apache.cassandra.db.migration.avro.CfDef();
cf.id = cfId;
cf.keyspace = new Utf8(ksName);
cf.name = new Utf8(cfName);
cf.column_type = new Utf8(cfType.name());
cf.comparator_type = new Utf8(comparator.toString());
if (subcolumnComparator != null) {
assert cfType == ColumnFamilyType.Super : String.format("%s CF %s should not have subcomparator %s defined", cfType, cfName, subcolumnComparator);
cf.subcomparator_type = new Utf8(subcolumnComparator.toString());
}
cf.comment = new Utf8(enforceCommentNotNull(comment));
cf.read_repair_chance = readRepairChance;
cf.replicate_on_write = replicateOnWrite;
cf.gc_grace_seconds = gcGraceSeconds;
cf.default_validation_class = defaultValidator == null ? null : new Utf8(defaultValidator.toString());
cf.key_validation_class = new Utf8(keyValidator.toString());
cf.min_compaction_threshold = minCompactionThreshold;
cf.max_compaction_threshold = maxCompactionThreshold;
cf.merge_shards_chance = mergeShardsChance;
cf.key_alias = keyAlias;
cf.column_metadata = new ArrayList<ColumnDef>(column_metadata.size());
for (ColumnDefinition cd : column_metadata.values()) cf.column_metadata.add(cd.toAvro());
cf.compaction_strategy = new Utf8(compactionStrategyClass.getName());
if (compactionStrategyOptions != null) {
cf.compaction_strategy_options = new HashMap<CharSequence, CharSequence>();
for (Map.Entry<String, String> e : compactionStrategyOptions.entrySet()) cf.compaction_strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
}
cf.compression_options = compressionParameters.asAvroOptions();
cf.bloom_filter_fp_chance = bloomFilterFpChance;
cf.caching = new Utf8(caching.toString());
return cf;
}
use of org.apache.cassandra.db.migration.avro.ColumnDef 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