public static ConditionQuery fillConditionQuery( List<HasContainer> hasContainers, ConditionQuery query, HugeGraph graph) { HugeType resultType = query.resultType(); for (HasContainer has : hasContainers) { Condition condition = convHas2Condition(has, resultType, graph); query.query(condition); } return query; }
if (query.resultType().isVertex()) { schemaLabel = schema.getVertexLabel(label); } else if (query.resultType().isEdge()) { schemaLabel = schema.getEdgeLabel(label); } else { throw new AssertionError(String.format( "Unsupported index query type: %s", query.resultType())); if (query.resultType().isVertex()) { schemaLabels = schema.getVertexLabels(); } else if (query.resultType().isEdge()) { schemaLabels = schema.getEdgeLabels(); } else { throw new AssertionError(String.format( "Unsupported index query type: %s", query.resultType()));
public static boolean matchEdgeSortKeys(ConditionQuery query, HugeGraph graph) { assert query.resultType().isEdge(); Id label = (Id) query.condition(HugeKeys.LABEL); if (label == null) { return false; } List<Id> keys = graph.edgeLabel(label).sortKeys(); return !keys.isEmpty() && query.matchUserpropKeys(keys); }
private static NoIndexException noIndexException(HugeGraph graph, ConditionQuery query, Id label) { String name = label == null ? "any label" : String.format("label '%s'", query.resultType().isVertex() ? graph.vertexLabel(label).name() : graph.edgeLabel(label).name()); List<String> mismatched = new ArrayList<>(); if (query.hasSecondaryCondition()) { mismatched.add("secondary"); } if (query.hasRangeCondition()) { mismatched.add("range"); } if (query.hasSearchCondition()) { mismatched.add("search"); } return new NoIndexException("Don't accept query based on properties " + "%s that are not indexed in %s, " + "may not match %s condition", graph.mapPkId2Name(query.userpropKeys()), name, String.join("/", mismatched)); }
public static void verifyEdgesConditionQuery(ConditionQuery query) { assert query.resultType().isEdge(); int total = query.conditions().size(); if (total == 1) { // Supported: 1.query just by edge label, 2.query with scan if (query.containsCondition(HugeKeys.LABEL) || query.containsScanCondition()) { return; } } int matched = 0; for (HugeKeys key : EdgeId.KEYS) { Object value = query.condition(key); if (value == null) { break; } matched++; } if (matched != total) { throw new BackendException( "Not supported querying edges by %s, expect %s", query.conditions(), EdgeId.KEYS[matched]); } }
@Watched(prefix = "index") private Iterator<BackendEntry> queryByName(ConditionQuery query) { if (!this.needIndexForName()) { return super.query(query); } IndexLabel il = IndexLabel.label(query.resultType()); String name = (String) query.condition(HugeKeys.NAME); E.checkState(name != null, "The name in condition can't be null " + "when querying schema by name"); ConditionQuery indexQuery; indexQuery = new ConditionQuery(HugeType.SECONDARY_INDEX, query); indexQuery.eq(HugeKeys.FIELD_VALUES, name); indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id()); Iterator<BackendEntry> entries = super.query(indexQuery); IdQuery idQuery = new IdQuery(query.resultType(), query); while (entries.hasNext()) { HugeIndex index = this.serializer.readIndex(graph(), indexQuery, entries.next()); idQuery.query(index.elementIds()); } if (idQuery.ids().isEmpty()) { return Collections.emptyIterator(); } assert idQuery.ids().size() == 1 : idQuery.ids(); return super.query(idQuery); } }
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 (!q.resultType().isRangeIndex()) { continue;
if (label != null && query.resultType().isVertex()) { VertexLabel vertexLabel = this.graph().vertexLabel(label); if (vertexLabel.idStrategy() == IdStrategy.PRIMARY_KEY) { if (label != null && query.resultType().isEdge()) { List<Id> keys = this.graph().edgeLabel(label).sortKeys(); if (query.condition(HugeKeys.OWNER_VERTEX) != null && if (query.resultType().isEdge()) { verifyEdgesConditionQuery(query);
HugeType type = query.resultType(); if (keyEq != null) { Id id = formatIndexId(type, index, keyEq);
public static ConditionQuery fillConditionQuery( List<HasContainer> hasContainers, ConditionQuery query, HugeGraph graph) { HugeType resultType = query.resultType(); for (HasContainer has : hasContainers) { Condition condition = convHas2Condition(has, resultType, graph); query.query(condition); } return query; }
@Watched(prefix = "index") private Set<Id> queryByLabel(ConditionQuery query) { HugeType queryType = query.resultType(); IndexLabel il = IndexLabel.label(queryType); Id label = (Id) query.condition(HugeKeys.LABEL); assert label != null; SchemaLabel schemaLabel; if (queryType.isVertex()) { schemaLabel = this.graph().vertexLabel(label); } else if (queryType.isEdge()) { schemaLabel = this.graph().edgeLabel(label); } else { throw new BackendException("Can't query %s by label", queryType); } if (!this.store().features().supportsQueryByLabel() && !schemaLabel.enableLabelIndex()) { throw new NoIndexException("Don't accept query by label '%s', " + "it disables label index", schemaLabel); } ConditionQuery indexQuery; indexQuery = new ConditionQuery(HugeType.SECONDARY_INDEX, query); indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id()); indexQuery.eq(HugeKeys.FIELD_VALUES, label); // Set offset and limit to avoid redundant element ids indexQuery.limit(query.limit()); indexQuery.offset(query.offset()); indexQuery.capacity(query.capacity()); return this.doIndexQuery(il, indexQuery); }
if (query.resultType().isVertex()) { schemaLabel = schema.getVertexLabel(label); } else if (query.resultType().isEdge()) { schemaLabel = schema.getEdgeLabel(label); } else { throw new AssertionError(String.format( "Unsupported index query type: %s", query.resultType())); if (query.resultType().isVertex()) { schemaLabels = schema.getVertexLabels(); } else if (query.resultType().isEdge()) { schemaLabels = schema.getEdgeLabels(); } else { throw new AssertionError(String.format( "Unsupported index query type: %s", query.resultType()));
public static boolean matchEdgeSortKeys(ConditionQuery query, HugeGraph graph) { assert query.resultType().isEdge(); Id label = (Id) query.condition(HugeKeys.LABEL); if (label == null) { return false; } List<Id> keys = graph.edgeLabel(label).sortKeys(); return !keys.isEmpty() && query.matchUserpropKeys(keys); }
private static NoIndexException noIndexException(HugeGraph graph, ConditionQuery query, Id label) { String name = label == null ? "any label" : String.format("label '%s'", query.resultType().isVertex() ? graph.vertexLabel(label).name() : graph.edgeLabel(label).name()); List<String> mismatched = new ArrayList<>(); if (query.hasSecondaryCondition()) { mismatched.add("secondary"); } if (query.hasRangeCondition()) { mismatched.add("range"); } if (query.hasSearchCondition()) { mismatched.add("search"); } return new NoIndexException("Don't accept query based on properties " + "%s that are not indexed in %s, " + "may not match %s condition", graph.mapPkId2Name(query.userpropKeys()), name, String.join("/", mismatched)); }
@Watched(prefix = "index") private Iterator<BackendEntry> queryByName(ConditionQuery query) { if (!this.needIndexForName()) { return super.query(query); } IndexLabel il = IndexLabel.label(query.resultType()); String name = (String) query.condition(HugeKeys.NAME); E.checkState(name != null, "The name in condition can't be null " + "when querying schema by name"); ConditionQuery indexQuery; indexQuery = new ConditionQuery(HugeType.SECONDARY_INDEX, query); indexQuery.eq(HugeKeys.FIELD_VALUES, name); indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id()); Iterator<BackendEntry> entries = super.query(indexQuery); IdQuery idQuery = new IdQuery(query.resultType(), query); while (entries.hasNext()) { HugeIndex index = this.serializer.readIndex(graph(), indexQuery, entries.next()); idQuery.query(index.elementIds()); } if (idQuery.ids().isEmpty()) { return ImmutableList.<BackendEntry>of().iterator(); } assert idQuery.ids().size() == 1 : idQuery.ids(); return super.query(idQuery); } }
public static void verifyEdgesConditionQuery(ConditionQuery query) { assert query.resultType().isEdge(); int total = query.conditions().size(); if (total == 1) { // Supported: 1.query just by edge label, 2.query with scan if (query.containsCondition(HugeKeys.LABEL) || query.containsScanCondition()) { return; } } int matched = 0; for (HugeKeys key : EdgeId.KEYS) { Object value = query.condition(key); if (value == null) { break; } matched++; } if (matched != total) { throw new BackendException( "Not supported querying edges by %s, expect %s", query.conditions(), EdgeId.KEYS[matched]); } }
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; }
private void processRangeIndexLeft(ConditionQuery query, HugeElement element) { // Construct index ConditionQuery Set<MatchedIndex> matchedIndexes = collectMatchedIndexes(query); IndexQueries queries = null; for (MatchedIndex index : matchedIndexes) { if (index.schemaLabel().id().equals(element.schemaLabel().id())) { queries = index.constructIndexQueries(query); break; } } E.checkState(queries != null, "Can't construct left-index query for '%s'", query); for (ConditionQuery q : queries.values()) { if (!q.resultType().isRangeIndex()) { continue; } // Query and delete index equals element id for (Iterator<BackendEntry> it = super.query(q); it.hasNext();) { BackendEntry entry = it.next(); HugeIndex index = this.serializer.readIndex(graph(), q, entry); if (index.elementIds().contains(element.id())) { index.resetElementIds(); index.elementIds(element.id()); this.doEliminate(this.serializer.writeIndex(index)); } } } }
@Watched(prefix = "index") private Set<Id> queryByLabel(ConditionQuery query) { HugeType queryType = query.resultType(); IndexLabel il = IndexLabel.label(queryType); Id label = (Id) query.condition(HugeKeys.LABEL); assert label != null; SchemaLabel schemaLabel; if (queryType.isVertex()) { schemaLabel = this.graph().vertexLabel(label); } else if (queryType.isEdge()) { schemaLabel = this.graph().edgeLabel(label); } else { throw new BackendException("Can't query %s by label", queryType); } if (!this.store().features().supportsQueryByLabel() && !schemaLabel.enableLabelIndex()) { throw new NoIndexException("Don't accept query by label '%s', " + "it disables label index", schemaLabel); } ConditionQuery indexQuery; indexQuery = new ConditionQuery(HugeType.SECONDARY_INDEX, query); indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id()); indexQuery.eq(HugeKeys.FIELD_VALUES, label); // Set offset and limit to avoid redundant element ids indexQuery.limit(query.limit()); indexQuery.offset(query.offset()); indexQuery.capacity(query.capacity()); return this.doIndexQuery(il, indexQuery); }