Search in sources :

Example 1 with ExactPredicate

use of org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate in project neo4j by neo4j.

the class IndexEntryResourceTypesTest method shouldDifferentiateBetweenIndexes.

@Test
void shouldDifferentiateBetweenIndexes() {
    ExactPredicate pred1 = exact(1, "value");
    ExactPredicate pred2 = exact(1, "value2");
    ExactPredicate pred3 = exact(2, "value");
    ExactPredicate pred4 = exact(2, "value2");
    List<Long> ids = Arrays.asList(ResourceIds.indexEntryResourceId(1, array(pred1)), ResourceIds.indexEntryResourceId(1, array(pred2)), ResourceIds.indexEntryResourceId(1, array(pred3)), ResourceIds.indexEntryResourceId(1, array(pred4)), ResourceIds.indexEntryResourceId(2, array(pred1)), ResourceIds.indexEntryResourceId(1, array(pred1, pred2)), ResourceIds.indexEntryResourceId(1, array(pred1, pred2, pred3)), ResourceIds.indexEntryResourceId(2, array(pred1, pred2, pred3, pred4)));
    Set<Long> uniqueIds = Iterables.asSet(ids);
    assertThat(ids.size()).isEqualTo(uniqueIds.size());
}
Also used : ExactPredicate(org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate) Test(org.junit.jupiter.api.Test)

Example 2 with ExactPredicate

use of org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate in project neo4j by neo4j.

the class GenericNativeIndexReader method initializeRangeForGeometrySubQuery.

/**
 * Initializes {@code treeKeyFrom} and {@code treeKeyTo} from the {@link PropertyIndexQuery query}.
 * Geometry range queries makes an otherwise straight-forward key construction complex in that a geometry range internally is performed
 * by executing multiple sub-range queries to the index. Each of those sub-range queries still needs to construct the full composite key -
 * in the case of a composite index. Therefore this method can be called either with null or non-null {@code crs} and {@code range} and
 * constructing a key when coming across a {@link PropertyIndexQuery.GeometryRangePredicate} will use the provided crs/range instead
 * of the predicate, where the specific range is one out of many sub-ranges calculated from the {@link PropertyIndexQuery.GeometryRangePredicate}
 * by the caller.
 *
 * @param treeKeyFrom the "from" key to construct from the query.
 * @param treeKeyTo the "to" key to construct from the query.
 * @param query the query to construct keys from to later send to {@link GBPTree} when reading.
 * @param crs {@link CoordinateReferenceSystem} for the specific {@code range}, if range is specified too.
 * @param range sub-range of a larger {@link PropertyIndexQuery.GeometryRangePredicate} to use instead of {@link PropertyIndexQuery.GeometryRangePredicate}
 * in the query.
 * @return {@code true} if filtering is needed for the results from the reader, otherwise {@code false}.
 */
private static boolean initializeRangeForGeometrySubQuery(GenericKey treeKeyFrom, GenericKey treeKeyTo, PropertyIndexQuery[] query, CoordinateReferenceSystem crs, SpaceFillingCurve.LongRange range) {
    boolean needsFiltering = false;
    for (int i = 0; i < query.length; i++) {
        PropertyIndexQuery predicate = query[i];
        switch(predicate.type()) {
            case exists:
                treeKeyFrom.initValueAsLowest(i, ValueGroup.UNKNOWN);
                treeKeyTo.initValueAsHighest(i, ValueGroup.UNKNOWN);
                break;
            case exact:
                ExactPredicate exactPredicate = (ExactPredicate) predicate;
                treeKeyFrom.initFromValue(i, exactPredicate.value(), NEUTRAL);
                treeKeyTo.initFromValue(i, exactPredicate.value(), NEUTRAL);
                break;
            case range:
                if (isGeometryRangeQuery(predicate)) {
                    // Use the supplied SpaceFillingCurve range instead of the GeometryRangePredicate because at the time of calling this method
                    // the original geometry range have been split up into multiple sub-ranges and this invocation is for one of those sub-ranges.
                    // We can not take query inclusion / exclusion into consideration here because then we risk missing border values. Always use
                    // Inclusion.LOW / HIGH respectively and filter out points later on.
                    treeKeyFrom.stateSlot(i).writePointDerived(crs, range.min, LOW);
                    treeKeyTo.stateSlot(i).writePointDerived(crs, range.max + 1, HIGH);
                    needsFiltering = true;
                } else {
                    RangePredicate<?> rangePredicate = (RangePredicate<?>) predicate;
                    initFromForRange(i, rangePredicate, treeKeyFrom);
                    initToForRange(i, rangePredicate, treeKeyTo);
                }
                break;
            case stringPrefix:
                StringPrefixPredicate prefixPredicate = (StringPrefixPredicate) predicate;
                treeKeyFrom.stateSlot(i).initAsPrefixLow(prefixPredicate.prefix());
                treeKeyTo.stateSlot(i).initAsPrefixHigh(prefixPredicate.prefix());
                break;
            case stringSuffix:
            case stringContains:
                treeKeyFrom.initValueAsLowest(i, ValueGroup.TEXT);
                treeKeyTo.initValueAsHighest(i, ValueGroup.TEXT);
                needsFiltering = true;
                break;
            default:
                throw new IllegalArgumentException("IndexQuery of type " + predicate.type() + " is not supported.");
        }
    }
    return needsFiltering;
}
Also used : RangePredicate(org.neo4j.internal.kernel.api.PropertyIndexQuery.RangePredicate) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) StringPrefixPredicate(org.neo4j.internal.kernel.api.PropertyIndexQuery.StringPrefixPredicate) ExactPredicate(org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate)

Example 3 with ExactPredicate

use of org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate in project neo4j by neo4j.

the class IndexQueryTest method testExact_ComparingBigDoublesAndLongs.

@Test
void testExact_ComparingBigDoublesAndLongs() {
    ExactPredicate p = PropertyIndexQuery.exact(propId, 9007199254740993L);
    assertFalse(test(p, 9007199254740992D));
}
Also used : ExactPredicate(org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate) Test(org.junit.jupiter.api.Test)

Example 4 with ExactPredicate

use of org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate in project neo4j by neo4j.

the class IndexQueryTest method assertExactPredicate.

private void assertExactPredicate(Object value) {
    ExactPredicate p = PropertyIndexQuery.exact(propId, value);
    assertTrue(test(p, value));
    assertFalseForOtherThings(p);
}
Also used : ExactPredicate(org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate)

Aggregations

ExactPredicate (org.neo4j.internal.kernel.api.PropertyIndexQuery.ExactPredicate)4 Test (org.junit.jupiter.api.Test)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)1 RangePredicate (org.neo4j.internal.kernel.api.PropertyIndexQuery.RangePredicate)1 StringPrefixPredicate (org.neo4j.internal.kernel.api.PropertyIndexQuery.StringPrefixPredicate)1