public ConditionQuery eq(HugeKeys key, Object value) { // Filter value by key return this.query(Condition.eq(key, value)); }
private static Condition convIn2Or(Relation relation) { assert relation.relation() == Condition.RelationType.IN; Object key = relation.key(); @SuppressWarnings("unchecked") List<Object> values = (List<Object>) relation.value(); Condition cond, conds = null; for (Object value : values) { if (key instanceof HugeKeys) { cond = Condition.eq((HugeKeys) key, value); } else { cond = Condition.eq((Id) key, value); } conds = conds == null ? cond : Condition.or(conds, cond); } return conds; }
@Test public void testFlattenWithOr() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.or(c2)); Assert.assertEquals(1, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(2, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1), ImmutableSet.of(c2)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
@Test public void testFlattenWithOrTree() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); Condition c3 = Condition.eq(IdGenerator.of("c3"), "3"); Condition c4 = Condition.eq(IdGenerator.of("c4"), "4"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.or(c2).or(c3.or(c4))); Assert.assertEquals(1, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(4, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1), ImmutableSet.of(c2), ImmutableSet.of(c3), ImmutableSet.of(c4)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
@Test public void testFlattenWithAndTree() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); Condition c3 = Condition.eq(IdGenerator.of("c3"), "3"); Condition c4 = Condition.eq(IdGenerator.of("c4"), "4"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.and(c2).and(c3.and(c4))); Assert.assertEquals(1, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(1, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1, c2, c3, c4)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
@Test public void testFlattenWithOrAndTree() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); Condition c3 = Condition.eq(IdGenerator.of("c3"), "3"); Condition c4 = Condition.eq(IdGenerator.of("c4"), "4"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.and(c2).or(c3.and(c4))); Assert.assertEquals(1, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(2, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1, c2), ImmutableSet.of(c3, c4)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); } }
@Test public void testFlattenWithAndOrTree() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); Condition c3 = Condition.eq(IdGenerator.of("c3"), "3"); Condition c4 = Condition.eq(IdGenerator.of("c4"), "4"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.or(c2).and(c3.or(c4))); Assert.assertEquals(1, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(4, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1, c3), ImmutableSet.of(c1, c4), ImmutableSet.of(c2, c3), ImmutableSet.of(c2, c4)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
@Test public void testFlattenWithMultiOr() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); Condition c3 = Condition.eq(IdGenerator.of("c3"), "3"); Condition c4 = Condition.eq(IdGenerator.of("c4"), "4"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.or(c2)); query.query(c3.or(c4)); Assert.assertEquals(2, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(4, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1, c3), ImmutableSet.of(c1, c4), ImmutableSet.of(c2, c3), ImmutableSet.of(c2, c4)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
@Test public void testFlattenWithAnd() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1.and(c2)); Assert.assertEquals(1, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(1, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1, c2)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
@Test public void testFlattenWithMultiAnd() { Condition c1 = Condition.eq(IdGenerator.of("c1"), "1"); Condition c2 = Condition.eq(IdGenerator.of("c2"), "2"); Condition c3 = Condition.eq(IdGenerator.of("c3"), "3"); Condition c4 = Condition.eq(IdGenerator.of("c4"), "4"); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); query.query(c1); query.query(c2); query.query(c3); query.query(c4); Assert.assertEquals(4, query.conditions().size()); List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query); Assert.assertEquals(1, queries.size()); Set<Set<Condition>> expect; expect = ImmutableSet.of(ImmutableSet.of(c1, c2, c3, c4)); Set<Set<Condition>> actual = new HashSet<>(); for (ConditionQuery q : queries) { actual.add(q.conditions()); } Assert.assertEquals(expect, actual); }
private HugeVertex queryVariableVertex(String key) { ConditionQuery query = new ConditionQuery(HugeType.VERTEX); VertexLabel vl = this.graph.vertexLabel(Hidden.hide(VARIABLES)); query.eq(HugeKeys.LABEL, vl.id()); PropertyKey pkey = this.graph.propertyKey(Hidden.hide(VARIABLE_KEY)); query.query(Condition.eq(pkey.id(), key)); query.showHidden(true); Iterator<Vertex> vertices = this.graph.vertices(query); if (!vertices.hasNext()) { return null; } return (HugeVertex) vertices.next(); }
private <V> Iterator<HugeTask<V>> queryTask(Map<String, Object> conditions, long limit) { return this.call(() -> { ConditionQuery query = new ConditionQuery(HugeType.VERTEX); VertexLabel vl = this.graph.vertexLabel(TaskTransaction.TASK); query.eq(HugeKeys.LABEL, vl.id()); for (Map.Entry<String, Object> entry : conditions.entrySet()) { PropertyKey pk = this.graph.propertyKey(entry.getKey()); query.query(Condition.eq(pk.id(), entry.getValue())); } query.showHidden(true); if (limit != NO_LIMIT) { query.limit(limit); } Iterator<Vertex> vertices = this.tx().queryVertices(query); Iterator<HugeTask<V>> tasks = new MapperIterator<>(vertices, HugeTask::fromVertex); // Convert iterator to list to avoid across thread tx accessed return IteratorUtils.list(tasks); }).iterator(); }
private static Relation convCompare2SyspropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; HugeKeys key = string2HugeKey(has.getKey()); Object value = convSysValueIfNeeded(graph, type, key, has.getValue()); switch ((Compare) bp) { case eq: return Condition.eq(key, value); case gt: return Condition.gt(key, value); case gte: return Condition.gte(key, value); case lt: return Condition.lt(key, value); case lte: return Condition.lte(key, value); case neq: return Condition.neq(key, value); } throw newUnsupportedPredicate(has.getPredicate()); }
private static Relation convCompare2UserpropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); Id pkeyId = pkey.id(); Object value = validPredicateValue(has.getValue(), pkey); switch ((Compare) bp) { case eq: return Condition.eq(pkeyId, value); case gt: return Condition.gt(pkeyId, value); case gte: return Condition.gte(pkeyId, value); case lt: return Condition.lt(pkeyId, value); case lte: return Condition.lte(pkeyId, value); case neq: return Condition.neq(pkeyId, value); } throw newUnsupportedPredicate(has.getPredicate()); }
public ConditionQuery eq(HugeKeys key, Object value) { // Filter value by key return this.query(Condition.eq(key, value)); }
private static Condition convIn2Or(Relation relation) { assert relation.relation() == Condition.RelationType.IN; Object key = relation.key(); @SuppressWarnings("unchecked") List<Object> values = (List<Object>) relation.value(); Condition cond, conds = null; for (Object value : values) { if (key instanceof HugeKeys) { cond = Condition.eq((HugeKeys) key, value); } else { cond = Condition.eq((Id) key, value); } conds = conds == null ? cond : Condition.or(conds, cond); } return conds; }
private HugeVertex queryVariableVertex(String key) { ConditionQuery query = new ConditionQuery(HugeType.VERTEX); VertexLabel vl = this.graph.vertexLabel(Hidden.hide(VARIABLES)); query.eq(HugeKeys.LABEL, vl.id()); PropertyKey pkey = this.graph.propertyKey(Hidden.hide(VARIABLE_KEY)); query.query(Condition.eq(pkey.id(), key)); query.showHidden(true); Iterator<Vertex> vertices = this.graph.vertices(query); if (!vertices.hasNext()) { return null; } return (HugeVertex) vertices.next(); }
private <V> Iterator<HugeTask<V>> queryTask(Map<String, Object> conditions, long limit) { return this.call(() -> { ConditionQuery query = new ConditionQuery(HugeType.VERTEX); VertexLabel vl = this.graph.vertexLabel(TaskTransaction.TASK); query.eq(HugeKeys.LABEL, vl.id()); for (Map.Entry<String, Object> entry : conditions.entrySet()) { PropertyKey pk = this.graph.propertyKey(entry.getKey()); query.query(Condition.eq(pk.id(), entry.getValue())); } query.showHidden(true); if (limit != NO_LIMIT) { query.limit(limit); } Iterator<Vertex> vertices = this.tx().queryVertices(query); return new MapperIterator<>(vertices, HugeTask::fromVertex); }); }
private static Relation convCompare2UserpropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); Id pkeyId = pkey.id(); Object value = validPredicateValue(has.getValue(), pkey); switch ((Compare) bp) { case eq: return Condition.eq(pkeyId, value); case gt: return Condition.gt(pkeyId, value); case gte: return Condition.gte(pkeyId, value); case lt: return Condition.lt(pkeyId, value); case lte: return Condition.lte(pkeyId, value); case neq: return Condition.neq(pkeyId, value); } throw newUnsupportedPredicate(has.getPredicate()); }