Search in sources :

Example 1 with ExpressionSymbol

use of com.cinchapi.ccl.grammar.ExpressionSymbol in project concourse by cinchapi.

the class CriteriaTest method testTimestampPinningSomeTimestamps.

@Test
public void testTimestampPinningSomeTimestamps() {
    Criteria criteria = Criteria.where().key("name").operator(Operator.EQUALS).value("Jeff Nelson").and().group(Criteria.where().key("company").operator(Operator.EQUALS).value("Cinchapi").at(Timestamp.now()).or().key("company").operator(Operator.EQUALS).value("Blavity")).build();
    Timestamp timestamp = Timestamp.now();
    criteria = criteria.at(timestamp);
    List<Symbol> symbols = Parsing.groupExpressions(criteria.symbols());
    symbols.forEach((symbol) -> {
        if (symbol instanceof ExpressionSymbol) {
            ExpressionSymbol expression = (ExpressionSymbol) symbol;
            Assert.assertEquals(expression.raw().timestamp(), timestamp.getMicros());
        }
    });
}
Also used : KeySymbol(com.cinchapi.ccl.grammar.KeySymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Symbol(com.cinchapi.ccl.grammar.Symbol) NavigationKeySymbol(com.cinchapi.ccl.grammar.NavigationKeySymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Timestamp(com.cinchapi.concourse.Timestamp) Test(org.junit.Test)

Example 2 with ExpressionSymbol

use of com.cinchapi.ccl.grammar.ExpressionSymbol in project concourse by cinchapi.

the class CriteriaTest method testTimestampPinning.

@Test
public void testTimestampPinning() {
    Criteria criteria = Criteria.where().key("name").operator(Operator.EQUALS).value("Jeff Nelson").and().group(Criteria.where().key("company").operator(Operator.EQUALS).value("Cinchapi").or().key("company").operator(Operator.EQUALS).value("Blavity")).build();
    Timestamp timestamp = Timestamp.now();
    criteria = criteria.at(timestamp);
    List<Symbol> symbols = Parsing.groupExpressions(criteria.symbols());
    symbols.forEach((symbol) -> {
        if (symbol instanceof ExpressionSymbol) {
            ExpressionSymbol expression = (ExpressionSymbol) symbol;
            Assert.assertEquals(expression.raw().timestamp(), timestamp.getMicros());
        }
    });
}
Also used : KeySymbol(com.cinchapi.ccl.grammar.KeySymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Symbol(com.cinchapi.ccl.grammar.Symbol) NavigationKeySymbol(com.cinchapi.ccl.grammar.NavigationKeySymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Timestamp(com.cinchapi.concourse.Timestamp) Test(org.junit.Test)

Example 3 with ExpressionSymbol

use of com.cinchapi.ccl.grammar.ExpressionSymbol in project concourse by cinchapi.

the class BuiltCriteria method at.

/**
 * Return this {@link Criteria} with each expression (e.g. {key} {operator}
 * {values}) pinned to the specified {@code timestamp}.
 *
 * <strong>NOTE:</strong> Any timestamps that are pinned to any expressions
 * within this Criteria will be replaced by the specified {@code timestamp}.
 *
 * @param timestamp the {@link Timestamp} to which the returned
 *            {@link Criteria} is pinned
 *
 * @return this {@link Criteria} pinned to {@code timestamp}
 */
public Criteria at(Timestamp timestamp) {
    AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl());
    List<Symbol> symbols = Parsing.groupExpressions(ConcourseCompiler.get().tokenize(ast));
    TimestampSymbol ts = new TimestampSymbol(timestamp.getMicros());
    symbols.forEach((symbol) -> {
        if (symbol instanceof ExpressionSymbol) {
            ExpressionSymbol expression = (ExpressionSymbol) symbol;
            expression.timestamp(ts);
        }
    });
    BuiltCriteria criteria = new BuiltCriteria();
    symbols = Parsing.ungroupExpressions(symbols);
    criteria.symbols = symbols;
    return criteria;
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) TimestampSymbol(com.cinchapi.ccl.grammar.TimestampSymbol) ParenthesisSymbol(com.cinchapi.ccl.grammar.ParenthesisSymbol) Symbol(com.cinchapi.ccl.grammar.Symbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) TimestampSymbol(com.cinchapi.ccl.grammar.TimestampSymbol)

Example 4 with ExpressionSymbol

use of com.cinchapi.ccl.grammar.ExpressionSymbol in project concourse by cinchapi.

the class ConcourseCompilerTest method testParseCclValueWithoutQuotesAnd.

@Test
public void testParseCclValueWithoutQuotesAnd() {
    String ccl = "name = jeff nelson and favorite_player != Lebron James";
    Queue<PostfixNotationSymbol> symbols = ConcourseCompiler.get().arrange((ConditionTree) ConcourseCompiler.get().parse(ccl));
    Assert.assertEquals(3, symbols.size());
    for (int i = 0; i < 2; ++i) {
        ExpressionSymbol expr = (ExpressionSymbol) symbols.poll();
        Assert.assertTrue(expr.values().get(0).value().toString().contains(" "));
    }
}
Also used : PostfixNotationSymbol(com.cinchapi.ccl.grammar.PostfixNotationSymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Test(org.junit.Test)

Example 5 with ExpressionSymbol

use of com.cinchapi.ccl.grammar.ExpressionSymbol in project concourse by cinchapi.

the class ConcourseCompilerTest method testParseCclValueAndTimestampPhraseWithoutQuotesAnd.

@Test
public void testParseCclValueAndTimestampPhraseWithoutQuotesAnd() {
    String ccl = "name = jeff nelson on last christmas day and favorite_player != Lebron James during last week";
    Queue<PostfixNotationSymbol> symbols = ConcourseCompiler.get().arrange((ConditionTree) ConcourseCompiler.get().parse(ccl));
    Assert.assertEquals(3, symbols.size());
    for (int i = 0; i < 2; ++i) {
        ExpressionSymbol expr = (ExpressionSymbol) symbols.poll();
        Assert.assertTrue(expr.values().get(0).value().toString().contains(" "));
        // this means a
        Assert.assertNotEquals(0, expr.raw().timestamp());
    // timestamp was
    // parsed
    }
}
Also used : PostfixNotationSymbol(com.cinchapi.ccl.grammar.PostfixNotationSymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Test(org.junit.Test)

Aggregations

ExpressionSymbol (com.cinchapi.ccl.grammar.ExpressionSymbol)21 Test (org.junit.Test)19 PostfixNotationSymbol (com.cinchapi.ccl.grammar.PostfixNotationSymbol)17 KeySymbol (com.cinchapi.ccl.grammar.KeySymbol)9 Symbol (com.cinchapi.ccl.grammar.Symbol)8 OperatorSymbol (com.cinchapi.ccl.grammar.OperatorSymbol)7 ValueSymbol (com.cinchapi.ccl.grammar.ValueSymbol)7 ParenthesisSymbol (com.cinchapi.ccl.grammar.ParenthesisSymbol)6 Operator (com.cinchapi.concourse.thrift.Operator)6 ConjunctionSymbol (com.cinchapi.ccl.grammar.ConjunctionSymbol)5 NavigationKeySymbol (com.cinchapi.ccl.grammar.NavigationKeySymbol)2 Timestamp (com.cinchapi.concourse.Timestamp)2 TimestampSymbol (com.cinchapi.ccl.grammar.TimestampSymbol)1 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)1 Store (com.cinchapi.concourse.server.storage.Store)1 TObject (com.cinchapi.concourse.thrift.TObject)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1