org.apache.cassandra.exceptions.InvalidRequestException Java Examples

The following examples show how to use org.apache.cassandra.exceptions.InvalidRequestException. 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: Sets.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static Value fromSerialized(ByteBuffer value, SetType type, int version) throws InvalidRequestException
{
    try
    {
        // Collections have this small hack that validate cannot be called on a serialized object,
        // but compose does the validation (so we're fine).
        Set<?> s = (Set<?>)type.getSerializer().deserializeForNativeProtocol(value, version);
        SortedSet<ByteBuffer> elements = new TreeSet<ByteBuffer>(type.getElementsType());
        for (Object element : s)
            elements.add(type.getElementsType().decompose(element));
        return new Value(elements);
    }
    catch (MarshalException e)
    {
        throw new InvalidRequestException(e.getMessage());
    }
}
 
Example #2
Source File: UpdateStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Map<Term, Operation> getColumns() throws InvalidRequestException
{
    // Created from an UPDATE
    if (columns != null)
        return columns;

    // 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");

    columns = new HashMap<Term, Operation>();

    for (int i = 0; i < columnNames.size(); i++)
        columns.put(columnNames.get(i), new Operation(columnValues.get(i)));

    return columns;
}
 
Example #3
Source File: Maps.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Value bind(QueryOptions options) throws InvalidRequestException
{
    Map<ByteBuffer, ByteBuffer> buffers = new TreeMap<ByteBuffer, ByteBuffer>(comparator);
    for (Map.Entry<Term, Term> entry : elements.entrySet())
    {
        // We don't support values > 64K because the serialization format encode the length as an unsigned short.
        ByteBuffer keyBytes = entry.getKey().bindAndGet(options);
        if (keyBytes == null)
            throw new InvalidRequestException("null is not supported inside collections");
        if (keyBytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("Map key is too long. Map keys are limited to %d bytes but %d bytes keys provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            keyBytes.remaining()));

        ByteBuffer valueBytes = entry.getValue().bindAndGet(options);
        if (valueBytes == null)
            throw new InvalidRequestException("null is not supported inside collections");
        if (valueBytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("Map value is too long. Map values are limited to %d bytes but %d bytes value provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            valueBytes.remaining()));

        buffers.put(keyBytes, valueBytes);
    }
    return new Value(buffers);
}
 
Example #4
Source File: Attributes.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public long getTimestamp(long now, QueryOptions options) throws InvalidRequestException
{
    if (timestamp == null)
        return now;

    ByteBuffer tval = timestamp.bindAndGet(options);
    if (tval == null)
        throw new InvalidRequestException("Invalid null value of timestamp");

    try
    {
        LongType.instance.validate(tval);
    }
    catch (MarshalException e)
    {
        throw new InvalidRequestException("Invalid timestamp value");
    }

    return LongType.instance.compose(tval);
}
 
Example #5
Source File: PerRowSecondaryIndexTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
protected SecondaryIndexSearcher createSecondaryIndexSearcher(Set<ByteBuffer> columns)
{
    return new SecondaryIndexSearcher(baseCfs.indexManager, columns)
    {
        
        @Override
        public List<Row> search(ExtendedFilter filter)
        {
            return Arrays.asList(new Row(LAST_INDEXED_KEY, LAST_INDEXED_ROW));
        }

        @Override
        public void validate(IndexExpression indexExpression) throws InvalidRequestException
        {
            if (indexExpression.value.equals(ByteBufferUtil.bytes("invalid")))
                throw new InvalidRequestException("Invalid search!");
        }
        
    };
}
 
Example #6
Source File: SelectStatementTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Test 'clustering_0 IN (1, 2, 3)' with only one clustering column
 */
@Test
public void testBuildBoundWithOneInRestrictionsAndOneClusteringColumn() throws InvalidRequestException
{
    ByteBuffer value1 = ByteBufferUtil.bytes(1);
    ByteBuffer value2 = ByteBufferUtil.bytes(2);
    ByteBuffer value3 = ByteBufferUtil.bytes(3);
    SingleColumnRestriction.IN in = new SingleColumnRestriction.InWithValues(toTerms(value1, value2, value3));
    Restriction[] restrictions = new Restriction[] { in };

    List<Composite> bounds = executeBuildBound(restrictions, Bound.START);
    assertEquals(3, bounds.size());
    assertComposite(bounds.get(0), value1, EOC.START);
    assertComposite(bounds.get(1), value2, EOC.START);
    assertComposite(bounds.get(2), value3, EOC.START);

    bounds = executeBuildBound(restrictions, Bound.END);
    assertEquals(3, bounds.size());
    assertComposite(bounds.get(0), value1, EOC.END);
    assertComposite(bounds.get(1), value2, EOC.END);
    assertComposite(bounds.get(2), value3, EOC.END);
}
 
Example #7
Source File: DeleteStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: Sets.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
    if (!(receiver.type instanceof SetType))
    {
        // We've parsed empty maps as a set literal to break the ambiguity so
        // handle that case now
        if ((receiver.type instanceof MapType) && elements.isEmpty())
            return;

        throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver.name, receiver.type.asCQL3Type()));
    }

    ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
    for (Term.Raw rt : elements)
    {
        if (!rt.isAssignableTo(keyspace, valueSpec))
            throw new InvalidRequestException(String.format("Invalid set literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type()));
    }
}
 
Example #9
Source File: Sets.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Value bind(QueryOptions options) throws InvalidRequestException
{
    SortedSet<ByteBuffer> buffers = new TreeSet<>(comparator);
    for (Term t : elements)
    {
        ByteBuffer bytes = t.bindAndGet(options);

        if (bytes == null)
            throw new InvalidRequestException("null is not supported inside collections");

        // We don't support value > 64K because the serialization format encode the length as an unsigned short.
        if (bytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("Set value is too long. Set values are limited to %d bytes but %d bytes value provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            bytes.remaining()));

        buffers.add(bytes);
    }
    return new Value(buffers);
}
 
Example #10
Source File: CqlBulkRecordWriter.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * The column values must correspond to the order in which
 * they appear in the insert stored procedure. 
 * 
 * Key is not used, so it can be null or any object.
 * </p>
 *
 * @param key
 *            any object or null.
 * @param values
 *            the values to write.
 * @throws IOException
 */
@Override
public void write(Object key, List<ByteBuffer> values) throws IOException
{
    prepareWriter();
    try
    {
        ((CQLSSTableWriter) writer).rawAddRow(values);
        
        if (null != progress)
            progress.progress();
        if (null != context)
            HadoopCompat.progress(context);
    } 
    catch (InvalidRequestException e)
    {
        throw new IOException("Error adding row with key: " + key, e);
    }
}
 
Example #11
Source File: TriggerExecutor.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void validateForSinglePartition(AbstractType<?> keyValidator,
                                        UUID cfId,
                                        ByteBuffer key,
                                        Collection<Mutation> tmutations)
throws InvalidRequestException
{
    for (Mutation mutation : tmutations)
    {
        if (keyValidator.compare(mutation.key(), key) != 0)
            throw new InvalidRequestException("Partition key of additional mutation does not match primary update key");

        for (ColumnFamily cf : mutation.getColumnFamilies())
        {
            if (! cf.id().equals(cfId))
                throw new InvalidRequestException("Column family of additional mutation does not match primary update cf");
        }
    }
    validate(tmutations);
}
 
Example #12
Source File: Operation.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Operation prepare(String keyspace, ColumnDefinition receiver) throws InvalidRequestException
{
    if (!(receiver.type.isCollection()))
        throw new InvalidRequestException(String.format("Invalid deletion operation for non collection column %s", receiver.name));
    else if (!(receiver.type.isMultiCell()))
        throw new InvalidRequestException(String.format("Invalid deletion operation for frozen collection column %s", receiver.name));

    switch (((CollectionType)receiver.type).kind)
    {
        case LIST:
            Term idx = element.prepare(keyspace, Lists.indexSpecOf(receiver));
            return new Lists.DiscarderByIndex(receiver, idx);
        case SET:
            Term elt = element.prepare(keyspace, Sets.valueSpecOf(receiver));
            return new Sets.ElementDiscarder(receiver, elt);
        case MAP:
            Term key = element.prepare(keyspace, Maps.keySpecOf(receiver));
            return new Maps.DiscarderByKey(receiver, key);
    }
    throw new AssertionError();
}
 
Example #13
Source File: SelectStatementTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Calls the <code>SelectStatement.buildBound</code> with the specified restrictions.
 *
 * @param restrictions the restrictions
 * @return the result from the method call to <code>SelectStatement.buildBound</code>
 * @throws InvalidRequestException if the method call throw an exception
 */
private static List<Composite> executeBuildBound(Restriction[] restrictions,
                                                 Bound bound) throws InvalidRequestException
{
    List<AbstractType<?>> types = new ArrayList<>();

    for (int i = 0, m = restrictions.length; i < m; i++)
        types.add(Int32Type.instance);

    CompoundSparseCellNameType cType = new CompoundSparseCellNameType(types);
    CFMetaData cfMetaData = new CFMetaData("keyspace", "test", ColumnFamilyType.Standard, cType);

    List<ColumnDefinition> columnDefs = new ArrayList<>();
    for (int i = 0, m = restrictions.length; i < m; i++)
    {
        ByteBuffer name = ByteBufferUtil.bytes("clustering_" + i);
        columnDefs.add(ColumnDefinition.clusteringKeyDef(cfMetaData, name, types.get(i), i));
    }

    return SelectStatement.buildBound(bound, columnDefs, restrictions, false, cType, QueryOptions.DEFAULT);
}
 
Example #14
Source File: SelectStatementTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Test '(clustering_0, clustering_1) = (1, 2)' with two clustering column
 */
@Test
public void testBuildBoundWithMultiEqRestrictions() throws InvalidRequestException
{
    ByteBuffer value1 = ByteBufferUtil.bytes(1);
    ByteBuffer value2 = ByteBufferUtil.bytes(2);
    MultiColumnRestriction.EQ eq = new MultiColumnRestriction.EQ(toMultiItemTerminal(value1, value2), false);
    Restriction[] restrictions = new Restriction[] { eq, eq };

    List<Composite> bounds = executeBuildBound(restrictions, Bound.START);
    assertEquals(1, bounds.size());
    assertComposite(bounds.get(0), value1, value2, EOC.START);

    bounds = executeBuildBound(restrictions, Bound.END);
    assertEquals(1, bounds.size());
    assertComposite(bounds.get(0), value1, value2, EOC.END);
}
 
Example #15
Source File: TriggerExecutorTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void differentKeyRowMutations() throws ConfigurationException, InvalidRequestException
{
    CFMetaData metadata = makeCfMetaData("ks1", "cf1", TriggerDefinition.create("test", DifferentKeyTrigger.class.getName()));
    ColumnFamily cf = makeCf(metadata, "v1", null);
    Mutation rm = new Mutation(UTF8Type.instance.fromString("k1"), cf);

    List<? extends IMutation> tmutations = new ArrayList<>(TriggerExecutor.instance.execute(Arrays.asList(rm)));
    assertEquals(2, tmutations.size());
    Collections.sort(tmutations, new RmComparator());

    assertEquals(bytes("k1"), tmutations.get(0).key());
    assertEquals(bytes("otherKey"), tmutations.get(1).key());

    List<ColumnFamily> mutatedCFs = new ArrayList<>(tmutations.get(0).getColumnFamilies());
    assertEquals(1, mutatedCFs.size());
    assertEquals(bytes("v1"), mutatedCFs.get(0).getColumn(getColumnName(metadata, "c1")).value());
    assertNull(mutatedCFs.get(0).getColumn(getColumnName(metadata, "c2")));

    mutatedCFs = new ArrayList<>(tmutations.get(1).getColumnFamilies());
    assertEquals(1, mutatedCFs.size());
    assertNull(mutatedCFs.get(0).getColumn(getColumnName(metadata, "c1")));
    assertEquals(bytes("trigger"), mutatedCFs.get(0).getColumn(getColumnName(metadata, "c2")).value());
}
 
Example #16
Source File: PerRowSecondaryIndexTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidSearch() throws IOException
{
    Mutation rm;
    rm = new Mutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k4"));
    rm.add("Indexed1", Util.cellname("indexed"), ByteBufferUtil.bytes("foo"), 1);
    rm.apply();
    
    // test we can search:
    UntypedResultSet result = QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'foo'");
    assertEquals(1, result.size());

    // test we can't search if the searcher doesn't validate the expression:
    try
    {
        QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'invalid'");
        fail("Query should have been invalid!");
    }
    catch (Exception e)
    {
        assertTrue(e instanceof InvalidRequestException || (e.getCause() != null && (e.getCause() instanceof InvalidRequestException)));
    }
}
 
Example #17
Source File: Lists.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException
{
    assert column.type.isMultiCell() : "Attempted to prepend to a frozen list";
    Term.Terminal value = t.bind(params.options);
    if (value == null)
        return;

    assert value instanceof Lists.Value;
    long time = PrecisionTime.REFERENCE_TIME - (System.currentTimeMillis() - PrecisionTime.REFERENCE_TIME);

    List<ByteBuffer> toAdd = ((Lists.Value)value).elements;
    for (int i = toAdd.size() - 1; i >= 0; i--)
    {
        PrecisionTime pt = PrecisionTime.getNext(time);
        ByteBuffer uuid = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(pt.millis, pt.nanos));
        cf.addColumn(params.makeColumn(cf.getComparator().create(prefix, column, uuid), toAdd.get(i)));
    }
}
 
Example #18
Source File: CreateKeyspaceStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * The <code>CqlParser</code> only goes as far as extracting the keyword arguments
 * from these statements, so this method is responsible for processing and
 * validating.
 *
 * @throws InvalidRequestException if arguments are missing or unacceptable
 */
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateKeyspaceNotSystem(name);

    // keyspace name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
    if (name.length() > Schema.NAME_LENGTH)
        throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));

    attrs.validate();

    if (attrs.getReplicationStrategyClass() == null)
        throw new ConfigurationException("Missing mandatory replication strategy class");

    // The strategy is validated through KSMetaData.validate() in announceNewKeyspace below.
    // However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
    // so doing proper validation here.
    AbstractReplicationStrategy.validateReplicationStrategy(name,
                                                            AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
                                                            StorageService.instance.getTokenMetadata(),
                                                            DatabaseDescriptor.getEndpointSnitch(),
                                                            attrs.getReplicationOptions());
}
 
Example #19
Source File: CQL3CasRequest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public boolean appliesTo(ColumnFamily current) throws InvalidRequestException
{
    for (RowCondition condition : conditions.values())
    {
        if (!condition.appliesTo(current))
            return false;
    }
    return true;
}
 
Example #20
Source File: Lists.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
static void doAppend(Term t, ColumnFamily cf, Composite prefix, ColumnDefinition column, UpdateParameters params) throws InvalidRequestException
{
    Term.Terminal value = t.bind(params.options);
    Lists.Value listValue = (Lists.Value)value;
    if (column.type.isMultiCell())
    {
        // If we append null, do nothing. Note that for Setter, we've
        // already removed the previous value so we're good here too
        if (value == null)
            return;

        List<ByteBuffer> toAdd = listValue.elements;
        for (int i = 0; i < toAdd.size(); i++)
        {
            ByteBuffer uuid = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes());
            cf.addColumn(params.makeColumn(cf.getComparator().create(prefix, column, uuid), toAdd.get(i)));
        }
    }
    else
    {
        // for frozen lists, we're overwriting the whole cell value
        CellName name = cf.getComparator().create(prefix, column);
        if (value == null)
            cf.addAtom(params.makeTombstone(name));
        else
            cf.addColumn(params.makeColumn(name, listValue.getWithProtocolVersion(Server.CURRENT_VERSION)));
    }
}
 
Example #21
Source File: Operation.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Operation prepare(String keyspace, ColumnDefinition receiver) throws InvalidRequestException
{
    if (!(receiver.type instanceof CollectionType))
    {
        if (!(receiver.type instanceof CounterColumnType))
            throw new InvalidRequestException(String.format("Invalid operation (%s) for non counter column %s", toString(receiver), receiver.name));
        return new Constants.Substracter(receiver, value.prepare(keyspace, receiver));
    }
    else if (!(receiver.type.isMultiCell()))
        throw new InvalidRequestException(String.format("Invalid operation (%s) for frozen collection column %s", toString(receiver), receiver.name));

    switch (((CollectionType)receiver.type).kind)
    {
        case LIST:
            return new Lists.Discarder(receiver, value.prepare(keyspace, receiver));
        case SET:
            return new Sets.Discarder(receiver, value.prepare(keyspace, receiver));
        case MAP:
            // The value for a map subtraction is actually a set
            ColumnSpecification vr = new ColumnSpecification(receiver.ksName,
                                                             receiver.cfName,
                                                             receiver.name,
                                                             SetType.getInstance(((MapType)receiver.type).getKeysType(), false));
            return new Sets.Discarder(receiver, value.prepare(keyspace, vr));
    }
    throw new AssertionError();
}
 
Example #22
Source File: Maps.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException
{
    if (column.type.isMultiCell())
    {
        // delete + put
        CellName name = cf.getComparator().create(prefix, column);
        cf.addAtom(params.makeTombstoneForOverwrite(name.slice()));
    }
    Putter.doPut(t, cf, prefix, column, params);
}
 
Example #23
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ByteBuffer compute(ResultSetBuilder rs) throws InvalidRequestException
{
    List<ByteBuffer> args = new ArrayList<ByteBuffer>(argSelectors.size());
    for (Selector s : argSelectors)
        args.add(s.compute(rs));

    return fun.execute(args);
}
 
Example #24
Source File: CQLSSTableWriterClientTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriterInClientMode() throws IOException, InvalidRequestException
{
    final String TABLE1 = "table1";
    final String TABLE2 = "table2";

    String schema = "CREATE TABLE client_test.%s ("
                        + "  k int PRIMARY KEY,"
                        + "  v1 text,"
                        + "  v2 int"
                        + ")";
    String insert = "INSERT INTO client_test.%s (k, v1, v2) VALUES (?, ?, ?)";

    CQLSSTableWriter writer = CQLSSTableWriter.builder()
                                              .inDirectory(this.testDirectory)
                                              .forTable(String.format(schema, TABLE1))
                                              .using(String.format(insert, TABLE1)).build();

    CQLSSTableWriter writer2 = CQLSSTableWriter.builder()
                                               .inDirectory(this.testDirectory)
                                               .forTable(String.format(schema, TABLE2))
                                               .using(String.format(insert, TABLE2)).build();

    writer.addRow(0, "A", 0);
    writer2.addRow(0, "A", 0);
    writer.addRow(1, "B", 1);
    writer2.addRow(1, "B", 1);
    writer.close();
    writer2.close();

    assertContainsDataFiles(this.testDirectory, "client_test-table1", "client_test-table2");
}
 
Example #25
Source File: CQL3Type.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public CQL3Type prepare(String keyspace) throws InvalidRequestException
{
    if (name.hasKeyspace())
    {
        // The provided keyspace is the one of the current statement this is part of. If it's different from the keyspace of
        // the UTName, we reject since we want to limit user types to their own keyspace (see #6643)
        if (!keyspace.equals(name.getKeyspace()))
            throw new InvalidRequestException(String.format("Statement on keyspace %s cannot refer to a user type in keyspace %s; "
                                                            + "user types can only be used in the keyspace they are defined in",
                                                            keyspace, name.getKeyspace()));
    }
    else
    {
        name.setKeyspace(keyspace);
    }

    KSMetaData ksm = Schema.instance.getKSMetaData(name.getKeyspace());
    if (ksm == null)
        throw new InvalidRequestException("Unknown keyspace " + name.getKeyspace());
    UserType type = ksm.userTypes.getType(name.getUserTypeName());
    if (type == null)
        throw new InvalidRequestException("Unknown type " + name);

    if (!frozen)
        throw new InvalidRequestException("Non-frozen User-Defined types are not supported, please use frozen<>");

    return new UserDefined(name.toString(), type);
}
 
Example #26
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static void validateComposite(Composite name, CType type) throws InvalidRequestException
{
    long serializedSize = type.serializer().serializedSize(name, TypeSizes.NATIVE);
    if (serializedSize > Cell.MAX_NAME_LENGTH)
        throw new InvalidRequestException(String.format("The sum of all clustering columns is too long (%s > %s)",
                                                        serializedSize,
                                                        Cell.MAX_NAME_LENGTH));
}
 
Example #27
Source File: Lists.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException
{
    if (column.type.isMultiCell())
    {
        // delete + append
        CellName name = cf.getComparator().create(prefix, column);
        cf.addAtom(params.makeTombstoneForOverwrite(name.slice()));
    }
    Appender.doAppend(t, cf, prefix, column, params);
}
 
Example #28
Source File: SingleColumnRestriction.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Override
public final void setBound(Operator operator, Term t) throws InvalidRequestException
{
    Bound b;
    boolean inclusive;
    switch (operator)
    {
        case GT:
            b = Bound.START;
            inclusive = false;
            break;
        case GTE:
            b = Bound.START;
            inclusive = true;
            break;
        case LT:
            b = Bound.END;
            inclusive = false;
            break;
        case LTE:
            b = Bound.END;
            inclusive = true;
            break;
        default:
            throw new AssertionError();
    }

    assert bounds[b.idx] == null;

    bounds[b.idx] = t;
    boundInclusive[b.idx] = inclusive;
}
 
Example #29
Source File: SingleColumnRestriction.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public List<ByteBuffer> values(QueryOptions options) throws InvalidRequestException
{
    Term.MultiItemTerminal lval = (Term.MultiItemTerminal)marker.bind(options);
    if (lval == null)
        throw new InvalidRequestException("Invalid null value for IN restriction");
    return lval.getElements();
}
 
Example #30
Source File: PermissionAlteringStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void validate(ClientState state) throws RequestValidationException
{
    // validate login here before checkAccess to avoid leaking user existence to anonymous users.
    state.ensureNotAnonymous();

    if (!Auth.isExistingUser(username))
        throw new InvalidRequestException(String.format("User %s doesn't exist", username));

    // if a keyspace is omitted when GRANT/REVOKE ON TABLE <table>, we need to correct the resource.
    resource = maybeCorrectResource(resource, state);
    if (!resource.exists())
        throw new InvalidRequestException(String.format("%s doesn't exist", resource));
}