Java Code Examples for org.apache.cassandra.config.CFMetaData#addDefaultIndexNames()
The following examples show how to use
org.apache.cassandra.config.CFMetaData#addDefaultIndexNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraServer.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public String system_add_column_family(CfDef cf_def) throws InvalidRequestException, SchemaDisagreementException, TException { logger.debug("add_column_family"); try { ClientState cState = state(); String keyspace = cState.getKeyspace(); cState.hasKeyspaceAccess(keyspace, Permission.CREATE); cf_def.unsetId(); // explicitly ignore any id set by client (Hector likes to set zero) CFMetaData cfm = CFMetaData.fromThrift(cf_def); CFMetaData.validateCompactionOptions(cfm.compactionStrategyClass, cfm.compactionStrategyOptions); cfm.addDefaultIndexNames(); if (!cfm.getTriggers().isEmpty()) state().ensureIsSuper("Only superusers are allowed to add triggers."); MigrationManager.announceNewColumnFamily(cfm); return Schema.instance.getVersion().toString(); } catch (RequestValidationException e) { throw ThriftConversion.toThrift(e); } }
Example 2
Source File: CreateIndexStatement.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public boolean announceMigration(boolean isLocalOnly) throws RequestValidationException { CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily()).copy(); IndexTarget target = rawTarget.prepare(cfm); logger.debug("Updating column {} definition for index {}", target.column, indexName); ColumnDefinition cd = cfm.getColumnDefinition(target.column); if (cd.getIndexType() != null && ifNotExists) return false; if (properties.isCustom) { cd.setIndexType(IndexType.CUSTOM, properties.getOptions()); } else if (cfm.comparator.isCompound()) { Map<String, String> options = Collections.emptyMap(); // For now, we only allow indexing values for collections, but we could later allow // to also index map keys, so we record that this is the values we index to make our // lives easier then. if (cd.type.isCollection() && cd.type.isMultiCell()) options = ImmutableMap.of(target.isCollectionKeys ? SecondaryIndex.INDEX_KEYS_OPTION_NAME : SecondaryIndex.INDEX_VALUES_OPTION_NAME, ""); cd.setIndexType(IndexType.COMPOSITES, options); } else { cd.setIndexType(IndexType.KEYS, Collections.<String, String>emptyMap()); } cd.setIndexName(indexName); cfm.addDefaultIndexNames(); MigrationManager.announceColumnFamilyUpdate(cfm, false, isLocalOnly); return true; }
Example 3
Source File: CassandraServer.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public String system_add_keyspace(KsDef ks_def) throws InvalidRequestException, SchemaDisagreementException, TException { logger.debug("add_keyspace"); try { ThriftValidation.validateKeyspaceNotSystem(ks_def.name); state().hasAllKeyspacesAccess(Permission.CREATE); ThriftValidation.validateKeyspaceNotYetExisting(ks_def.name); // generate a meaningful error if the user setup keyspace and/or column definition incorrectly for (CfDef cf : ks_def.cf_defs) { if (!cf.getKeyspace().equals(ks_def.getName())) { throw new InvalidRequestException("CfDef (" + cf.getName() +") had a keyspace definition that did not match KsDef"); } } Collection<CFMetaData> cfDefs = new ArrayList<CFMetaData>(ks_def.cf_defs.size()); for (CfDef cf_def : ks_def.cf_defs) { cf_def.unsetId(); // explicitly ignore any id set by client (same as system_add_column_family) CFMetaData cfm = CFMetaData.fromThrift(cf_def); cfm.addDefaultIndexNames(); if (!cfm.getTriggers().isEmpty()) state().ensureIsSuper("Only superusers are allowed to add triggers."); cfDefs.add(cfm); } MigrationManager.announceNewKeyspace(KSMetaData.fromThrift(ks_def, cfDefs.toArray(new CFMetaData[cfDefs.size()]))); return Schema.instance.getVersion().toString(); } catch (RequestValidationException e) { throw ThriftConversion.toThrift(e); } }
Example 4
Source File: CassandraServer.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public String system_update_column_family(CfDef cf_def) throws InvalidRequestException, SchemaDisagreementException, TException { logger.debug("update_column_family"); try { if (cf_def.keyspace == null || cf_def.name == null) throw new InvalidRequestException("Keyspace and CF name must be set."); state().hasColumnFamilyAccess(cf_def.keyspace, cf_def.name, Permission.ALTER); CFMetaData oldCfm = Schema.instance.getCFMetaData(cf_def.keyspace, cf_def.name); if (oldCfm == null) throw new InvalidRequestException("Could not find column family definition to modify."); if (!oldCfm.isThriftCompatible()) throw new InvalidRequestException("Cannot modify CQL3 table " + oldCfm.cfName + " as it may break the schema. You should use cqlsh to modify CQL3 tables instead."); CFMetaData cfm = CFMetaData.fromThriftForUpdate(cf_def, oldCfm); CFMetaData.validateCompactionOptions(cfm.compactionStrategyClass, cfm.compactionStrategyOptions); cfm.addDefaultIndexNames(); if (!oldCfm.getTriggers().equals(cfm.getTriggers())) state().ensureIsSuper("Only superusers are allowed to add or remove triggers."); MigrationManager.announceColumnFamilyUpdate(cfm, true); return Schema.instance.getVersion().toString(); } catch (RequestValidationException e) { throw ThriftConversion.toThrift(e); } }