public void validate(ClientState state) throws RequestValidationException {
   ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
   try {
     TriggerExecutor.instance.loadTriggerInstance(triggerClass);
   } catch (Exception e) {
     throw new ConfigurationException(
         String.format("Trigger class '%s' doesn't exist", triggerClass));
   }
 }
Esempio n. 2
0
  public static void validateColumnOrSuperColumn(
      String keyspace, String cfName, ColumnOrSuperColumn cosc) throws InvalidRequestException {
    if (cosc.column != null) {
      validateTtl(cosc.column);
      ThriftValidation.validateColumnPath(
          keyspace,
          new ColumnPath(cfName).setSuper_column((ByteBuffer) null).setColumn(cosc.column.name));
    }

    if (cosc.super_column != null) {
      for (Column c : cosc.super_column.columns) {
        validateTtl(c);
        ThriftValidation.validateColumnPath(
            keyspace,
            new ColumnPath(cfName).setSuper_column(cosc.super_column.name).setColumn(c.name));
      }
    }

    if (cosc.column == null && cosc.super_column == null)
      throw new InvalidRequestException(
          "ColumnOrSuperColumn must have one or both of Column or SuperColumn");
  }
  public ParsedStatement.Prepared prepare(ColumnSpecification[] boundNames)
      throws InvalidRequestException {
    CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
    type = metadata.getDefaultValidator().isCommutative() ? Type.COUNTER : Type.LOGGED;

    cfDef = metadata.getCfDef();
    UpdateStatement.processKeys(cfDef, whereClause, processedKeys, boundNames);

    for (Selector column : columns) {
      CFDefinition.Name name = cfDef.get(column.id());
      if (name == null)
        throw new InvalidRequestException(String.format("Unknown identifier %s", column));

      // For compact, we only have one value except the key, so the only form of DELETE that make
      // sense is without a column
      // list. However, we support having the value name for coherence with the static/sparse case
      if (name.kind != CFDefinition.Name.Kind.COLUMN_METADATA
          && name.kind != CFDefinition.Name.Kind.VALUE_ALIAS)
        throw new InvalidRequestException(
            String.format(
                "Invalid identifier %s for deletion (should not be a PRIMARY KEY part)", column));

      if (column.key() != null) {
        if (name.type instanceof ListType) {
          if (column.key().isBindMarker())
            boundNames[column.key().bindIndex] = ListOperation.indexSpecOf(name);
        } else if (name.type instanceof MapType) {
          if (column.key().isBindMarker())
            boundNames[column.key().bindIndex] = MapOperation.keySpecOf(name, (MapType) name.type);
        } else {
          throw new InvalidRequestException(
              String.format(
                  "Invalid selection %s since %s is neither a list or a map", column, column.id()));
        }
      }

      toRemove.add(Pair.create(name, column.key()));
    }

    return new ParsedStatement.Prepared(this, Arrays.<ColumnSpecification>asList(boundNames));
  }
 public void validate(ClientState state) throws InvalidRequestException {
   ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
 }
  public void validate(ClientState state) throws RequestValidationException {
    CFMetaData cfm = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
    if (cfm.isCounter())
      throw new InvalidRequestException("Secondary indexes are not supported on counter tables");

    IndexTarget target = rawTarget.prepare(cfm);
    ColumnDefinition cd = cfm.getColumnDefinition(target.column);

    if (cd == null)
      throw new InvalidRequestException("No column definition found for column " + target.column);

    boolean isMap = cd.type instanceof MapType;
    boolean isFrozenCollection = cd.type.isCollection() && !cd.type.isMultiCell();
    if (target.isCollectionKeys) {
      if (!isMap)
        throw new InvalidRequestException(
            "Cannot create index on keys of column " + target + " with non-map type");
      if (!cd.type.isMultiCell())
        throw new InvalidRequestException(
            "Cannot create index on keys of frozen<map> column " + target);
    } else if (target.isFullCollection) {
      if (!isFrozenCollection)
        throw new InvalidRequestException(
            "full() indexes can only be created on frozen collections");
    } else if (isFrozenCollection) {
      throw new InvalidRequestException(
          "Frozen collections currently only support full-collection indexes. "
              + "For example, 'CREATE INDEX ON <table>(full(<columnName>))'.");
    }

    if (cd.getIndexType() != null) {
      boolean previousIsKeys = cd.hasIndexOption(SecondaryIndex.INDEX_KEYS_OPTION_NAME);
      if (isMap && target.isCollectionKeys != previousIsKeys) {
        String msg =
            "Cannot create index on %s %s, an index on %s %s already exists and indexing "
                + "a map on both keys and values at the same time is not currently supported";
        throw new InvalidRequestException(
            String.format(
                msg,
                target.column,
                target.isCollectionKeys ? "keys" : "values",
                target.column,
                previousIsKeys ? "keys" : "values"));
      }

      if (ifNotExists) return;
      else throw new InvalidRequestException("Index already exists");
    }

    properties.validate();

    // TODO: we could lift that limitation
    if ((cfm.comparator.isDense() || !cfm.comparator.isCompound())
        && cd.kind != ColumnDefinition.Kind.REGULAR)
      throw new InvalidRequestException(
          "Secondary indexes are not supported on PRIMARY KEY columns in COMPACT STORAGE tables");

    // It would be possible to support 2ndary index on static columns (but not without modifications
    // of at least ExtendedFilter and
    // CompositesIndex) and maybe we should, but that means a query like:
    //     SELECT * FROM foo WHERE static_column = 'bar'
    // would pull the full partition every time the static column of partition is 'bar', which
    // sounds like offering a
    // fair potential for foot-shooting, so I prefer leaving that to a follow up ticket once we have
    // identified cases where
    // such indexing is actually useful.
    if (cd.isStatic())
      throw new InvalidRequestException("Secondary indexes are not allowed on static columns");

    if (cd.kind == ColumnDefinition.Kind.PARTITION_KEY && cd.isOnAllComponents())
      throw new InvalidRequestException(
          String.format("Cannot create secondary index on partition key column %s", target.column));
  }