Search in sources :

Example 6 with Criteria

use of com.cinchapi.concourse.lang.Criteria in project concourse by cinchapi.

the class CON662 method test.

@Test
public void test() {
    Criteria criteria = Criteria.parse("foo.bar eq 1");
    client.find(criteria);
    // lack of Exception means the test passes
    Assert.assertTrue(true);
}
Also used : Criteria(com.cinchapi.concourse.lang.Criteria) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 7 with Criteria

use of com.cinchapi.concourse.lang.Criteria in project concourse by cinchapi.

the class CON670 method repro.

@Test
public void repro() {
    client.add("name", "jeffrey o");
    client.add("name", "jeffrey a");
    client.add("name", "jeff n");
    client.add("name", "jeffe c");
    client.add("name", "jefferson nel");
    Criteria condition = Criteria.where().key("name").operator(Operator.LIKE).value("%jeff%");
    Set<Long> a = client.find(condition);
    Set<Long> b = client.select(condition).keySet();
    Iterator<Long> ait = a.iterator();
    Iterator<Long> bit = b.iterator();
    while (ait.hasNext()) {
        long anext = ait.next();
        long bnext = bit.next();
        Assert.assertEquals(anext, bnext);
    }
}
Also used : Criteria(com.cinchapi.concourse.lang.Criteria) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 8 with Criteria

use of com.cinchapi.concourse.lang.Criteria in project concourse by cinchapi.

the class Command method init.

/**
 * Inspect the operation and populate the operation variables if they
 * haven't already been {@link #initialized}.
 */
private void init() {
    if (!initialized) {
        String function = method.getName();
        String[] toks = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, function).split("-");
        Association args = Association.of();
        if (function.equals("getServerVersion")) {
            operation = function;
        } else if (function.equals("verifyOrSet")) {
            operation = function;
            args.put("key", params[0]);
            args.put("value", params[1]);
            args.put("record", params[2]);
        } else if (function.equals("verifyAndSwap")) {
            operation = function;
            args.put("key", params[0]);
            args.put("record", params[2]);
            args.put("values", ImmutableList.of(params[1], params[3]));
        } else if (function.equals("findOrInsertCclJson")) {
            operation = "findOrInsert";
            args.put("ccl", params[0]);
        } else if (function.equals("findOrInsertCriteriaJson")) {
            operation = "findOrInsert";
            args.put("criteria", params[0]);
        } else if (function.equals("findOrAddKeyValue")) {
            operation = "findOrAdd";
            args.put("key", params[0]);
            conditionKeys = ImmutableSet.of((String) params[0]);
        } else {
            operation = toks[0];
            for (int i = 1; i < toks.length; ++i) {
                args.put(toks[i].toLowerCase(), params[i - 1]);
            }
        }
        // Parser
        if (args.containsKey("ccl")) {
            String ccl = args.fetch("ccl");
            conditionTree = (ConditionTree) ConcourseCompiler.get().parse(ccl);
        } else if (args.containsKey("criteria")) {
            TCriteria tcriteria = args.fetch("criteria");
            Criteria criteria = Language.translateFromThriftCriteria(tcriteria);
            conditionTree = (ConditionTree) ConcourseCompiler.get().parse(criteria.ccl());
        } else {
            conditionTree = null;
        }
        // operationKeys
        if (args.containsKey("key")) {
            String key = args.fetch("key");
            operationKeys = Sets.newHashSet(key);
        } else if (args.containsKey("keys")) {
            Collection<String> keys = args.fetch("keys");
            operationKeys = Sets.newHashSet(keys);
        } else {
            operationKeys = ImmutableSet.of();
        }
        // operationRecords
        if (args.containsKey("record")) {
            long record = args.fetch("record");
            operationRecords = Sets.newHashSet(record);
        } else if (args.containsKey("records")) {
            Collection<Long> records = args.fetch("records");
            operationRecords = Sets.newHashSet(records);
        } else {
            operationRecords = ImmutableSet.of();
        }
        // order
        if (args.containsKey("order")) {
            TOrder torder = args.fetch("order");
            order = JavaThriftBridge.convert(torder);
        } else {
            order = null;
        }
        // methods above.
        if (conditionKeys == null && conditionTree != null) {
            conditionKeys = ConcourseCompiler.get().analyze(conditionTree).keys();
        } else if (function.startsWith("findKey")) {
            conditionKeys = ImmutableSet.of((String) params[0]);
        } else if (conditionKeys == null) {
            conditionKeys = ImmutableSet.of();
        }
        // operationTimestamp
        if (args.containsKey("time")) {
            operationTimestamp = args.fetch("time");
        }
        initialized = true;
    }
}
Also used : Association(com.cinchapi.common.collect.Association) ConditionTree(com.cinchapi.ccl.syntax.ConditionTree) Collection(java.util.Collection) TCriteria(com.cinchapi.concourse.thrift.TCriteria) TCriteria(com.cinchapi.concourse.thrift.TCriteria) Criteria(com.cinchapi.concourse.lang.Criteria) TOrder(com.cinchapi.concourse.thrift.TOrder)

Example 9 with Criteria

use of com.cinchapi.concourse.lang.Criteria in project concourse by cinchapi.

the class CON167 method testRoundTrip.

@Test
public void testRoundTrip() {
    String value = "`bar`";
    Criteria expected = Criteria.where().key("foo").operator(Operator.EQUALS).value(value).build();
    Criteria actual = Language.translateFromThriftCriteria(Language.translateToThriftCriteria(expected));
    Assert.assertEquals(expected, actual);
}
Also used : Criteria(com.cinchapi.concourse.lang.Criteria) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 10 with Criteria

use of com.cinchapi.concourse.lang.Criteria in project concourse by cinchapi.

the class CON672 method reproString.

@Test
public void reproString() {
    String value = "a=b";
    Criteria criteria = Criteria.where().key("foo").operator(Operator.EQUALS).value(value);
    System.out.println(criteria.ccl());
    client.find(criteria);
    // lack of Exception means the test passes
    Assert.assertTrue(true);
}
Also used : Criteria(com.cinchapi.concourse.lang.Criteria) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Aggregations

Criteria (com.cinchapi.concourse.lang.Criteria)11 Test (org.junit.Test)10 ConcourseIntegrationTest (com.cinchapi.concourse.test.ConcourseIntegrationTest)6 ConditionTree (com.cinchapi.ccl.syntax.ConditionTree)1 Association (com.cinchapi.common.collect.Association)1 Tag (com.cinchapi.concourse.Tag)1 TCriteria (com.cinchapi.concourse.thrift.TCriteria)1 TOrder (com.cinchapi.concourse.thrift.TOrder)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1