org.apache.cassandra.cql3.QueryOptions Java Examples

The following examples show how to use org.apache.cassandra.cql3.QueryOptions. 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: SSTableAttachedSecondaryIndexTest.java    From sasi with Apache License 2.0 6 votes vote down vote up
private Set<String> executeCQL(String rawStatement) throws Exception
{
    SelectStatement statement = (SelectStatement) QueryProcessor.parseStatement(rawStatement).prepare().statement;
    ResultMessage.Rows cqlRows = statement.executeInternal(QueryState.forInternalCalls(), new QueryOptions(ConsistencyLevel.LOCAL_ONE, Collections.<ByteBuffer>emptyList()));

    Set<String> results = new TreeSet<>();
    for (CqlRow row : cqlRows.toThriftResult().getRows())
    {
        for (org.apache.cassandra.thrift.Column col : row.columns)
        {
            String columnName = UTF8Type.instance.getString(col.bufferForName());
            if (columnName.equals("key"))
                results.add(AsciiType.instance.getString(col.bufferForValue()));
        }
    }

    return results;
}
 
Example #2
Source File: ExecuteMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public int encodedSize(ExecuteMessage msg, int version)
{
    int size = 0;
    size += CBUtil.sizeOfBytes(msg.statementId.bytes);
    if (version == 1)
    {
        size += CBUtil.sizeOfValueList(msg.options.getValues());
        size += CBUtil.sizeOfConsistencyLevel(msg.options.getConsistency());
    }
    else
    {
        size += QueryOptions.codec.encodedSize(msg.options, version);
    }
    return size;
}
 
Example #3
Source File: ExecuteMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void encode(ExecuteMessage msg, ByteBuf dest, int version)
{
    CBUtil.writeBytes(msg.statementId.bytes, dest);
    if (version == 1)
    {
        CBUtil.writeValueList(msg.options.getValues(), dest);
        CBUtil.writeConsistencyLevel(msg.options.getConsistency(), dest);
    }
    else
    {
        QueryOptions.codec.encode(msg.options, dest, version);
    }
}
 
Example #4
Source File: ExecuteMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ExecuteMessage decode(ByteBuf body, int version)
{
    byte[] id = CBUtil.readBytes(body);
    if (version == 1)
    {
        List<ByteBuffer> values = CBUtil.readValueList(body);
        ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body);
        return new ExecuteMessage(MD5Digest.wrap(id), QueryOptions.fromProtocolV1(consistency, values));
    }
    else
    {
        return new ExecuteMessage(MD5Digest.wrap(id), QueryOptions.codec.decode(body, version));
    }
}
 
Example #5
Source File: MultiColumnRestriction.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public List<List<ByteBuffer>> splitValues(QueryOptions options) throws InvalidRequestException
{
    List<List<ByteBuffer>> buffers = new ArrayList<>(values.size());
    for (Term value : values)
    {
        Term.MultiItemTerminal term = (Term.MultiItemTerminal)value.bind(options);
        buffers.add(term.getElements());
    }
    return buffers;
}
 
Example #6
Source File: MultiColumnRestriction.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public List<List<ByteBuffer>> splitValues(QueryOptions options) throws InvalidRequestException
{
    Tuples.InMarker inMarker = (Tuples.InMarker)marker;
    Tuples.InValue inValue = inMarker.bind(options);
    if (inValue == null)
        throw new InvalidRequestException("Invalid null value for IN restriction");
    return inValue.getSplitValues();
}
 
Example #7
Source File: QueryMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public int encodedSize(QueryMessage msg, int version)
{
    int size = CBUtil.sizeOfLongString(msg.query);

    if (version == 1)
    {
        size += CBUtil.sizeOfConsistencyLevel(msg.options.getConsistency());
    }
    else
    {
        size += QueryOptions.codec.encodedSize(msg.options, version);
    }
    return size;
}
 
Example #8
Source File: QueryMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void encode(QueryMessage msg, ByteBuf dest, int version)
{
    CBUtil.writeLongString(msg.query, dest);
    if (version == 1)
        CBUtil.writeConsistencyLevel(msg.options.getConsistency(), dest);
    else
        QueryOptions.codec.encode(msg.options, dest, version);
}
 
Example #9
Source File: QueryMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public QueryMessage decode(ByteBuf body, int version)
{
    String query = CBUtil.readLongString(body);
    if (version == 1)
    {
        ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body);
        return new QueryMessage(query, QueryOptions.fromProtocolV1(consistency, Collections.<ByteBuffer>emptyList()));
    }
    else
    {
        return new QueryMessage(query, QueryOptions.codec.decode(body, version));
    }
}
 
Example #10
Source File: SchemaAlteringStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ResultMessage executeInternal(QueryState state, QueryOptions options)
{
    try
    {
        boolean didChangeSchema = announceMigration(true);
        return didChangeSchema ? new ResultMessage.SchemaChange(changeEvent()) : new ResultMessage.Void();
    }
    catch (RequestValidationException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #11
Source File: SchemaAlteringStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ResultMessage execute(QueryState state, QueryOptions options) throws RequestValidationException
{
    // If an IF [NOT] EXISTS clause was used, this may not result in an actual schema change.  To avoid doing
    // extra work in the drivers to handle schema changes, we return an empty message in this case. (CASSANDRA-7600)
    boolean didChangeSchema = announceMigration(false);
    return didChangeSchema ? new ResultMessage.SchemaChange(changeEvent()) : new ResultMessage.Void();
}
 
Example #12
Source File: ExecuteMessage.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ExecuteMessage(MD5Digest statementId, QueryOptions options)
{
    super(Message.Type.EXECUTE);
    this.statementId = statementId;
    this.options = options;
}
 
Example #13
Source File: CassandraTypeDeserializerTest.java    From debezium-incubator with Apache License 2.0 4 votes vote down vote up
@Test
public void testUserType() {
    // this is slightly complicated, so we're testing in two parts:
    // first, explicitly test for schema correctness
    ByteBuffer expectedTypeName = ByteBuffer.wrap("FooType".getBytes(Charset.defaultCharset()));
    List<FieldIdentifier> expectedFieldIdentifiers = new ArrayList<>();
    expectedFieldIdentifiers.add(new FieldIdentifier(ByteBuffer.wrap("asciiField".getBytes(Charset.defaultCharset()))));
    expectedFieldIdentifiers.add(new FieldIdentifier(ByteBuffer.wrap("doubleField".getBytes(Charset.defaultCharset()))));
    expectedFieldIdentifiers.add(new FieldIdentifier(ByteBuffer.wrap("durationField".getBytes(Charset.defaultCharset()))));
    // testing duration to make sure that recursive deserialization works correctly
    List<AbstractType<?>> expectedFieldTypes = new ArrayList<>();
    expectedFieldTypes.add(AsciiType.instance);
    expectedFieldTypes.add(DoubleType.instance);
    expectedFieldTypes.add(DurationType.instance);
    UserType userType = new UserType("barspace",
            expectedTypeName,
            expectedFieldIdentifiers,
            expectedFieldTypes,
            true);

    Schema userSchema = CassandraTypeDeserializer.getSchemaBuilder(userType).build();

    long expectedNanoDuration = (30 + 2) * ChronoUnit.DAYS.getDuration().toNanos() + 3;

    Struct expectedUserTypeData = new Struct(userSchema)
            .put("asciiField", "foobar")
            .put("doubleField", 1.5d)
            .put("durationField", expectedNanoDuration);

    Map<String, Object> jsonObject = new HashMap<>(3);
    jsonObject.put("\"asciiField\"", "foobar");
    jsonObject.put("\"doubleField\"", 1.5d);
    jsonObject.put("\"durationField\"", DurationType.instance.getSerializer().toString(Duration.newInstance(1, 2, 3)));
    Term userTypeObject = userType.fromJSONObject(jsonObject);

    ByteBuffer buffer = userTypeObject.bindAndGet(QueryOptions.DEFAULT);

    ByteBuffer serializedUserTypeObject = userType.decompose(buffer);

    Object deserializedUserTypeObject = CassandraTypeDeserializer.deserialize(userType, serializedUserTypeObject);

    Assert.assertEquals(expectedUserTypeData, deserializedUserTypeObject);
}
 
Example #14
Source File: QueryMessage.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public QueryMessage(String query, QueryOptions options)
{
    super(Type.QUERY);
    this.query = query;
    this.options = options;
}
 
Example #15
Source File: UseStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ResultMessage executeInternal(QueryState state, QueryOptions options) throws InvalidRequestException
{
    // In production, internal queries are exclusively on the system keyspace and 'use' is thus useless
    // but for some unit tests we need to set the keyspace (e.g. for tests with DROP INDEX)
    return execute(state, options);
}
 
Example #16
Source File: UseStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ResultMessage execute(QueryState state, QueryOptions options) throws InvalidRequestException
{
    state.getClientState().setKeyspace(keyspace);
    return new ResultMessage.SetKeyspace(keyspace);
}
 
Example #17
Source File: AuthorizationStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ResultMessage executeInternal(QueryState state, QueryOptions options)
{
    // executeInternal is for local query only, thus altering permission doesn't make sense and is not supported
    throw new UnsupportedOperationException();
}
 
Example #18
Source File: AuthorizationStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ResultMessage execute(QueryState state, QueryOptions options)
throws RequestValidationException, RequestExecutionException
{
    return execute(state.getClientState());
}
 
Example #19
Source File: MultiColumnRestriction.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Similar to bounds(), but returns one ByteBuffer per-component in the bound instead of a single
 * ByteBuffer to represent the entire bound.
 */
public List<ByteBuffer> componentBounds(Bound b, QueryOptions options) throws InvalidRequestException
{
    Tuples.Value value = (Tuples.Value)bounds[b.idx].bind(options);
    return value.getElements();
}
 
Example #20
Source File: MultiColumnRestriction.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ByteBuffer bound(Bound b, QueryOptions options) throws InvalidRequestException
{
    throw new UnsupportedOperationException("Multicolumn slice restrictions do not support bound()");
}
 
Example #21
Source File: MultiColumnRestriction.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public List<ByteBuffer> values(QueryOptions options) throws InvalidRequestException
{
    Tuples.Value t = (Tuples.Value)value.bind(options);
    return t.getElements();
}
 
Example #22
Source File: AuthenticationStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ResultMessage executeInternal(QueryState state, QueryOptions options)
{
    // executeInternal is for local query only, thus altering users doesn't make sense and is not supported
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: AuthenticationStatement.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public ResultMessage execute(QueryState state, QueryOptions options)
throws RequestExecutionException, RequestValidationException
{
    return execute(state.getClientState());
}
 
Example #24
Source File: Restriction.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public List<ByteBuffer> values(QueryOptions options) throws InvalidRequestException; 
Example #25
Source File: Restriction.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public List<ByteBuffer> values(QueryOptions options) throws InvalidRequestException; 
Example #26
Source File: Restriction.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public ByteBuffer bound(Bound b, QueryOptions options) throws InvalidRequestException; 
Example #27
Source File: MultiColumnRestriction.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public List<List<ByteBuffer>> splitValues(QueryOptions options) throws InvalidRequestException;