Package org.apache.cassandra.thrift

Examples of org.apache.cassandra.thrift.InvalidRequestException


            for (ColumnDef cd : cf_def.column_metadata)
            {
                if (cd.name.equals(columnName.key))
                {
                    if (cd.index_type != null)
                        throw new InvalidRequestException("Index already exists");
                    if (logger.isDebugEnabled())
                        logger.debug("Updating column {} definition for index {}", columnName, indexName);
                    cd.setIndex_type(IndexType.KEYS);
                    cd.setIndex_name(indexName);
                    columnExists = true;
                    break;
                }
            }
            if (!columnExists)
            {
                CFDefinition cfDef = oldCfm.getCfDef();
                CFDefinition.Name name = cfDef.get(columnName);
                if (name != null)
                {
                    switch (name.kind)
                    {
                        case KEY_ALIAS:
                        case COLUMN_ALIAS:
                            throw new InvalidRequestException(String.format("Cannot create index on PRIMARY KEY part %s", columnName));
                        case VALUE_ALIAS:
                            throw new InvalidRequestException(String.format("Cannot create index on column %s of compact CF", columnName));
                    }
                }
                throw new InvalidRequestException("No column definition found for column " + columnName);
            }

            CFMetaData.addDefaultIndexNames(cf_def);
            ThriftValidation.validateCfDef(cf_def, oldCfm);
            return new UpdateColumnFamily(cf_def);
View Full Code Here


    {
        cfProps.validate();

        // Column family name
        if (!name.matches("\\w+"))
            throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name", name));
        if (name.length() > 32)
            throw new InvalidRequestException(String.format("Column family names shouldn't be more than 32 character long (got \"%s\")", name));
       
        // Ensure that exactly one key has been specified.
        if (keyValidator.size() < 1)
            throw new InvalidRequestException("You must specify a PRIMARY KEY");
        else if (keyValidator.size() > 1)
            throw new InvalidRequestException("You may only specify one PRIMARY KEY");

        AbstractType<?> comparator;

        try
        {
            comparator = cfProps.getComparator();
        }
        catch (ConfigurationException e)
        {
            throw new InvalidRequestException(e.toString());
        }

        for (Map.Entry<Term, String> column : columns.entrySet())
        {
            ByteBuffer name = column.getKey().getByteBuffer(comparator, variables);

            if (keyAlias != null && keyAlias.equals(name))
                throw new InvalidRequestException("Invalid column name: "
                                                  + column.getKey().getText()
                                                  + ", because it equals to the key_alias.");

        }
    }
View Full Code Here

                AbstractType<?> validator = TypeParser.parse(validatorClassName);
                columnDefs.put(columnName, new ColumnDefinition(columnName, validator, null, null, null));
            }
            catch (ConfigurationException e)
            {
                InvalidRequestException ex = new InvalidRequestException(e.toString());
                ex.initCause(e);
                throw ex;
            }
        }
       
        return columnDefs;
View Full Code Here

                   .compressionParameters(CompressionParameters.create(cfProps.compressionParameters))
                   .validate();
        }
        catch (ConfigurationException e)
        {
            throw new InvalidRequestException(e.toString());
        }
        return newCFMD;
    }
View Full Code Here

    public List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables) throws InvalidRequestException
    {
        // Check key
        List<Term> keys = processedKeys.get(cfDef.key.name);
        if (keys == null || keys.isEmpty())
            throw new InvalidRequestException(String.format("Missing mandatory PRIMARY KEY part %s", cfDef.key));

        ColumnNameBuilder builder = cfDef.getColumnNameBuilder();
        CFDefinition.Name firstEmpty = null;
        for (CFDefinition.Name name : cfDef.columns.values())
        {
            List<Term> values = processedKeys.get(name.name);
            if (values == null || values.isEmpty())
            {
                firstEmpty = name;
                // For sparse, we must have all components
                if (cfDef.isComposite && !cfDef.isCompact)
                    throw new InvalidRequestException(String.format("Missing mandatory PRIMARY KEY part %s", name));
            }
            else if (firstEmpty != null)
            {
                throw new InvalidRequestException(String.format("Missing PRIMARY KEY part %s since %s is set", firstEmpty.name, name.name));
            }
            else
            {
                assert values.size() == 1; // We only allow IN for row keys so far
                builder.add(values.get(0), Relation.Type.EQ, variables);
View Full Code Here

        RowMutation rm = new RowMutation(cfDef.cfm.ksName, key);

        if (cfDef.isCompact)
        {
            if (builder.componentCount() == 0)
                throw new InvalidRequestException(String.format("Missing PRIMARY KEY part %s", cfDef.columns.values().iterator().next()));

            Operation value = processedColumns.get(cfDef.value.name);
            if (value == null)
                throw new InvalidRequestException(String.format("Missing mandatory column %s", cfDef.value));
            hasCounterColumn = addToMutation(clientState, rm, builder.build(), cfDef.value, value, variables);
        }
        else
        {
            for (CFDefinition.Name name : cfDef.metadata.values())
View Full Code Here

            return false;
        }
        else
        {
            if (!valueDef.name.equals(value.ident))
                throw new InvalidRequestException("Only expressions like X = X + <long> are supported.");

            long val;
            try
            {
                val = ByteBufferUtil.toLong(value.value.getByteBuffer(LongType.instance, variables));
            }
            catch (NumberFormatException e)
            {
                throw new InvalidRequestException(String.format("'%s' is an invalid value, should be a long.",
                            value.value.getText()));
            }

            if (value.type == Operation.Type.MINUS)
            {
                if (val == Long.MIN_VALUE)
                    throw new InvalidRequestException("The negation of " + val + " overflows supported integer precision (signed 8 bytes integer)");
                else
                    val = -val;
            }
            rm.addCounter(new QueryPath(columnFamily(), null, colName), val);
            return true;
View Full Code Here

            {
                if (!column.getValue().isUnary())
                    hasCommutativeOperation = true;

                if (hasCommutativeOperation && column.getValue().isUnary())
                    throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");
            }
        }

        // Deal here with the keyspace overwrite thingy to avoid mistake
        CFMetaData metadata = validateColumnFamily(keyspace(), columnFamily(), hasCommutativeOperation);
        if (hasCommutativeOperation)
            validateCommutativeForWrite(metadata, cLevel);

        cfDef = metadata.getCfDef();

        if (columns == null)
        {
            // Created from an INSERT
            // Don't hate, validate.
            if (columnNames.size() != columnValues.size())
                throw new InvalidRequestException("unmatched column names/values");
            if (columnNames.size() < 1)
                throw new InvalidRequestException("no columns specified for INSERT");

            for (int i = 0; i < columnNames.size(); i++)
            {
                CFDefinition.Name name = cfDef.get(columnNames.get(i));
                if (name == null)
                    throw new InvalidRequestException(String.format("Unknown identifier %s", columnNames.get(i)));

                Term value = columnValues.get(i);
                if (value.isBindMarker())
                    types[value.bindIndex] = name.type;

                switch (name.kind)
                {
                    case KEY_ALIAS:
                    case COLUMN_ALIAS:
                        if (processedKeys.containsKey(name.name))
                            throw new InvalidRequestException(String.format("Multiple definition found for PRIMARY KEY part %s", name));
                        processedKeys.put(name.name, Collections.singletonList(value));
                        break;
                    case VALUE_ALIAS:
                    case COLUMN_METADATA:
                        if (processedColumns.containsKey(name.name))
                            throw new InvalidRequestException(String.format("Multiple definition found for column %s", name));
                        processedColumns.put(name.name, new Operation(value));
                        break;
                }
            }
        }
        else
        {
            // Created from an UPDATE
            for (Map.Entry<ColumnIdentifier, Operation> entry : columns.entrySet())
            {
                CFDefinition.Name name = cfDef.get(entry.getKey());
                if (name == null)
                    throw new InvalidRequestException(String.format("Unknown identifier %s", entry.getKey()));

                switch (name.kind)
                {
                    case KEY_ALIAS:
                    case COLUMN_ALIAS:
                        throw new InvalidRequestException(String.format("PRIMARY KEY part %s found in SET part", entry.getKey()));
                    case VALUE_ALIAS:
                    case COLUMN_METADATA:
                        if (processedColumns.containsKey(name.name))
                            throw new InvalidRequestException(String.format("Multiple definition found for column %s", name));
                        Operation op = entry.getValue();
                        if (op.value.isBindMarker())
                            types[op.value.bindIndex] = name.type;
                        processedColumns.put(name.name, op);
                        break;
View Full Code Here

    {
        for (Relation rel : keys)
        {
            CFDefinition.Name name = cfDef.get(rel.getEntity());
            if (name == null)
                throw new InvalidRequestException(String.format("Unknown key identifier %s", rel.getEntity()));

            switch (name.kind)
            {
                case KEY_ALIAS:
                case COLUMN_ALIAS:
                    List<Term> values;
                    if (rel.operator() == Relation.Type.EQ)
                        values = Collections.singletonList(rel.getValue());
                    else if (name.kind == CFDefinition.Name.Kind.KEY_ALIAS && rel.operator() == Relation.Type.IN)
                        values = rel.getInValues();
                    else
                        throw new InvalidRequestException(String.format("Invalid operator %s for key %s", rel.operator(), rel.getEntity()));

                    if (processed.containsKey(name.name))
                        throw new InvalidRequestException(String.format("Multiple definition found for PRIMARY KEY part %s", name));
                    for (Term value : values)
                        if (value.isBindMarker())
                            types[value.bindIndex] = name.type;
                    processed.put(name.name, values);
                    break;
                case VALUE_ALIAS:
                case COLUMN_METADATA:
                    throw new InvalidRequestException(String.format("PRIMARY KEY part %s found in SET part", rel.getEntity()));
            }
        }
    }
View Full Code Here

     */
    public void validate() throws InvalidRequestException
    {
        // keyspace name
        if (!name.matches("\\w+"))
            throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
        if (name.length() > 32)
            throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than 32 character long (got \"%s\")", name));
       
        // required
        if (!attrs.containsKey("strategy_class"))
            throw new InvalidRequestException("missing required argument \"strategy_class\"");
        strategyClass = attrs.get("strategy_class");
       
        // optional
        for (String key : attrs.keySet())
            if ((key.contains(":")) && (key.startsWith("strategy_options")))
                strategyOptions.put(key.split(":")[1], attrs.get(key));

        // trial run to let ARS validate class + per-class options
        try
        {
            AbstractReplicationStrategy.createReplicationStrategy(name,
                                                                  AbstractReplicationStrategy.getClass(strategyClass),
                                                                  StorageService.instance.getTokenMetadata(),
                                                                  DatabaseDescriptor.getEndpointSnitch(),
                                                                  strategyOptions);
        }
        catch (ConfigurationException e)
        {
            throw new InvalidRequestException(e.getMessage());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cassandra.thrift.InvalidRequestException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.