protected AbstractType getExpressionComparator() { return baseCfs.getComparator().asAbstractType(); } }
public AbstractType<?> getComponentComparator(Integer componentIndex, ColumnDefinition.Kind kind) { switch (kind) { case REGULAR: if (componentIndex == null) return comparator.asAbstractType(); AbstractType<?> t = comparator.subtype(componentIndex); assert t != null : "Non-sensical component index"; return t; default: // CQL3 column names are UTF8 return UTF8Type.instance; } }
public static AbstractType<?> getComparatorFor(CFMetaData metadata, boolean subColumn) { return metadata.isSuper() ? metadata.comparator.subtype(subColumn ? 1 : 0) : metadata.comparator.asAbstractType(); }
private static SortedSet<CellName> getColumnNames(SelectStatement select, CFMetaData metadata, List<ByteBuffer> variables) throws InvalidRequestException { String keyString = metadata.getCQL2KeyName(); List<Term> selectColumnNames = select.getColumnNames(); SortedSet<CellName> columnNames = new TreeSet<>(metadata.comparator); for (Term column : selectColumnNames) { // skip the key for the slice op; we'll add it to the resultset in extractThriftColumns if (!column.getText().equalsIgnoreCase(keyString)) columnNames.add(metadata.comparator.cellFromByteBuffer(column.getByteBuffer(metadata.comparator.asAbstractType(),variables))); } return columnNames; }
name = stringAsType((String) fields.get(0), comparator.asAbstractType()); timestamp = (Long) fields.get(2); kind = ""; value = stringAsType((String) fields.get(1), comparator.asAbstractType());
private List<ColumnDefinition> getColumns(CFMetaData cfm) throws InvalidRequestException { List<ColumnDefinition> columnDefs = new ArrayList<>(columns.size()); for (Map.Entry<Term, String> col : columns.entrySet()) { try { ByteBuffer columnName = cfm.comparator.asAbstractType().fromStringCQL2(col.getKey().getText()); String validatorClassName = CFPropDefs.comparators.containsKey(col.getValue()) ? CFPropDefs.comparators.get(col.getValue()) : col.getValue(); AbstractType<?> validator = TypeParser.parse(validatorClassName); columnDefs.add(ColumnDefinition.regularDef(cfm, columnName, validator, null)); } catch (ConfigurationException e) { InvalidRequestException ex = new InvalidRequestException(e.toString()); ex.initCause(e); throw ex; } catch (SyntaxException e) { InvalidRequestException ex = new InvalidRequestException(e.toString()); ex.initCause(e); throw ex; } } return columnDefs; }
private List<ColumnDefinition> addDefaultColumnAliases(List<ColumnDefinition> ckCols) { for (int i = 0; i < ckCols.size(); i++) { if (ckCols.get(i) == null) { Integer idx; AbstractType<?> type; if (comparator.isCompound()) { idx = i; type = comparator.subtype(i); } else { idx = null; type = comparator.asAbstractType(); } ByteBuffer name = ByteBufferUtil.bytes(DEFAULT_COLUMN_ALIAS + (i + 1)); ColumnDefinition newDef = ColumnDefinition.clusteringKeyDef(this, name, type, idx); addOrReplaceColumnDefinition(newDef); ckCols.set(i, newDef); } } return ckCols; }
public TableMapper(ColumnFamilyStore table, boolean isMetaColumn, ColumnDefinition primaryColumnDefinition) { this.table = table; this.cfMetaData = table.metadata; this.clusteringCType = table.getComparator(); this.primaryKeyAbstractType = table.metadata.getKeyValidator(); this.clusteringKeyType = table.getComparator().asAbstractType(); this.primaryKeyType = CompositeType.getInstance(primaryKeyAbstractType, clusteringKeyType); this.defaultPartitionKey = defaultPartitionKey(); this.isMetaColumn = isMetaColumn; this.primaryColumnDefinition = primaryColumnDefinition; }
/** * Returns whether this CFMetaData can be returned to thrift. */ public boolean isThriftCompatible() { // Super CF are always "thrift compatible". But since they may have defs with a componentIndex != null, // we have to special case here. if (isSuper()) return true; for (ColumnDefinition def : allColumns()) { // Non-REGULAR ColumnDefinition are not "thrift compatible" per-se, but it's ok because they hold metadata // this is only of use to CQL3, so we will just skip them in toThrift. if (def.kind == ColumnDefinition.Kind.REGULAR && !def.isThriftCompatible()) return false; } // The table might also have no REGULAR columns (be PK-only), but still be "thrift incompatible". See #7832. if (isCQL3OnlyPKComparator(comparator.asAbstractType()) && !isDense) return false; return true; }
public ColumnIdentifier prepare(CFMetaData cfm) { AbstractType<?> comparator = cfm.comparator.asAbstractType(); if (cfm.getIsDense() || comparator instanceof CompositeType || comparator instanceof UTF8Type) return new ColumnIdentifier(text, true); // We have a Thrift-created table with a non-text comparator. We need to parse column names with the comparator // to get the correct ByteBuffer representation. However, this doesn't apply to key aliases, so we need to // make a special check for those and treat them normally. See CASSANDRA-8178. ByteBuffer bufferName = ByteBufferUtil.bytes(text); for (ColumnDefinition def : cfm.partitionKeyColumns()) { if (def.name.bytes.equals(bufferName)) return new ColumnIdentifier(text, true); } return new ColumnIdentifier(comparator.fromString(rawText), text); }
public void applyPropertiesTo(CFMetaData cfmd) throws RequestValidationException { cfmd.defaultValidator(defaultValidator) .keyValidator(keyValidator) .addAllColumnDefinitions(getColumns(cfmd)) .isDense(isDense); cfmd.addColumnMetadataFromAliases(keyAliases, keyValidator, ColumnDefinition.Kind.PARTITION_KEY); cfmd.addColumnMetadataFromAliases(columnAliases, comparator.asAbstractType(), ColumnDefinition.Kind.CLUSTERING_COLUMN); if (valueAlias != null) cfmd.addColumnMetadataFromAliases(Collections.<ByteBuffer>singletonList(valueAlias), defaultValidator, ColumnDefinition.Kind.COMPACT_VALUE); properties.applyToCFMetadata(cfmd); }
public CFMetaData rebuild() isDense(calculateIsDense(comparator.asAbstractType(), allColumns()));
public Mutation mutationForKey(ByteBuffer key, String keyspace, Long timestamp, ThriftClientState clientState, List<ByteBuffer> variables, CFMetaData metadata) throws InvalidRequestException { Mutation mutation = new Mutation(keyspace, key); QueryProcessor.validateKeyAlias(metadata, keyName); if (columns.size() < 1) { // No columns, delete the partition mutation.delete(columnFamily, (timestamp == null) ? getTimestamp(clientState) : timestamp); } else { // Delete specific columns AbstractType<?> at = metadata.comparator.asAbstractType(); for (Term column : columns) { CellName columnName = metadata.comparator.cellFromByteBuffer(column.getByteBuffer(at, variables)); validateColumnName(columnName); mutation.delete(columnFamily, columnName, (timestamp == null) ? getTimestamp(clientState) : timestamp); } } return mutation; }
private boolean updateDefinition(CFMetaData cfm, ColumnDefinition def, String keyspace, ByteBuffer toReplace, UserType updated) { AbstractType<?> t = updateWith(def.type, keyspace, toReplace, updated); if (t == null) return false; // We need to update this validator ... cfm.addOrReplaceColumnDefinition(def.withNewType(t)); // ... but if it's part of the comparator or key validator, we need to go update those too. switch (def.kind) { case PARTITION_KEY: cfm.keyValidator(updateWith(cfm.getKeyValidator(), keyspace, toReplace, updated)); break; case CLUSTERING_COLUMN: cfm.comparator = CellNames.fromAbstractType(updateWith(cfm.comparator.asAbstractType(), keyspace, toReplace, updated), cfm.comparator.isDense()); break; default: // If it's a collection, we still want to modify the comparator because the collection is aliased in it if (def.type instanceof CollectionType && def.type.isMultiCell()) { t = updateWith(cfm.comparator.asAbstractType(), keyspace, toReplace, updated); // If t == null, all relevant comparators were updated via updateWith, which reaches into types and // collections if (t != null) cfm.comparator = CellNames.fromAbstractType(t, cfm.comparator.isDense()); } break; } return true; }
AbstractType<?> at = comparator.asAbstractType();
private static IDiskAtomFilter filterFromSelect(SelectStatement select, CFMetaData metadata, List<ByteBuffer> variables) throws InvalidRequestException { if (select.isColumnRange() || select.getColumnNames().size() == 0) { AbstractType<?> comparator = metadata.comparator.asAbstractType(); return new SliceQueryFilter(metadata.comparator.fromByteBuffer(select.getColumnStart().getByteBuffer(comparator, variables)), metadata.comparator.fromByteBuffer(select.getColumnFinish().getByteBuffer(comparator, variables)), select.isColumnsReversed(), select.getColumnsLimit()); } else { return new NamesQueryFilter(getColumnNames(select, metadata, variables)); } }
ByteBuffer entity = columnRelation.getEntity().getByteBuffer(metadata.comparator.asAbstractType(), variables); ByteBuffer value = columnRelation.getValue().getByteBuffer(metadata.getValueValidator(metadata.comparator.cellFromByteBuffer(entity)), variables);
private static void validateSelect(String keyspace, SelectStatement select, List<ByteBuffer> variables) throws InvalidRequestException { select.getConsistencyLevel().validateForRead(keyspace); // Finish key w/o start key (KEY < foo) if (!select.isKeyRange() && (select.getKeyFinish() != null)) throw new InvalidRequestException("Key range clauses must include a start key (i.e. KEY > term)"); // Key range and by-key(s) combined (KEY > foo AND KEY = bar) if (select.isKeyRange() && select.getKeys().size() > 0) throw new InvalidRequestException("You cannot combine key range and by-key clauses in a SELECT"); // Start and finish keys, *and* column relations (KEY > foo AND KEY < bar and name1 = value1). if (select.isKeyRange() && (select.getKeyFinish() != null) && (select.getColumnRelations().size() > 0)) throw new InvalidRequestException("You cannot combine key range and by-column clauses in a SELECT"); // Can't use more than one KEY = if (!select.isMultiKey() && select.getKeys().size() > 1) throw new InvalidRequestException("You cannot use more than one KEY = in a SELECT"); if (select.getColumnRelations().size() > 0) { ColumnFamilyStore cfstore = Keyspace.open(keyspace).getColumnFamilyStore(select.getColumnFamily()); CellNameType comparator = cfstore.metadata.comparator; AbstractType<?> at = comparator.asAbstractType(); SecondaryIndexManager idxManager = cfstore.indexManager; for (Relation relation : select.getColumnRelations()) { ByteBuffer name = relation.getEntity().getByteBuffer(at, variables); if ((relation.operator() == RelationType.EQ) && idxManager.indexes(comparator.cellFromByteBuffer(name))) return; } throw new InvalidRequestException("No indexed columns present in by-columns clause with \"equals\" operator"); } }
AbstractType<?> at = metadata.comparator.asAbstractType(); Composite start = metadata.comparator.fromByteBuffer(select.getColumnStart().getByteBuffer(at,variables)); Composite finish = metadata.comparator.fromByteBuffer(select.getColumnFinish().getByteBuffer(at,variables));
cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("key_aliases"))), cfm.keyValidator, ColumnDefinition.Kind.PARTITION_KEY); if (result.has("column_aliases")) cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("column_aliases"))), cfm.comparator.asAbstractType(), ColumnDefinition.Kind.CLUSTERING_COLUMN); if (result.has("value_alias")) cfm.addColumnMetadataFromAliases(Collections.singletonList(result.getBytes("value_alias")), cfm.defaultValidator, ColumnDefinition.Kind.COMPACT_VALUE);