Search in sources :

Example 16 with ExpressionSymbol

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

the class ConcourseCompilerTest method testParseCCLConjuctionsWithAnd.

@Test
public void testParseCCLConjuctionsWithAnd() {
    String ccl = "name = chandresh pancholi on last christmas day && favovite_player != C. Ronaldo during last year";
    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(" "));
        Assert.assertNotEquals(0, expr.raw().timestamp());
    }
}
Also used : PostfixNotationSymbol(com.cinchapi.ccl.grammar.PostfixNotationSymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) Test(org.junit.Test)

Example 17 with ExpressionSymbol

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

the class ConcourseCompilerTest method testParseCclTimestampPhraseWithoutQuotes.

@Test
public void testParseCclTimestampPhraseWithoutQuotes() {
    String ccl = "name = jeff at 3 seconds ago";
    Queue<PostfixNotationSymbol> symbols = ConcourseCompiler.get().arrange((ConditionTree) ConcourseCompiler.get().parse(ccl));
    ExpressionSymbol expr = (ExpressionSymbol) symbols.poll();
    // 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)

Example 18 with ExpressionSymbol

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

the class Finder method visit.

@Override
public Set<Long> visit(ExpressionTree tree, Object... data) {
    Verify.that(data.length >= 1);
    Verify.that(data[0] instanceof Store);
    Store store = (Store) data[0];
    ExpressionSymbol expression = ((ExpressionSymbol) tree.root());
    String key = expression.raw().key();
    Operator operator = (Operator) expression.raw().operator();
    if (key.equals(Constants.JSON_RESERVED_IDENTIFIER_NAME)) {
        Set<Long> ids;
        if (operator == Operator.EQUALS) {
            ids = Sets.newTreeSet();
            expression.raw().values().forEach(value -> ids.add(((Number) value).longValue()));
        } else if (operator == Operator.NOT_EQUALS) {
            Set<Long> exclude = expression.raw().values().stream().map(value -> ((Number) value).longValue()).collect(Collectors.toCollection(HashSet::new));
            ids = Sets.difference(store.getAllRecords(), exclude);
        } else {
            throw new IllegalArgumentException("Cannot query on record id using " + expression.raw().operator());
        }
        return ids;
    } else {
        ArrayBuilder<TObject> values = ArrayBuilder.builder();
        expression.values().forEach(value -> values.add(Convert.javaToThrift(value.value())));
        Set<Long> results = (expression.timestamp() == TimestampSymbol.PRESENT || expression.timestamp() == null) ? Stores.find(store, key, operator, values.build()) : Stores.find(store, expression.raw().timestamp(), key, operator, values.build());
        return results;
    }
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) HashSet(java.util.HashSet) Store(com.cinchapi.concourse.server.storage.Store) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) HashSet(java.util.HashSet)

Example 19 with ExpressionSymbol

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

the class ConcourseCompilerTest method testToPostfixNotationSimple.

@Test
public void testToPostfixNotationSimple() {
    Criteria criteria = Criteria.where().key("foo").operator(Operator.EQUALS).value("bar").build();
    Queue<PostfixNotationSymbol> pfn = Parsing.toPostfixNotation(criteria.symbols());
    Assert.assertEquals(pfn.size(), 1);
    Assert.assertEquals(((ExpressionSymbol) Iterables.getOnlyElement(pfn)).key(), new KeySymbol("foo"));
    Assert.assertEquals(((ExpressionSymbol) Iterables.getOnlyElement(pfn)).values().get(0), new ValueSymbol("bar"));
    Assert.assertEquals(((ExpressionSymbol) Iterables.getOnlyElement(pfn)).operator(), new OperatorSymbol(Operator.EQUALS));
}
Also used : OperatorSymbol(com.cinchapi.ccl.grammar.OperatorSymbol) KeySymbol(com.cinchapi.ccl.grammar.KeySymbol) PostfixNotationSymbol(com.cinchapi.ccl.grammar.PostfixNotationSymbol) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) ValueSymbol(com.cinchapi.ccl.grammar.ValueSymbol) Test(org.junit.Test)

Example 20 with ExpressionSymbol

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

the class ConcourseCompilerTest method testParseCclTimestampComplexPhrase.

@Test
public void testParseCclTimestampComplexPhrase() {
    String ccl = "name = jeff at \"last christmas\"";
    Queue<PostfixNotationSymbol> symbols = ConcourseCompiler.get().arrange((ConditionTree) ConcourseCompiler.get().parse(ccl));
    ExpressionSymbol expr = (ExpressionSymbol) symbols.poll();
    // 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