use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class FinderTest method testAndConjunctionShortCircuit.
@Test
public void testAndConjunctionShortCircuit() {
Queue store = new Queue(16);
store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1));
store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1));
store.insert(Write.add("age", Convert.javaToThrift(100), 1));
store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2));
store.insert(Write.add("age", Convert.javaToThrift(100), 2));
store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3));
store.insert(Write.add("company", Convert.javaToThrift("ARMN Inc."), 3));
store.insert(Write.add("age", Convert.javaToThrift(50), 3));
String ccl = "(name = jeff or company = Cinchapi) and age = 70";
AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
Finder visitor = Finder.instance();
Set<Long> result = ast.accept(visitor, store);
Assert.assertEquals(Sets.newHashSet(), result);
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class FinderTest method testAndConjunction.
@Test
public void testAndConjunction() {
Queue store = new Queue(16);
store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1));
store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1));
store.insert(Write.add("age", Convert.javaToThrift(100), 1));
store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2));
store.insert(Write.add("age", Convert.javaToThrift(100), 2));
store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3));
store.insert(Write.add("company", Convert.javaToThrift("ARMN Inc."), 3));
store.insert(Write.add("age", Convert.javaToThrift(50), 3));
String ccl = "name = jeff and company = Cinchapi";
AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
Finder visitor = Finder.instance();
Set<Long> result = ast.accept(visitor, store);
Assert.assertEquals(Sets.newHashSet(1L), result);
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class Criteria method parse.
/**
* Return a {@link Criteria} object that expresses the same as the
* {@code ccl} statement.
*
* @param ccl the CCL statement to parse
* @return an equivalent {@link Criteria} object
*/
public static Criteria parse(String ccl) {
try {
AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
BuiltCriteria criteria = new BuiltCriteria();
criteria.symbols = Lists.newArrayList(ConcourseCompiler.get().tokenize(ast));
return criteria;
} catch (Exception e) {
if (e instanceof SyntaxException || e instanceof IllegalStateException || e.getCause() != null && e.getCause() instanceof com.cinchapi.ccl.generated.ParseException) {
throw new ParseException(new com.cinchapi.concourse.thrift.ParseException(e.getMessage()));
} else {
throw CheckedExceptions.throwAsRuntimeException(e);
}
}
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class ExportCli method init.
/**
* Initialize the CLI based on the arguments that are provided.
*/
private void init() {
ExportOptions opts = (ExportOptions) options;
// file
if (!Empty.ness().describes(opts.file)) {
file = Paths.get(opts.file);
File $file = file.toFile();
$file.getParentFile().mkdirs();
try {
$file.createNewFile();
} catch (IOException e) {
CheckedExceptions.wrapAsRuntimeException(e);
}
}
// records
if (!Empty.ness().describes(opts.records)) {
records = AnyObjects.split(opts.records, ',').stream().map(Long::parseLong).collect(Collectors.toCollection(LinkedHashSet::new));
}
// keys
if (!Empty.ness().describes(opts.keys)) {
keys = AnyObjects.split(opts.keys, ',').stream().collect(Collectors.toCollection(LinkedHashSet::new));
}
// order
if (!Empty.ness().describes(opts.order)) {
if (!opts.order.toLowerCase().startsWith("order by")) {
opts.order = "ORDER BY " + opts.order;
}
try {
AbstractSyntaxTree ast = ConcourseCompiler.get().parse(opts.order);
OrderTree tree = (OrderTree) ast;
order = Order.from(tree);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid order CCL statement");
}
}
// page
String $page = "";
if (!Empty.ness().describes(opts.page)) {
$page += "PAGE " + opts.page + " ";
}
if (!Empty.ness().describes(opts.size)) {
$page += "SIZE " + opts.size;
}
if (!Empty.ness().describes($page)) {
try {
AbstractSyntaxTree ast = ConcourseCompiler.get().parse($page);
PageTree tree = (PageTree) ast;
page = Page.from(tree);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid page or size argument");
}
}
excludeRecordId = opts.excludeRecordId;
condition = opts.condition;
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class ConcourseServer method selectKeysCriteriaTimeOrder.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, Set<TObject>>> selectKeysCriteriaTimeOrder(List<String> keys, TCriteria criteria, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
SortableTable<Set<TObject>> result = emptySortableResultDataset();
AtomicOperations.executeWithRetry(store, atomic -> Operations.selectKeysAstAtomic(keys, ast, timestamp, result, null, $result -> $result.sort(Sorting.byValues(Orders.from(order), atomic), timestamp), atomic));
return result;
}
Aggregations