-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Returning Composite index structure and field values for hex string
Signed-off-by: ntisseyre <[email protected]>
- Loading branch information
Showing
7 changed files
with
172 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
import org.janusgraph.core.attribute.Geoshape; | ||
import org.janusgraph.core.attribute.Text; | ||
import org.janusgraph.core.log.TransactionRecovery; | ||
import org.janusgraph.core.schema.CompositeIndexInfo; | ||
import org.janusgraph.core.schema.JanusGraphIndex; | ||
import org.janusgraph.core.schema.JanusGraphManagement; | ||
import org.janusgraph.core.schema.Mapping; | ||
|
@@ -97,7 +98,6 @@ | |
import org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy; | ||
import org.janusgraph.graphdb.transaction.StandardJanusGraphTx; | ||
import org.janusgraph.graphdb.types.CompositeIndexType; | ||
import org.janusgraph.graphdb.types.IndexField; | ||
import org.janusgraph.graphdb.types.MixedIndexType; | ||
import org.janusgraph.graphdb.types.ParameterType; | ||
|
@@ -162,7 +162,6 @@ | |
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
|
||
/** | ||
* @author Matthias Broecheler ([email protected]) | ||
*/ | ||
|
@@ -4357,29 +4356,82 @@ public void testGetIndexInfo() throws DecoderException { | |
|
||
mgmt.makeVertexLabel("cat").make(); | ||
|
||
makeKey("id", Integer.class); | ||
final PropertyKey idKey = makeKey("id", Integer.class); | ||
final PropertyKey nameKey = makeKey("name", String.class); | ||
final PropertyKey metaKey = makeKey("meta", Object.class); | ||
|
||
String searchByNameIndex = "searchByName"; | ||
mgmt.buildIndex(searchByNameIndex, Vertex.class) | ||
.addKey(nameKey) | ||
.buildCompositeIndex(); | ||
|
||
String indexName = "searchByName"; | ||
mgmt.buildIndex(indexName, Vertex.class) | ||
String searchByMetaIndex = "searchByMeta"; | ||
mgmt.buildIndex(searchByMetaIndex, Vertex.class) | ||
.addKey(nameKey) | ||
.addKey(metaKey) | ||
.buildCompositeIndex(); | ||
|
||
String inlinePropIndex = "inlineProp"; | ||
mgmt.buildIndex(inlinePropIndex, Vertex.class) | ||
.addKey(nameKey) | ||
.addKey(metaKey) | ||
.addInlinePropertyKey(idKey) | ||
.buildCompositeIndex(); | ||
|
||
mgmt.commit(); | ||
|
||
mgmt = graph.openManagement(); | ||
|
||
//Read index with single property | ||
Map<String, Object> fieldValues = new HashMap<>(); | ||
fieldValues.put("name", "someName"); | ||
|
||
String hexString = mgmt.getIndexKey(indexName, fieldValues); | ||
CompositeIndexType indexType = mgmt.getIndexInfo(hexString); | ||
String hexString = mgmt.getIndexKey(searchByNameIndex, fieldValues); | ||
CompositeIndexInfo indexInfo = mgmt.getIndexInfo(hexString); | ||
|
||
IndexField[] indexFields = new IndexField[1]; | ||
indexFields[0] = IndexField.of(nameKey); | ||
|
||
assertEquals(indexName, indexType.getName()); | ||
assertEquals(1, indexType.getFieldKeys().length); | ||
assertEquals(nameKey, indexType.getFieldKeys()[0].getFieldKey()); | ||
assertEquals(0, indexType.getInlineFieldKeys().length); | ||
assertEquals(searchByNameIndex, indexInfo.getIndexName()); | ||
assertEquals(1, indexInfo.getCompositeIndexType().getFieldKeys().length); | ||
assertEquals("someName", indexInfo.getValues().get(nameKey)); | ||
assertEquals(0, indexInfo.getCompositeIndexType().getInlineFieldKeys().length); | ||
|
||
//Read index with multi properties | ||
fieldValues = new HashMap<>(); | ||
fieldValues.put("name", "name1"); | ||
fieldValues.put("meta", "hello"); | ||
|
||
hexString = mgmt.getIndexKey(searchByMetaIndex, fieldValues); | ||
indexInfo = mgmt.getIndexInfo(hexString); | ||
|
||
indexFields = new IndexField[2]; | ||
indexFields[0] = IndexField.of(nameKey); | ||
indexFields[1] = IndexField.of(metaKey); | ||
|
||
assertEquals(searchByMetaIndex, indexInfo.getIndexName()); | ||
assertEquals(2, indexInfo.getCompositeIndexType().getFieldKeys().length); | ||
assertEquals("name1", indexInfo.getValues().get(nameKey)); | ||
assertEquals("hello", indexInfo.getValues().get(metaKey)); | ||
assertEquals(0, indexInfo.getCompositeIndexType().getInlineFieldKeys().length); | ||
|
||
//Read index with inline properties | ||
fieldValues = new HashMap<>(); | ||
fieldValues.put("name", "name2"); | ||
fieldValues.put("meta", "bye"); | ||
|
||
hexString = mgmt.getIndexKey(inlinePropIndex, fieldValues); | ||
indexInfo = mgmt.getIndexInfo(hexString); | ||
|
||
indexFields = new IndexField[2]; | ||
indexFields[0] = IndexField.of(nameKey); | ||
indexFields[1] = IndexField.of(metaKey); | ||
|
||
assertEquals(inlinePropIndex, indexInfo.getIndexName()); | ||
assertEquals(2, indexInfo.getCompositeIndexType().getFieldKeys().length); | ||
assertEquals("name2", indexInfo.getValues().get(nameKey)); | ||
assertEquals("bye", indexInfo.getValues().get(metaKey)); | ||
assertEquals(1, indexInfo.getCompositeIndexType().getInlineFieldKeys().length); | ||
assertEquals("id", indexInfo.getCompositeIndexType().getInlineFieldKeys()[0]); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
janusgraph-core/src/main/java/org/janusgraph/core/schema/CompositeIndexInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2025 JanusGraph Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.janusgraph.core.schema; | ||
|
||
import org.janusgraph.core.PropertyKey; | ||
import org.janusgraph.graphdb.types.CompositeIndexType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CompositeIndexInfo { | ||
final CompositeIndexType compositeIndexType; | ||
final Object[] indexFieldValues; | ||
|
||
final Map<PropertyKey, Object> indexValues; | ||
|
||
public CompositeIndexInfo(CompositeIndexType compositeIndexType, Object[] indexFieldValues) { | ||
this.compositeIndexType = compositeIndexType; | ||
this.indexFieldValues = indexFieldValues; | ||
|
||
this.indexValues = new HashMap<>(); | ||
for (int i = 0; i < compositeIndexType.getFieldKeys().length; i++) { | ||
PropertyKey p = compositeIndexType.getFieldKeys()[i].getFieldKey(); | ||
Object v = indexFieldValues[i]; | ||
this.indexValues.put(p, v); | ||
} | ||
} | ||
|
||
public CompositeIndexType getCompositeIndexType() { | ||
return compositeIndexType; | ||
} | ||
|
||
public String getIndexName() { | ||
return compositeIndexType.getName(); | ||
} | ||
|
||
public Map<PropertyKey, Object> getValues() { | ||
return indexValues; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters