Java Code Examples for com.datastax.driver.core.querybuilder.QueryBuilder#gt()

The following examples show how to use com.datastax.driver.core.querybuilder.QueryBuilder#gt() . 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: CassandraTable.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
protected Clause relation2Cql(Relation relation) {
    String key = relation.serialKey().toString();
    Object value = relation.serialValue();

    switch (relation.relation()) {
        case EQ:
            return QueryBuilder.eq(key, value);
        case GT:
            return QueryBuilder.gt(key, value);
        case GTE:
            return QueryBuilder.gte(key, value);
        case LT:
            return QueryBuilder.lt(key, value);
        case LTE:
            return QueryBuilder.lte(key, value);
        case IN:
            return QueryBuilder.in(key, value);
        case CONTAINS_VALUE:
            return QueryBuilder.contains(key, value);
        case CONTAINS_KEY:
            return QueryBuilder.containsKey(key, value);
        case SCAN:
            String[] col = pkColumnName().stream()
                                         .map(pk -> formatKey(pk))
                                         .toArray(String[]::new);
            Shard shard = (Shard) value;
            Object start = QueryBuilder.raw(shard.start());
            Object end = QueryBuilder.raw(shard.end());
            return Clauses.and(
                    QueryBuilder.gte(QueryBuilder.token(col), start),
                    QueryBuilder.lt(QueryBuilder.token(col), end));
        /*
         * Currently we can't support LIKE due to error:
         * "cassandra no viable alternative at input 'like'..."
         */
        // case LIKE:
        //    return QueryBuilder.like(key, value);
        case NEQ:
        default:
            throw new NotSupportException("relation '%s'", relation);
    }
}
 
Example 2
Source File: MultiShardMessageIterator.java    From usergrid with Apache License 2.0 4 votes vote down vote up
private void advance(){

        if (currentShard == null){
            currentShard = shardIterator.next();
        }

        Clause queueNameClause = QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName);
        Clause regionClause    = QueryBuilder.eq( COLUMN_REGION, region);
        Clause shardIdClause   = QueryBuilder.eq( COLUMN_SHARD_ID, currentShard.getShardId());

        // if we have a pointer from the shard and this is the first seek, init from the pointer's position
        if ( currentShard.getPointer() != null && nextStart == null ){
            nextStart = currentShard.getPointer();
        }

        Statement query;

        if ( nextStart == null) {

            query = QueryBuilder.select().all().from(QueueMessageSerializationImpl.getTableName(messageType))
                    .where(queueNameClause)
                    .and(regionClause)
                    .and(shardIdClause)
                    .limit(PAGE_SIZE);

        } else {

            Clause messageIdClause = QueryBuilder.gt( COLUMN_QUEUE_MESSAGE_ID, nextStart);
            query = QueryBuilder.select().all().from(QueueMessageSerializationImpl.getTableName(messageType))
                    .where(queueNameClause)
                    .and(regionClause)
                    .and(shardIdClause)
                    .and(messageIdClause)
                    .limit(PAGE_SIZE);
        }


        List<Row> rows = cassandraClient.getQueueMessageSession().execute(query).all();

        logger.trace("results {} from query {}", rows.size(), query.toString());

        if ( (rows == null || rows.size() == 0) && shardIterator.hasNext()) {

            currentShard = shardIterator.next();
            advance();

        } else {

            currentIterator = getIteratorFromRows(rows);

        }
    }
 
Example 3
Source File: ShardIterator.java    From usergrid with Apache License 2.0 3 votes vote down vote up
private void advance(){


        Clause queueNameClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_QUEUE_NAME, queueName);
        Clause regionClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_REGION, region);
        Clause activeClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_ACTIVE, 1);
        Clause shardIdClause;

        if (nextStart == 0L && lastShardId.isPresent()) {
            shardIdClause = QueryBuilder.gt( ShardSerializationImpl.COLUMN_SHARD_ID, lastShardId.get() );

        } else if (nextStart == 0L && !lastShardId.isPresent()) {
            shardIdClause = QueryBuilder.gte( ShardSerializationImpl.COLUMN_SHARD_ID, 0L );

        } else {
            shardIdClause = QueryBuilder.gt( ShardSerializationImpl.COLUMN_SHARD_ID, nextStart );
        }



        Statement query = QueryBuilder.select().all().from(ShardSerializationImpl.getTableName(shardType))
                .where(queueNameClause)
                .and(regionClause)
                .and(activeClause)
                .and(shardIdClause)
                .limit(PAGE_SIZE);

        List<Row> rows = cassandraClient.getQueueMessageSession().execute(query).all();


        currentIterator = getIteratorFromRows(rows);


    }