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());
}
}
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
}
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;
}
}
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));
}
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
}
Aggregations