Search in sources :

Example 6 with PredicateCondition

use of org.janusgraph.graphdb.query.condition.PredicateCondition in project janusgraph by JanusGraph.

the class IndexSelectionUtil method getKeyIndexesForCondition.

private static Iterable<IndexType> getKeyIndexesForCondition(Condition<JanusGraphElement> condition) {
    if (condition instanceof PredicateCondition) {
        final RelationType type = ((PredicateCondition<RelationType, JanusGraphElement>) condition).getKey();
        Preconditions.checkArgument(type != null && type.isPropertyKey());
        return ((InternalRelationType) type).getKeyIndexes();
    }
    return Collections.emptySet();
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType)

Example 7 with PredicateCondition

use of org.janusgraph.graphdb.query.condition.PredicateCondition in project janusgraph by JanusGraph.

the class IndexSerializer method getQuery.

public IndexQuery getQuery(final MixedIndexType index, final Condition condition, final OrderList orders) {
    final Condition newCondition = ConditionUtil.literalTransformation(condition, new Function<Condition<JanusGraphElement>, Condition<JanusGraphElement>>() {

        @Nullable
        @Override
        public Condition<JanusGraphElement> apply(final Condition<JanusGraphElement> condition) {
            Preconditions.checkArgument(condition instanceof PredicateCondition);
            final PredicateCondition pc = (PredicateCondition) condition;
            final PropertyKey key = (PropertyKey) pc.getKey();
            return new PredicateCondition<>(key2Field(index, key), pc.getPredicate(), pc.getValue());
        }
    });
    ImmutableList<IndexQuery.OrderEntry> newOrders = IndexQuery.NO_ORDER;
    if (!orders.isEmpty() && IndexSelectionUtil.indexCoversOrder(index, orders)) {
        final ImmutableList.Builder<IndexQuery.OrderEntry> lb = ImmutableList.builder();
        for (int i = 0; i < orders.size(); i++) {
            lb.add(new IndexQuery.OrderEntry(key2Field(index, orders.getKey(i)), orders.getOrder(i), orders.getKey(i).dataType()));
        }
        newOrders = lb.build();
    }
    return new IndexQuery(index.getStoreName(), newCondition, newOrders);
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) Condition(org.janusgraph.graphdb.query.condition.Condition) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) JointIndexQuery(org.janusgraph.graphdb.query.graph.JointIndexQuery) ImmutableList(com.google.common.collect.ImmutableList) JanusGraphElement(org.janusgraph.core.JanusGraphElement) Nullable(javax.annotation.Nullable) PropertyKey(org.janusgraph.core.PropertyKey)

Example 8 with PredicateCondition

use of org.janusgraph.graphdb.query.condition.PredicateCondition in project janusgraph by JanusGraph.

the class AbstractIndexSelectionStrategy method coversAll.

private boolean coversAll(final MixedIndexType index, Condition<JanusGraphElement> condition, IndexSerializer indexInfo) {
    if (condition.getType() != Condition.Type.LITERAL) {
        return StreamSupport.stream(condition.getChildren().spliterator(), false).allMatch(child -> coversAll(index, child, indexInfo));
    }
    if (!(condition instanceof PredicateCondition)) {
        return false;
    }
    final PredicateCondition<RelationType, JanusGraphElement> atom = (PredicateCondition) condition;
    if (atom.getValue() == null && atom.getPredicate() != Cmp.NOT_EQUAL) {
        return false;
    }
    Preconditions.checkArgument(atom.getKey().isPropertyKey());
    final PropertyKey key = (PropertyKey) atom.getKey();
    final ParameterIndexField[] fields = index.getFieldKeys();
    final ParameterIndexField match = Arrays.stream(fields).filter(field -> field.getStatus() == SchemaStatus.ENABLED).filter(field -> field.getFieldKey().equals(key)).findAny().orElse(null);
    if (match == null) {
        return false;
    }
    boolean existsQuery = atom.getValue() == null && atom.getPredicate() == Cmp.NOT_EQUAL && indexInfo.supportsExistsQuery(index, match);
    return existsQuery || indexInfo.supports(index, match, atom.getPredicate());
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) MultiCondition(org.janusgraph.graphdb.query.condition.MultiCondition) Arrays(java.util.Arrays) JointIndexQuery(org.janusgraph.graphdb.query.graph.JointIndexQuery) Condition(org.janusgraph.graphdb.query.condition.Condition) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OrderList(org.janusgraph.graphdb.internal.OrderList) Cardinality(org.janusgraph.core.Cardinality) Cmp(org.janusgraph.core.attribute.Cmp) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) IndexField(org.janusgraph.graphdb.types.IndexField) Map(java.util.Map) Or(org.janusgraph.graphdb.query.condition.Or) ParameterIndexField(org.janusgraph.graphdb.types.ParameterIndexField) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) IndexType(org.janusgraph.graphdb.types.IndexType) StreamSupport(java.util.stream.StreamSupport) Nullable(javax.annotation.Nullable) JanusGraphElement(org.janusgraph.core.JanusGraphElement) JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) RelationType(org.janusgraph.core.RelationType) And(org.janusgraph.graphdb.query.condition.And) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) PropertyKey(org.janusgraph.core.PropertyKey) Configuration(org.janusgraph.diskstorage.configuration.Configuration) Collection(java.util.Collection) Set(java.util.Set) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) AbstractMap(java.util.AbstractMap) List(java.util.List) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) JanusGraphRelation(org.janusgraph.core.JanusGraphRelation) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) JanusGraphElement(org.janusgraph.core.JanusGraphElement) RelationType(org.janusgraph.core.RelationType) ParameterIndexField(org.janusgraph.graphdb.types.ParameterIndexField) PropertyKey(org.janusgraph.core.PropertyKey)

Example 9 with PredicateCondition

use of org.janusgraph.graphdb.query.condition.PredicateCondition in project janusgraph by JanusGraph.

the class JanusGraphTest method testGetMatchingIndexes.

@Test
public void testGetMatchingIndexes() {
    final PropertyKey name = makeKey("name", String.class);
    final PropertyKey age = makeKey("age", Integer.class);
    mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
    mgmt.buildIndex("byAge", Vertex.class).addKey(age).buildCompositeIndex();
    finishSchema();
    String searchName = "someName";
    Integer searchAge = 42;
    // test with no valid constraints
    assertEquals(Collections.emptySet(), IndexSelectionUtil.getMatchingIndexes(null));
    assertEquals(Collections.emptySet(), IndexSelectionUtil.getMatchingIndexes(null, null));
    assertEquals(Collections.emptySet(), IndexSelectionUtil.getMatchingIndexes(null, i -> true));
    // test with two valid constraints
    List<PredicateCondition<String, JanusGraphElement>> constraints = Arrays.asList(new PredicateCondition<>("name", JanusGraphPredicateUtils.convert(P.eq(searchName).getBiPredicate()), searchName), new PredicateCondition<>("age", JanusGraphPredicateUtils.convert(P.eq(searchAge).getBiPredicate()), searchAge));
    MultiCondition<JanusGraphElement> conditions = QueryUtil.constraints2QNF((StandardJanusGraphTx) tx, constraints);
    assertEquals(2, IndexSelectionUtil.getMatchingIndexes(conditions).size());
    assertEquals(1, IndexSelectionUtil.getMatchingIndexes(conditions, i -> i.getName().equals("byAge")).size());
    // test with invalid filter
    assertEquals(0, IndexSelectionUtil.getMatchingIndexes(conditions, null).size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagementUtil(org.janusgraph.core.util.ManagementUtil) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) DisableDefaultSchemaMaker(org.janusgraph.core.schema.DisableDefaultSchemaMaker) JanusGraphAssert.getStepMetrics(org.janusgraph.testutil.JanusGraphAssert.getStepMetrics) Cardinality(org.janusgraph.core.Cardinality) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) Duration(java.time.Duration) Map(java.util.Map) JanusGraphAssert.assertNotContains(org.janusgraph.testutil.JanusGraphAssert.assertNotContains) Path(java.nio.file.Path) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) EnumSet(java.util.EnumSet) IndexRepairJob(org.janusgraph.graphdb.olap.job.IndexRepairJob) PropertyKey(org.janusgraph.core.PropertyKey) OUT(org.apache.tinkerpop.gremlin.structure.Direction.OUT) JanusGraphPredicateUtils(org.janusgraph.graphdb.query.JanusGraphPredicateUtils) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) Arguments(org.junit.jupiter.params.provider.Arguments) VERBOSE_TX_RECOVERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.VERBOSE_TX_RECOVERY) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) ADJUST_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ADJUST_LIMIT) RELATION(org.janusgraph.graphdb.internal.RelationCategory.RELATION) SCHEMA_CONSTRAINTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SCHEMA_CONSTRAINTS) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MultiCondition(org.janusgraph.graphdb.query.condition.MultiCondition) FORCE_INDEX_USAGE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.FORCE_INDEX_USAGE) CUSTOM_ATTRIBUTE_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) TestGraphConfigs(org.janusgraph.testutil.TestGraphConfigs) Supplier(java.util.function.Supplier) Lists(com.google.common.collect.Lists) Change(org.janusgraph.core.log.Change) GhostVertexRemover(org.janusgraph.graphdb.olap.job.GhostVertexRemover) StreamSupport(java.util.stream.StreamSupport) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) LOG_SEND_DELAY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_SEND_DELAY) ALLOW_STALE_CONFIG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ALLOW_STALE_CONFIG) T(org.apache.tinkerpop.gremlin.structure.T) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IDS_STORE_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDS_STORE_NAME) JanusGraphVertexQuery(org.janusgraph.core.JanusGraphVertexQuery) Preconditions(com.google.common.base.Preconditions) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraphConfigurationException(org.janusgraph.core.JanusGraphConfigurationException) Log(org.janusgraph.diskstorage.log.Log) Date(java.util.Date) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) NotImplementedException(org.apache.commons.lang.NotImplementedException) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) TextP(org.apache.tinkerpop.gremlin.process.traversal.TextP) MethodSource(org.junit.jupiter.params.provider.MethodSource) Multiplicity(org.janusgraph.core.Multiplicity) RelationType(org.janusgraph.core.RelationType) ElementLifeCycle(org.janusgraph.graphdb.internal.ElementLifeCycle) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Collection(java.util.Collection) LogTxMeta(org.janusgraph.graphdb.database.log.LogTxMeta) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JanusGraphAssert.assertEmpty(org.janusgraph.testutil.JanusGraphAssert.assertEmpty) TestCategory(org.janusgraph.TestCategory) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) STORAGE_BATCH(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BATCH) Order.desc(org.apache.tinkerpop.gremlin.process.traversal.Order.desc) STORAGE_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND) JanusGraphFeature(org.janusgraph.testutil.JanusGraphFeature) JanusGraphQuery(org.janusgraph.core.JanusGraphQuery) HashSet(java.util.HashSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) ImmutableList(com.google.common.collect.ImmutableList) Message(org.janusgraph.diskstorage.log.Message) TRANSACTION_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TRANSACTION_LOG) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) GraphOfTheGodsFactory(org.janusgraph.example.GraphOfTheGodsFactory) Logger(org.slf4j.Logger) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) VertexList(org.janusgraph.core.VertexList) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Contain(org.janusgraph.core.attribute.Contain) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Arrays(java.util.Arrays) JanusGraphAssert.assertNotEmpty(org.janusgraph.testutil.JanusGraphAssert.assertNotEmpty) MessageReader(org.janusgraph.diskstorage.log.MessageReader) Geoshape(org.janusgraph.core.attribute.Geoshape) EDGE(org.janusgraph.graphdb.internal.RelationCategory.EDGE) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Tag(org.junit.jupiter.api.Tag) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) USE_MULTIQUERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY) JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) EnumMap(java.util.EnumMap) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) INITIAL_JANUSGRAPH_VERSION(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INITIAL_JANUSGRAPH_VERSION) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SimpleQueryProfiler(org.janusgraph.graphdb.query.profile.SimpleQueryProfiler) PermanentLockingException(org.janusgraph.diskstorage.locking.PermanentLockingException) ArrayList(java.util.ArrayList) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) Cmp(org.janusgraph.core.attribute.Cmp) ConsistencyModifier(org.janusgraph.core.schema.ConsistencyModifier) JanusGraphException(org.janusgraph.core.JanusGraphException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) MAX_COMMIT_TIME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MAX_COMMIT_TIME) JanusGraphElement(org.janusgraph.core.JanusGraphElement) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) ValueSource(org.junit.jupiter.params.provider.ValueSource) TX_CACHE_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TX_CACHE_SIZE) File(java.io.File) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SYSTEM_LOG_TRANSACTIONS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SYSTEM_LOG_TRANSACTIONS) ChronoUnit(java.time.temporal.ChronoUnit) HARD_MAX_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.HARD_MAX_LIMIT) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) SchemaAction(org.janusgraph.core.schema.SchemaAction) Order.asc(org.apache.tinkerpop.gremlin.process.traversal.Order.asc) OrderList(org.janusgraph.graphdb.internal.OrderList) BATCH_PROPERTY_PREFETCHING(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.BATCH_PROPERTY_PREFETCHING) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) IndexSelectionUtil(org.janusgraph.graphdb.query.index.IndexSelectionUtil) P(org.apache.tinkerpop.gremlin.process.traversal.P) BOTH(org.apache.tinkerpop.gremlin.structure.Direction.BOTH) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) USER_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USER_LOG) Property(org.apache.tinkerpop.gremlin.structure.Property) SchemaViolationException(org.janusgraph.core.SchemaViolationException) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob) StandardPropertyKeyMaker(org.janusgraph.graphdb.types.StandardPropertyKeyMaker) Sets(com.google.common.collect.Sets) LOG_READ_INTERVAL(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_READ_INTERVAL) List(java.util.List) TempDir(org.junit.jupiter.api.io.TempDir) JanusGraphDefaultSchemaMaker(org.janusgraph.core.schema.JanusGraphDefaultSchemaMaker) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) CUSTOM_SERIALIZER_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS) AUTO_TYPE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.AUTO_TYPE) HashMap(java.util.HashMap) LIMIT_BATCH_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE) JanusGraphAssert.assertContains(org.janusgraph.testutil.JanusGraphAssert.assertContains) Backend(org.janusgraph.diskstorage.Backend) Iterators(com.google.common.collect.Iterators) SpecialInt(org.janusgraph.graphdb.serializer.SpecialInt) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) DB_CACHE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.DB_CACHE) LOG_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_BACKEND) IgnorePropertySchemaMaker(org.janusgraph.core.schema.IgnorePropertySchemaMaker) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BackendException(org.janusgraph.diskstorage.BackendException) MANAGEMENT_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MANAGEMENT_LOG) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Iterator(java.util.Iterator) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) STORAGE_READONLY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_READONLY) JanusGraph(org.janusgraph.core.JanusGraph) IN(org.apache.tinkerpop.gremlin.structure.Direction.IN) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Order(org.janusgraph.graphdb.internal.Order) PROPERTY(org.janusgraph.graphdb.internal.RelationCategory.PROPERTY) TimeUnit(java.util.concurrent.TimeUnit) JanusGraphAssert.queryProfilerAnnotationIsPresent(org.janusgraph.testutil.JanusGraphAssert.queryProfilerAnnotationIsPresent) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) Collections(java.util.Collections) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) JanusGraphElement(org.janusgraph.core.JanusGraphElement) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 10 with PredicateCondition

use of org.janusgraph.graphdb.query.condition.PredicateCondition in project janusgraph by JanusGraph.

the class JanusGraphTest method testExistsMatchingIndex.

@Test
public void testExistsMatchingIndex() {
    final PropertyKey name = makeKey("name", String.class);
    final PropertyKey age = makeKey("age", Integer.class);
    mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
    mgmt.buildIndex("byAge", Vertex.class).addKey(age).buildCompositeIndex();
    finishSchema();
    String searchName = "someName";
    Integer searchAge = 42;
    // test with no valid constraints
    assertEquals(false, IndexSelectionUtil.existsMatchingIndex(null));
    assertEquals(false, IndexSelectionUtil.existsMatchingIndex(null, null));
    assertEquals(false, IndexSelectionUtil.existsMatchingIndex(null, i -> true));
    // test with two valid constraints
    List<PredicateCondition<String, JanusGraphElement>> constraints = Arrays.asList(new PredicateCondition<>("name", JanusGraphPredicateUtils.convert(P.eq(searchName).getBiPredicate()), searchName), new PredicateCondition<>("age", JanusGraphPredicateUtils.convert(P.eq(searchAge).getBiPredicate()), searchAge));
    MultiCondition<JanusGraphElement> conditions = QueryUtil.constraints2QNF((StandardJanusGraphTx) tx, constraints);
    assertEquals(true, IndexSelectionUtil.existsMatchingIndex(conditions));
    assertEquals(true, IndexSelectionUtil.existsMatchingIndex(conditions, i -> i.getName().equals("byAge")));
    assertEquals(false, IndexSelectionUtil.existsMatchingIndex(conditions, i -> i.getName().equals("byNonExistentKey")));
    // test with invalid filter
    assertEquals(false, IndexSelectionUtil.existsMatchingIndex(conditions, null));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagementUtil(org.janusgraph.core.util.ManagementUtil) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) DisableDefaultSchemaMaker(org.janusgraph.core.schema.DisableDefaultSchemaMaker) JanusGraphAssert.getStepMetrics(org.janusgraph.testutil.JanusGraphAssert.getStepMetrics) Cardinality(org.janusgraph.core.Cardinality) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) Duration(java.time.Duration) Map(java.util.Map) JanusGraphAssert.assertNotContains(org.janusgraph.testutil.JanusGraphAssert.assertNotContains) Path(java.nio.file.Path) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) EnumSet(java.util.EnumSet) IndexRepairJob(org.janusgraph.graphdb.olap.job.IndexRepairJob) PropertyKey(org.janusgraph.core.PropertyKey) OUT(org.apache.tinkerpop.gremlin.structure.Direction.OUT) JanusGraphPredicateUtils(org.janusgraph.graphdb.query.JanusGraphPredicateUtils) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) Arguments(org.junit.jupiter.params.provider.Arguments) VERBOSE_TX_RECOVERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.VERBOSE_TX_RECOVERY) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) ADJUST_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ADJUST_LIMIT) RELATION(org.janusgraph.graphdb.internal.RelationCategory.RELATION) SCHEMA_CONSTRAINTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SCHEMA_CONSTRAINTS) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MultiCondition(org.janusgraph.graphdb.query.condition.MultiCondition) FORCE_INDEX_USAGE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.FORCE_INDEX_USAGE) CUSTOM_ATTRIBUTE_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) TestGraphConfigs(org.janusgraph.testutil.TestGraphConfigs) Supplier(java.util.function.Supplier) Lists(com.google.common.collect.Lists) Change(org.janusgraph.core.log.Change) GhostVertexRemover(org.janusgraph.graphdb.olap.job.GhostVertexRemover) StreamSupport(java.util.stream.StreamSupport) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) LOG_SEND_DELAY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_SEND_DELAY) ALLOW_STALE_CONFIG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ALLOW_STALE_CONFIG) T(org.apache.tinkerpop.gremlin.structure.T) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IDS_STORE_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDS_STORE_NAME) JanusGraphVertexQuery(org.janusgraph.core.JanusGraphVertexQuery) Preconditions(com.google.common.base.Preconditions) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraphConfigurationException(org.janusgraph.core.JanusGraphConfigurationException) Log(org.janusgraph.diskstorage.log.Log) Date(java.util.Date) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) NotImplementedException(org.apache.commons.lang.NotImplementedException) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) TextP(org.apache.tinkerpop.gremlin.process.traversal.TextP) MethodSource(org.junit.jupiter.params.provider.MethodSource) Multiplicity(org.janusgraph.core.Multiplicity) RelationType(org.janusgraph.core.RelationType) ElementLifeCycle(org.janusgraph.graphdb.internal.ElementLifeCycle) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Collection(java.util.Collection) LogTxMeta(org.janusgraph.graphdb.database.log.LogTxMeta) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JanusGraphAssert.assertEmpty(org.janusgraph.testutil.JanusGraphAssert.assertEmpty) TestCategory(org.janusgraph.TestCategory) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) STORAGE_BATCH(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BATCH) Order.desc(org.apache.tinkerpop.gremlin.process.traversal.Order.desc) STORAGE_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND) JanusGraphFeature(org.janusgraph.testutil.JanusGraphFeature) JanusGraphQuery(org.janusgraph.core.JanusGraphQuery) HashSet(java.util.HashSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) ImmutableList(com.google.common.collect.ImmutableList) Message(org.janusgraph.diskstorage.log.Message) TRANSACTION_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TRANSACTION_LOG) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) GraphOfTheGodsFactory(org.janusgraph.example.GraphOfTheGodsFactory) Logger(org.slf4j.Logger) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) VertexList(org.janusgraph.core.VertexList) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Contain(org.janusgraph.core.attribute.Contain) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Arrays(java.util.Arrays) JanusGraphAssert.assertNotEmpty(org.janusgraph.testutil.JanusGraphAssert.assertNotEmpty) MessageReader(org.janusgraph.diskstorage.log.MessageReader) Geoshape(org.janusgraph.core.attribute.Geoshape) EDGE(org.janusgraph.graphdb.internal.RelationCategory.EDGE) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Tag(org.junit.jupiter.api.Tag) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) USE_MULTIQUERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY) JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) EnumMap(java.util.EnumMap) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) INITIAL_JANUSGRAPH_VERSION(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INITIAL_JANUSGRAPH_VERSION) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SimpleQueryProfiler(org.janusgraph.graphdb.query.profile.SimpleQueryProfiler) PermanentLockingException(org.janusgraph.diskstorage.locking.PermanentLockingException) ArrayList(java.util.ArrayList) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) Cmp(org.janusgraph.core.attribute.Cmp) ConsistencyModifier(org.janusgraph.core.schema.ConsistencyModifier) JanusGraphException(org.janusgraph.core.JanusGraphException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) MAX_COMMIT_TIME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MAX_COMMIT_TIME) JanusGraphElement(org.janusgraph.core.JanusGraphElement) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) ValueSource(org.junit.jupiter.params.provider.ValueSource) TX_CACHE_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TX_CACHE_SIZE) File(java.io.File) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SYSTEM_LOG_TRANSACTIONS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SYSTEM_LOG_TRANSACTIONS) ChronoUnit(java.time.temporal.ChronoUnit) HARD_MAX_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.HARD_MAX_LIMIT) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) SchemaAction(org.janusgraph.core.schema.SchemaAction) Order.asc(org.apache.tinkerpop.gremlin.process.traversal.Order.asc) OrderList(org.janusgraph.graphdb.internal.OrderList) BATCH_PROPERTY_PREFETCHING(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.BATCH_PROPERTY_PREFETCHING) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) IndexSelectionUtil(org.janusgraph.graphdb.query.index.IndexSelectionUtil) P(org.apache.tinkerpop.gremlin.process.traversal.P) BOTH(org.apache.tinkerpop.gremlin.structure.Direction.BOTH) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) USER_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USER_LOG) Property(org.apache.tinkerpop.gremlin.structure.Property) SchemaViolationException(org.janusgraph.core.SchemaViolationException) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob) StandardPropertyKeyMaker(org.janusgraph.graphdb.types.StandardPropertyKeyMaker) Sets(com.google.common.collect.Sets) LOG_READ_INTERVAL(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_READ_INTERVAL) List(java.util.List) TempDir(org.junit.jupiter.api.io.TempDir) JanusGraphDefaultSchemaMaker(org.janusgraph.core.schema.JanusGraphDefaultSchemaMaker) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) CUSTOM_SERIALIZER_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS) AUTO_TYPE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.AUTO_TYPE) HashMap(java.util.HashMap) LIMIT_BATCH_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE) JanusGraphAssert.assertContains(org.janusgraph.testutil.JanusGraphAssert.assertContains) Backend(org.janusgraph.diskstorage.Backend) Iterators(com.google.common.collect.Iterators) SpecialInt(org.janusgraph.graphdb.serializer.SpecialInt) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) DB_CACHE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.DB_CACHE) LOG_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_BACKEND) IgnorePropertySchemaMaker(org.janusgraph.core.schema.IgnorePropertySchemaMaker) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BackendException(org.janusgraph.diskstorage.BackendException) MANAGEMENT_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MANAGEMENT_LOG) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Iterator(java.util.Iterator) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) STORAGE_READONLY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_READONLY) JanusGraph(org.janusgraph.core.JanusGraph) IN(org.apache.tinkerpop.gremlin.structure.Direction.IN) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Order(org.janusgraph.graphdb.internal.Order) PROPERTY(org.janusgraph.graphdb.internal.RelationCategory.PROPERTY) TimeUnit(java.util.concurrent.TimeUnit) JanusGraphAssert.queryProfilerAnnotationIsPresent(org.janusgraph.testutil.JanusGraphAssert.queryProfilerAnnotationIsPresent) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) Collections(java.util.Collections) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) JanusGraphElement(org.janusgraph.core.JanusGraphElement) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)11 RelationType (org.janusgraph.core.RelationType)6 Cmp (org.janusgraph.core.attribute.Cmp)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 JanusGraphElement (org.janusgraph.core.JanusGraphElement)5 Preconditions (com.google.common.base.Preconditions)4 ImmutableList (com.google.common.collect.ImmutableList)4 Arrays (java.util.Arrays)4 HashSet (java.util.HashSet)4 Collectors (java.util.stream.Collectors)4 Cardinality (org.janusgraph.core.Cardinality)4 PropertyKey (org.janusgraph.core.PropertyKey)4 QueryUtil (org.janusgraph.graphdb.query.QueryUtil)4 Condition (org.janusgraph.graphdb.query.condition.Condition)4 MultiCondition (org.janusgraph.graphdb.query.condition.MultiCondition)4 Or (org.janusgraph.graphdb.query.condition.Or)4