Search in sources :

Example 16 with Relation

use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.

the class ConditionQueryFlatten method calcValidRange.

private static Relations calcValidRange(Relation gte, Relation gt, Relation eq, Relation lte, Relation lt) {
    Relations result = new Relations();
    Relation lower = null;
    Relation upper = null;
    if (gte != null) {
        lower = gte;
    }
    if (gt != null) {
        // Select bigger one in (gt, gte) as lower limit
        lower = highRelation(gte, gt);
    }
    if (lt != null) {
        upper = lt;
    }
    if (lte != null) {
        // Select smaller one in (lt, lte) as upper limit
        upper = lowRelation(lte, lt);
    }
    // Ensure low < high
    if (!validRange(lower, upper)) {
        return Relations.of();
    }
    // Handle eq
    if (eq != null) {
        if (!validEq(eq, lower, upper)) {
            return Relations.of();
        }
        result.add(eq);
        return result;
    }
    // No eq if come here
    assert lower != null || upper != null;
    if (lower != null) {
        result.add(lower);
    }
    if (upper != null) {
        result.add(upper);
    }
    return result;
}
Also used : Relation(com.baidu.hugegraph.backend.query.Condition.Relation) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation)

Example 17 with Relation

use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.

the class ConditionTest method testConditionEqWithSysprop.

@Test
public void testConditionEqWithSysprop() {
    Condition c1 = Condition.eq(HugeKeys.ID, "123");
    Assert.assertEquals("ID == 123", c1.toString());
    Assert.assertTrue(c1.isRelation());
    Assert.assertTrue(c1.isSysprop());
    Assert.assertTrue(c1.isFlattened());
    Assert.assertFalse(c1.isLogic());
    Assert.assertTrue(c1.test("123"));
    Assert.assertFalse(c1.test("1234"));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(new Date(123)));
    Assert.assertFalse(c1.test((Object) null));
    Relation r1 = (Relation) c1;
    Assert.assertEquals(HugeKeys.ID, r1.key());
    Assert.assertEquals("123", r1.value());
    Assert.assertEquals("123", r1.serialValue());
    Assert.assertEquals(RelationType.EQ, r1.relation());
    Assert.assertTrue(r1.test("123"));
    Relation r2 = (Relation) c1.copy();
    Assert.assertEquals(r1, r2);
    Assert.assertEquals(HugeKeys.ID, r2.key());
    Assert.assertEquals("123", r2.value());
    Assert.assertEquals("123", r2.serialValue());
    Assert.assertEquals(RelationType.EQ, r2.relation());
    Assert.assertTrue(r2.test("123"));
    r2.serialValue("1234");
    Assert.assertEquals("1234", r2.serialValue());
    Assert.assertEquals("123", r1.serialValue());
    Assert.assertTrue(r2.test("123"));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.eq(HugeKeys.ID, null).test("any");
    }, e -> {
        Assert.assertEquals("Can't test null value for `==`", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 18 with Relation

use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.

the class ConditionTest method testConditionEqWithUserprop.

@Test
public void testConditionEqWithUserprop() {
    Condition c1 = Condition.eq(IdGenerator.of("1"), "123");
    Assert.assertEquals("1 == 123", c1.toString());
    Assert.assertTrue(c1.isRelation());
    Assert.assertFalse(c1.isSysprop());
    Assert.assertTrue(c1.isFlattened());
    Assert.assertFalse(c1.isLogic());
    Assert.assertTrue(c1.test("123"));
    Assert.assertFalse(c1.test("1234"));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(new Date(123)));
    Assert.assertFalse(c1.test((Object) null));
    Relation r1 = (Relation) c1;
    Assert.assertEquals(IdGenerator.of("1"), r1.key());
    Assert.assertEquals("123", r1.value());
    Assert.assertEquals("123", r1.serialValue());
    Assert.assertEquals(RelationType.EQ, r1.relation());
    Assert.assertTrue(r1.test("123"));
    Relation r2 = (Relation) c1.copy();
    Assert.assertEquals(r1, r2);
    Assert.assertEquals(IdGenerator.of("1"), r2.key());
    Assert.assertEquals("123", r2.value());
    Assert.assertEquals("123", r2.serialValue());
    Assert.assertEquals(RelationType.EQ, r2.relation());
    Assert.assertTrue(r2.test("123"));
    r2.serialValue("1234");
    Assert.assertEquals("1234", r2.serialValue());
    Assert.assertEquals("123", r1.serialValue());
    Assert.assertTrue(r2.test("123"));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.eq(IdGenerator.of("1"), null).test("any");
    }, e -> {
        Assert.assertEquals("Can't test null value for `==`", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

Relation (com.baidu.hugegraph.backend.query.Condition.Relation)18 SyspropRelation (com.baidu.hugegraph.backend.query.Condition.SyspropRelation)7 Id (com.baidu.hugegraph.backend.id.Id)5 Condition (com.baidu.hugegraph.backend.query.Condition)5 ArrayList (java.util.ArrayList)4 BackendException (com.baidu.hugegraph.backend.BackendException)3 Shard (com.baidu.hugegraph.backend.store.Shard)3 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)3 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)2 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)2 Clause (com.datastax.driver.core.querybuilder.Clause)2 Date (java.util.Date)2 Test (org.junit.Test)2 PageState (com.baidu.hugegraph.backend.page.PageState)1 Aggregate (com.baidu.hugegraph.backend.query.Aggregate)1 Query (com.baidu.hugegraph.backend.query.Query)1 Order (com.baidu.hugegraph.backend.query.Query.Order)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 BackendTable (com.baidu.hugegraph.backend.store.BackendTable)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1