Search in sources :

Example 6 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithOneGapBetween.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithOneGapBetween(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value[]>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithTwoProps(tx, new String[] { "a" }, new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, "b", new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, 500000)));
        expected.add(entityWithTwoProps(tx, "c", new String[] { "b" }));
        tx.commit();
    }
    createCompositeIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertCompositeResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexTransactionStateTestBase method shouldPerformStringRangeSearchWithRemovedRemovedPropertyInTxState.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringRangeSearchWithRemovedRemovedPropertyInTxState(boolean needsValues) throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    long entityToChange;
    try (KernelTransaction tx = beginTransaction()) {
        entityToChange = entityWithPropId(tx, "banana");
        entityWithPropId(tx, "apple");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "cherry"));
        entityWithProp(tx, "dragonfruit");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        removeProperty(tx, entityToChange);
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        assertEntityAndValueForSeek(expected, tx, index, needsValues, "berry", PropertyIndexQuery.range(prop, "b", true, "d", false));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexTransactionStateTestBase method shouldPerformStringRangeSearchWithAddedEntityInTxState.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringRangeSearchWithAddedEntityInTxState(boolean needsValues) throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    long entityToChange;
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "banana"));
        entityToChange = entityWithPropId(tx, "apple");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "cherry"));
        entityWithProp(tx, "dragonfruit");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        TextValue newProperty = stringValue("blueberry");
        setProperty(tx, entityToChange, newProperty);
        expected.add(Pair.of(entityToChange, newProperty));
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        assertEntityAndValueForSeek(expected, tx, index, needsValues, "berry", PropertyIndexQuery.range(prop, "b", true, "d", false));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TextValue(org.neo4j.values.storable.TextValue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexTransactionStateTestBase method shouldPerformEqualitySeek.

@Test
void shouldPerformEqualitySeek() throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "banana"));
        entityWithProp(tx, "apple");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "banana"));
        entityWithProp(tx, "dragonfruit");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        // Equality seek does never provide values
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        assertEntityAndValueForSeek(expected, tx, index, false, "banana", PropertyIndexQuery.exact(prop, "banana"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexTransactionStateTestBase method shouldPerformStringSuffixSearch.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringSuffixSearch(boolean needsValues) throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "1suff"));
        entityWithProp(tx, "pluff");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        expected.add(entityWithProp(tx, "2suff"));
        entityWithPropId(tx, "skruff");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        assertEntityAndValueForSeek(expected, tx, index, needsValues, "pasuff", PropertyIndexQuery.stringSuffix(prop, stringValue("suff")));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Pair (org.neo4j.internal.helpers.collection.Pair)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)22 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)12 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)11 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 TextValue (org.neo4j.values.storable.TextValue)9 PointValue (org.neo4j.values.storable.PointValue)8 Value (org.neo4j.values.storable.Value)8 Values.stringValue (org.neo4j.values.storable.Values.stringValue)8 Values.pointValue (org.neo4j.values.storable.Values.pointValue)7 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 Label (org.neo4j.graphdb.Label)5 Path (java.nio.file.Path)4 Transaction (org.neo4j.graphdb.Transaction)4 Map (java.util.Map)3