use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class MysqlTable method queryCondition2Select.
protected List<StringBuilder> queryCondition2Select(Query query, StringBuilder select) {
// Query by conditions
Collection<Condition> conditions = query.conditions();
List<StringBuilder> clauses = new ArrayList<>(conditions.size());
for (Condition condition : conditions) {
clauses.add(this.condition2Sql(condition));
}
WhereBuilder where = this.newWhereBuilder();
where.and(clauses);
select.append(where.build());
return ImmutableList.of(select);
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionNotIn.
@Test
public void testConditionNotIn() {
Condition c1 = Condition.nin(HugeKeys.ID, ImmutableList.of(1, 2, "3"));
Assert.assertFalse(c1.test(1));
Assert.assertFalse(c1.test(2));
Assert.assertFalse(c1.test("3"));
Assert.assertTrue(c1.test(4));
Assert.assertTrue(c1.test(1.0));
Assert.assertTrue(c1.test(2.0));
Assert.assertTrue(c1.test(3));
Assert.assertTrue(c1.test(123));
Assert.assertTrue(c1.test(1.01));
Assert.assertTrue(c1.test("123"));
Assert.assertTrue(c1.test("123.0"));
Assert.assertTrue(c1.test("1"));
Assert.assertTrue(c1.test("2"));
Assert.assertTrue(c1.test("3.0"));
Assert.assertTrue(c1.test("1.0"));
Assert.assertTrue(c1.test((Object) null));
Assert.assertTrue(c1.test(ImmutableList.of(4)));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.nin(HugeKeys.ID, null).test("1");
}, e -> {
Assert.assertEquals("Can't test null value for `notin`", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition c2 = new SyspropRelation(HugeKeys.ID, RelationType.NOT_IN, "single-value");
c2.test("singlevalue");
}, e -> {
Assert.assertEquals("Can't test 'single-value'(String) " + "for `notin`, expect Collection", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionAnd.
@Test
public void testConditionAnd() {
Condition c1 = Condition.gt(HugeKeys.ID, 18);
Condition c2 = Condition.lt(HugeKeys.ID, 30);
Condition c3 = c1.and(c2);
Assert.assertEquals(Condition.and(c1, c2), c3);
Assert.assertTrue(c3.test(19));
Assert.assertTrue(c3.test(20));
Assert.assertTrue(c3.test(29));
Assert.assertFalse(c3.test(17));
Assert.assertFalse(c3.test(18));
Assert.assertFalse(c3.test(30));
Assert.assertFalse(c3.test(31));
// null means 0
Assert.assertFalse(c3.test((Object) null));
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionContainsKey.
@Test
public void testConditionContainsKey() {
Condition c1 = Condition.containsKey(HugeKeys.ID, "k1");
Assert.assertTrue(c1.test(ImmutableMap.of("k1", "abc")));
Assert.assertTrue(c1.test(ImmutableMap.of("k1", "abc", "k2", "123")));
Assert.assertFalse(c1.test(ImmutableMap.of("k3", "ab")));
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test((Object) null);
}, e -> {
Assert.assertEquals("Can't execute `containsk` on type null, " + "expect Map", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test("v1");
}, e -> {
Assert.assertEquals("Can't execute `containsk` on type String, " + "expect Map", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test(123f);
}, e -> {
Assert.assertEquals("Can't execute `containsk` on type Float, " + "expect Map", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionGte.
@Test
public void testConditionGte() {
Condition c1 = Condition.gte(HugeKeys.ID, 123);
Assert.assertTrue(c1.test(124));
Assert.assertTrue(c1.test(200));
Assert.assertTrue(c1.test(123));
Assert.assertTrue(c1.test(123.0));
Assert.assertFalse(c1.test(122));
Assert.assertFalse(c1.test(20));
Assert.assertTrue(c1.test("123"));
Assert.assertTrue(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.gte(HugeKeys.ID, 0);
Assert.assertTrue(c2.test((Object) null));
Condition c3 = Condition.gte(HugeKeys.ID, -1);
Assert.assertTrue(c3.test((Object) null));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.gte(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.gte(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());
});
}
Aggregations