Search in sources :

Example 41 with Condition

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

the class ConditionTest method testConditionLte.

@Test
public void testConditionLte() {
    Condition c1 = Condition.lte(HugeKeys.ID, 123);
    Assert.assertTrue(c1.test(123));
    Assert.assertTrue(c1.test(123.0));
    Assert.assertTrue(c1.test(120));
    Assert.assertTrue(c1.test(20));
    Assert.assertTrue(c1.test("123"));
    Assert.assertTrue(c1.test("123.0"));
    Assert.assertFalse(c1.test("123.01"));
    Assert.assertTrue(c1.test("20"));
    // null means 0
    Assert.assertTrue(c1.test((Object) null));
    Condition c2 = Condition.lte(HugeKeys.ID, 0);
    Assert.assertTrue(c2.test((Object) null));
    Condition c3 = Condition.lte(HugeKeys.ID, -1);
    Assert.assertFalse(c3.test((Object) null));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.lte(HugeKeys.ID, "123").test(123);
    }, e -> {
        String err = "Can't compare between 123(Integer) and 123(String)";
        Assert.assertEquals(err, e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.lte(HugeKeys.ID, "123").test(new Date(0L));
    }, e -> {
        String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
        Assert.assertEquals(err, e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 42 with Condition

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

the class ConditionTest method testConditionLt.

@Test
public void testConditionLt() {
    Condition c1 = Condition.lt(HugeKeys.ID, 123);
    Assert.assertTrue(c1.test(122));
    Assert.assertTrue(c1.test(120));
    Assert.assertTrue(c1.test(20));
    Assert.assertFalse(c1.test(124));
    Assert.assertFalse(c1.test(200));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(123.0));
    Assert.assertFalse(c1.test("123"));
    Assert.assertFalse(c1.test("123.0"));
    Assert.assertFalse(c1.test("123.01"));
    Assert.assertFalse(c1.test("200"));
    Assert.assertTrue(c1.test("122.99"));
    // null means 0
    Assert.assertTrue(c1.test((Object) null));
    Condition c2 = Condition.lt(HugeKeys.ID, 0.1);
    Assert.assertTrue(c2.test((Object) null));
    Condition c3 = Condition.lt(HugeKeys.ID, 0);
    Assert.assertFalse(c3.test((Object) null));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.lt(HugeKeys.ID, "123").test(123);
    }, e -> {
        String err = "Can't compare between 123(Integer) and 123(String)";
        Assert.assertEquals(err, e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.lt(HugeKeys.ID, "123").test(new Date(0L));
    }, e -> {
        String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
        Assert.assertEquals(err, e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 43 with Condition

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

the class ConditionTest method testConditionGt.

@Test
public void testConditionGt() {
    Condition c1 = Condition.gt(HugeKeys.ID, 123);
    Assert.assertTrue(c1.test(124));
    Assert.assertTrue(c1.test(200));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(123.0));
    Assert.assertFalse(c1.test(120));
    Assert.assertFalse(c1.test(20));
    Assert.assertFalse(c1.test("123"));
    Assert.assertFalse(c1.test("123.0"));
    Assert.assertTrue(c1.test("123.01"));
    Assert.assertTrue(c1.test("200"));
    // null means 0
    Assert.assertFalse(c1.test((Object) null));
    Condition c2 = Condition.gt(HugeKeys.ID, 0);
    Assert.assertFalse(c2.test((Object) null));
    Condition c3 = Condition.gt(HugeKeys.ID, -1);
    Assert.assertTrue(c3.test((Object) null));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.gt(HugeKeys.ID, "123").test(123);
    }, e -> {
        String err = "Can't compare between 123(Integer) and 123(String)";
        Assert.assertEquals(err, e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.gt(HugeKeys.ID, "123").test(new Date(0L));
    }, e -> {
        String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
        Assert.assertEquals(err, e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 44 with Condition

use of com.baidu.hugegraph.backend.query.Condition 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)

Example 45 with Condition

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

the class ConditionTest method testConditionTextContains.

@Test
public void testConditionTextContains() {
    Condition c1 = Condition.textContains(IdGenerator.of("1"), "tom");
    Assert.assertTrue(c1.test("tom"));
    Assert.assertTrue(c1.test("tomcat"));
    Assert.assertFalse(c1.test("cat"));
    Assert.assertFalse(c1.test("text"));
    Assert.assertFalse(c1.test("abc"));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        c1.test((Object) null);
    }, e -> {
        Assert.assertEquals("Can't execute `textcontains` on type null, " + "expect String", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        c1.test(123L);
    }, e -> {
        Assert.assertEquals("Can't execute `textcontains` on type Long, " + "expect String", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

Condition (com.baidu.hugegraph.backend.query.Condition)49 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)29 Test (org.junit.Test)29 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)16 ArrayList (java.util.ArrayList)13 Id (com.baidu.hugegraph.backend.id.Id)12 Collection (java.util.Collection)8 Date (java.util.Date)8 SyspropRelation (com.baidu.hugegraph.backend.query.Condition.SyspropRelation)6 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)4 RangeConditions (com.baidu.hugegraph.backend.query.Condition.RangeConditions)4 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)4 HugeException (com.baidu.hugegraph.HugeException)3 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)3 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)3 HugeType (com.baidu.hugegraph.type.HugeType)3 Directions (com.baidu.hugegraph.type.define.Directions)3 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)3 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)3 OrP (org.apache.tinkerpop.gremlin.process.traversal.util.OrP)3