protected static boolean isQueryByLabel(Query query) { Set<Condition> conditions = query.conditions(); if (query instanceof ConditionQuery && !conditions.isEmpty()) { ConditionQuery cq = (ConditionQuery) query; Id label = (Id) cq.condition(HugeKeys.LABEL); if (label != null && cq.allSysprop() && conditions.size() == 1 && cq.containsCondition(HugeKeys.LABEL, Condition.RelationType.EQ)) { return true; } } return false; }
@Watched(prefix = "index") @Override public Iterator<BackendEntry> query(Query query) { if (query instanceof ConditionQuery) { ConditionQuery q = (ConditionQuery) query; if (q.allSysprop() && q.conditions().size() == 1 && q.containsCondition(HugeKeys.NAME)) { return this.queryByName(q); } } return super.query(query); }
public Query query(CassandraSessionPool.Session session, Query query) { Set<Condition> conditions = query.conditions(); if (!(query instanceof ConditionQuery) || conditions.isEmpty()) { return query; } ConditionQuery q = ((ConditionQuery) query).copy(); String name = (String) q.condition(HugeKeys.NAME); if (name != null && q.allSysprop() && conditions.size() == 1 && q.containsCondition(HugeKeys.NAME, Condition.RelationType.EQ)) { Set<Integer> ids = queryByNameIndex(session, this.table, name); if (ids.isEmpty()) { // Not found data with the specified label return null; } q.resetConditions(); for (Integer id : ids) { q.query(IdGenerator.of(id)); } } return q; }
/** * Query data from label index table if just want to query by label */ private static Query queryByLabelIndex( CassandraSessionPool.Session session, String table, Query query) { Set<Condition> conditions = query.conditions(); if (!(query instanceof ConditionQuery) || conditions.isEmpty()) { return query; } ConditionQuery q = (ConditionQuery) query; Id label = (Id) q.condition(HugeKeys.LABEL); if (label != null && q.allSysprop() && conditions.size() == 1 && q.containsCondition(HugeKeys.LABEL, Condition.RelationType.EQ)) { Set<String> ids = queryByLabelIndex(session, table, label); if (ids.isEmpty()) { // Not found data with the specified label return null; } q.resetConditions(); for (String id : ids) { /* * NOTE: Do not need to deserialize, because can directly * use the element id to do query from the vertex/edge table */ q.query(IdGenerator.of(id)); } } return query; }
@Override protected Query writeQueryCondition(Query query) { if (query.resultType().isGraph()) { ConditionQuery result = (ConditionQuery) query; // No user-prop when serialize assert result.allSysprop(); for (Condition.Relation r : result.relations()) { if (r.relation() == Condition.RelationType.CONTAINS) { r.serialValue(JsonUtil.toJson(r.value())); } } } return query; }
if (query.allSysprop() && conds.size() == 1 && query.containsCondition(HugeKeys.LABEL)) {
private Query writeStringIndexQuery(ConditionQuery query) { E.checkArgument(query.allSysprop() && query.conditions().size() == 2, "There should be two conditions: " + "INDEX_LABEL_ID and FIELD_VALUES" + "in secondary index query"); Id index = (Id) query.condition(HugeKeys.INDEX_LABEL_ID); Object key = query.condition(HugeKeys.FIELD_VALUES); E.checkArgument(index != null, "Please specify the index label"); E.checkArgument(key != null, "Please specify the index key"); Id id = formatIndexId(query.resultType(), index, key); IdQuery idQuery = new IdQuery(query, id); idQuery.limit(query.limit()); idQuery.offset(query.offset()); return idQuery; }
@Override protected Query writeQueryCondition(Query query) { ConditionQuery result = (ConditionQuery) query; // No user-prop when serialize assert result.allSysprop(); for (Condition.Relation r : result.relations()) { // Serialize key if (query.resultType().isSchema()) { r.serialKey(((HugeKeys) r.key()).string()); } else { r.serialKey(formatSyspropName((HugeKeys) r.key())); } if (r.value() instanceof Id) { // Serialize id value r.serialValue(writeId((Id) r.value())); } else { // Serialize other type value r.serialValue(JsonUtil.toJson(r.value())); } if (r.relation() == Condition.RelationType.CONTAINS_KEY) { // Serialize has-key String key = (String) r.serialValue(); r.serialValue(formatPropertyName(key)); } } return result; }
if (query.allSysprop()) { if (query.resultType().isEdge()) { verifyEdgesConditionQuery(query);
protected static boolean isQueryByLabel(Query query) { Set<Condition> conditions = query.conditions(); if (query instanceof ConditionQuery && !conditions.isEmpty()) { ConditionQuery cq = (ConditionQuery) query; Id label = (Id) cq.condition(HugeKeys.LABEL); if (label != null && cq.allSysprop() && conditions.size() == 1 && cq.containsCondition(HugeKeys.LABEL, Condition.RelationType.EQ)) { return true; } } return false; }
@Watched(prefix = "index") @Override public Iterator<BackendEntry> query(Query query) { if (query instanceof ConditionQuery) { ConditionQuery q = (ConditionQuery) query; if (q.allSysprop() && q.conditions().size() == 1 && q.containsCondition(HugeKeys.NAME)) { return this.queryByName(q); } } return super.query(query); }
public Query query(CassandraSessionPool.Session session, Query query) { Set<Condition> conditions = query.conditions(); if (!(query instanceof ConditionQuery) || conditions.isEmpty()) { return query; } ConditionQuery q = ((ConditionQuery) query).copy(); String name = (String) q.condition(HugeKeys.NAME); if (name != null && q.allSysprop() && conditions.size() == 1 && q.containsCondition(HugeKeys.NAME, Condition.RelationType.EQ)) { Set<Integer> ids = queryByNameIndex(session, this.table, name); if (ids.isEmpty()) { // Not found data with the specified label return null; } q.resetConditions(); for (Integer id : ids) { q.query(IdGenerator.of(id)); } } return q; }
/** * Query data from label index table if just want to query by label */ private static Query queryByLabelIndex( CassandraSessionPool.Session session, String table, Query query) { Set<Condition> conditions = query.conditions(); if (!(query instanceof ConditionQuery) || conditions.isEmpty()) { return query; } ConditionQuery q = (ConditionQuery) query; Id label = (Id) q.condition(HugeKeys.LABEL); if (label != null && q.allSysprop() && conditions.size() == 1 && q.containsCondition(HugeKeys.LABEL, Condition.RelationType.EQ)) { Set<String> ids = queryByLabelIndex(session, table, label); if (ids.isEmpty()) { // Not found data with the specified label return null; } q.resetConditions(); for (String id : ids) { /* * NOTE: Do not need to deserialize, because can directly * use the element id to do query from the vertex/edge table */ q.query(IdGenerator.of(id)); } } return query; }
@Override protected Query writeQueryCondition(Query query) { if (query.resultType().isGraph()) { ConditionQuery result = (ConditionQuery) query; // No user-prop when serialize assert result.allSysprop(); for (Condition.Relation r : result.relations()) { if (r.relation() == Condition.RelationType.CONTAINS) { r.serialValue(JsonUtil.toJson(r.value())); } } } return query; }
if (query.allSysprop() && conds.size() == 1 && query.containsCondition(HugeKeys.LABEL)) {
private Query writeStringIndexQuery(ConditionQuery query) { E.checkArgument(query.allSysprop() && query.conditions().size() == 2, "There should be two conditions: " + "INDEX_LABEL_ID and FIELD_VALUES" + "in secondary index query"); Id index = (Id) query.condition(HugeKeys.INDEX_LABEL_ID); Object key = query.condition(HugeKeys.FIELD_VALUES); E.checkArgument(index != null, "Please specify the index label"); E.checkArgument(key != null, "Please specify the index key"); Id id = formatIndexId(query.resultType(), index, key); IdQuery idQuery = new IdQuery(query, id); idQuery.limit(query.limit()); idQuery.offset(query.offset()); return idQuery; }
if (query.allSysprop()) { if (query.resultType().isEdge()) { verifyEdgesConditionQuery(query);
@Override protected Query writeQueryCondition(Query query) { ConditionQuery result = (ConditionQuery) query; // No user-prop when serialize assert result.allSysprop(); for (Condition.Relation r : result.relations()) { // Serialize key if (query.resultType().isSchema()) { r.serialKey(((HugeKeys) r.key()).string()); } else { r.serialKey(formatSyspropName((HugeKeys) r.key())); } if (r.value() instanceof Id) { // Serialize id value r.serialValue(writeId((Id) r.value())); } else { // Serialize other type value r.serialValue(JsonUtil.toJson(r.value())); } if (r.relation() == Condition.RelationType.CONTAINS_KEY) { // Serialize has-key String key = (String) r.serialValue(); r.serialValue(formatPropertyName(key)); } } return result; }