//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyRandomRanges(org.neo4j.values.storable.ValueType[] types, java.util.TreeSet<ValueAndId> sortedValues) throws Exception
        private void VerifyRandomRanges(ValueType[] types, SortedSet <ValueAndId> sortedValues)
        {
            for (int i = 0; i < 100; i++)
            {
                // Construct a random range query of random value type
                ValueType type = Random.among(types);
                Value     from = Random.randomValues().nextValueOfType(type);
                Value     to   = Random.randomValues().nextValueOfType(type);
                if (Values.COMPARATOR.Compare(from, to) > 0)
                {
                    Value tmp = from;
                    from = to;
                    to   = tmp;
                }
                bool fromInclusive = Random.nextBoolean();
                bool toInclusive   = Random.nextBoolean();

                // Expected result based on query
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> predicate = org.neo4j.internal.kernel.api.IndexQuery.range(0, from, fromInclusive, to, toInclusive);
                IndexQuery.RangePredicate <object> predicate = IndexQuery.range(0, from, fromInclusive, to, toInclusive);
                IList <long> expectedIds = expectedIds(sortedValues, from, to, fromInclusive, toInclusive);

                // Depending on order capabilities we verify ids or order and ids.
                IndexOrder[] indexOrders = IndexProvider.getCapability(Descriptor).orderCapability(predicate.ValueGroup().category());
                foreach (IndexOrder order in indexOrders)
                {
                    IList <long> actualIds = AssertInOrder(order, predicate);
                    actualIds.sort(long?.compare);
                    // then
                    assertThat(actualIds, equalTo(expectedIds));
                }
            }
        }
        /// <summary>
        /// Initializes {@code treeKeyFrom} and {@code treeKeyTo} from the <seealso cref="IndexQuery 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 <seealso cref="IndexQuery.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 <seealso cref="IndexQuery.GeometryRangePredicate"/>
        /// by the caller.
        /// </summary>
        /// <param name="treeKeyFrom"> the "from" key to construct from the query. </param>
        /// <param name="treeKeyTo"> the "to" key to construct from the query. </param>
        /// <param name="query"> the query to construct keys from to later send to <seealso cref="GBPTree"/> when reading. </param>
        /// <param name="crs"> <seealso cref="CoordinateReferenceSystem"/> for the specific {@code range}, if range is specified too. </param>
        /// <param name="range"> sub-range of a larger <seealso cref="IndexQuery.GeometryRangePredicate"/> to use instead of <seealso cref="IndexQuery.GeometryRangePredicate"/>
        /// in the query. </param>
        /// <returns> {@code true} if filtering is needed for the results from the reader, otherwise {@code false}. </returns>
        private bool InitializeRangeForGeometrySubQuery(GenericKey treeKeyFrom, GenericKey treeKeyTo, IndexQuery[] query, CoordinateReferenceSystem crs, SpaceFillingCurve.LongRange range)
        {
            bool needsFiltering = false;

            for (int i = 0; i < query.Length; i++)
            {
                IndexQuery predicate = query[i];
                switch (predicate.Type())
                {
                case exists:
                    treeKeyFrom.InitValueAsLowest(i, ValueGroup.UNKNOWN);
                    treeKeyTo.InitValueAsHighest(i, ValueGroup.UNKNOWN);
                    break;

                case exact:
                    IndexQuery.ExactPredicate exactPredicate = (IndexQuery.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);
                    }
                    else
                    {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> rangePredicate = (org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?>) predicate;
                        IndexQuery.RangePredicate <object> rangePredicate = (IndexQuery.RangePredicate <object>)predicate;
                        InitFromForRange(i, rangePredicate, treeKeyFrom);
                        InitToForRange(i, rangePredicate, treeKeyTo);
                    }
                    break;

                case stringPrefix:
                    IndexQuery.StringPrefixPredicate prefixPredicate = (IndexQuery.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 System.ArgumentException("IndexQuery of type " + predicate.Type() + " is not supported.");
                }
            }
            return(needsFiltering);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustSelectNumberForRangeNumericPredicate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustSelectNumberForRangeNumericPredicate()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> numberRange = org.neo4j.internal.kernel.api.IndexQuery.range(PROP_KEY, 0, true, 1, false);
            IndexQuery.RangePredicate <object> numberRange = IndexQuery.range(PROP_KEY, 0, true, 1, false);

            // then
            VerifyQueryWithCorrectReader(ExpectedForNumbers(), numberRange);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustSelectStringForRangeStringPredicate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustSelectStringForRangeStringPredicate()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> stringRange = org.neo4j.internal.kernel.api.IndexQuery.range(PROP_KEY, "abc", true, "def", false);
            IndexQuery.RangePredicate <object> stringRange = IndexQuery.range(PROP_KEY, "abc", true, "def", false);

            // then
            VerifyQueryWithCorrectReader(ExpectedForStrings(), stringRange);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustSelectSpatialForRangeGeometricPredicate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustSelectSpatialForRangeGeometricPredicate()
        {
            // given
            assumeTrue(HasSpatialSupport());
            PointValue from = Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.0, 1.0);
            PointValue to   = Values.pointValue(CoordinateReferenceSystem.Cartesian, 2.0, 2.0);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> geometryRange = org.neo4j.internal.kernel.api.IndexQuery.range(PROP_KEY, from, true, to, false);
            IndexQuery.RangePredicate <object> geometryRange = IndexQuery.range(PROP_KEY, from, true, to, false);

            // then
            VerifyQueryWithCorrectReader(_readers[SPATIAL], geometryRange);
        }
        private static void InitToForRange <T1>(int stateSlot, IndexQuery.RangePredicate <T1> rangePredicate, GenericKey treeKeyTo)
        {
            Value toValue = rangePredicate.ToValue();

            if (toValue == Values.NO_VALUE)
            {
                treeKeyTo.InitValueAsHighest(stateSlot, rangePredicate.ValueGroup());
            }
            else
            {
                treeKeyTo.InitFromValue(stateSlot, toValue, ToInclusion(rangePredicate));
                treeKeyTo.CompareId = true;
            }
        }
        private static void InitFromForRange <T1>(int stateSlot, IndexQuery.RangePredicate <T1> rangePredicate, GenericKey treeKeyFrom)
        {
            Value fromValue = rangePredicate.FromValue();

            if (fromValue == Values.NO_VALUE)
            {
                treeKeyFrom.InitValueAsLowest(stateSlot, rangePredicate.ValueGroup());
            }
            else
            {
                treeKeyFrom.InitFromValue(stateSlot, fromValue, FromInclusion(rangePredicate));
                treeKeyFrom.CompareId = true;
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rangeSeekByStringOverPartitions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RangeSeekByStringOverPartitions()
        {
            PartitionedIndexReader indexReader = CreatePartitionedReaderFromReaders();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> query = org.neo4j.internal.kernel.api.IndexQuery.range(1, "a", false, "b", true);
            IndexQuery.RangePredicate <object> query = IndexQuery.range(1, "a", false, "b", true);
            when(_indexReader1.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 1));
            when(_indexReader2.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 2));
            when(_indexReader3.query(query)).thenReturn(PrimitiveLongResourceCollections.iterator(null, 3));

            LongSet results = PrimitiveLongCollections.asSet(indexReader.Query(query));

            VerifyResult(results);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideResultInOrderIfCapable() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideResultInOrderIfCapable()
        {
            int label = Token.nodeLabel("Node");
            int prop  = Token.propertyKey("prop");

            RandomValues   randomValues = RandomRule.randomValues();
            IndexReference index        = SchemaRead.index(label, prop);

            for (int i = 0; i < _nIterations; i++)
            {
                ValueType    type  = randomValues.Among(_targetedTypes);
                IndexOrder[] order = index.OrderCapability(type.valueGroup.category());
                foreach (IndexOrder indexOrder in order)
                {
                    if (indexOrder == IndexOrder.NONE)
                    {
                        continue;
                    }
                    NodeValueTuple from = new NodeValueTuple(this, long.MinValue, randomValues.NextValueOfType(type));
                    NodeValueTuple to   = new NodeValueTuple(this, long.MaxValue, randomValues.NextValueOfType(type));
                    if (COMPARATOR.compare(from, to) > 0)
                    {
                        NodeValueTuple tmp = from;
                        from = to;
                        to   = tmp;
                    }
                    bool fromInclusive = randomValues.NextBoolean();
                    bool toInclusive   = randomValues.NextBoolean();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> range = org.neo4j.internal.kernel.api.IndexQuery.range(prop, from.getOnlyValue(), fromInclusive, to.getOnlyValue(), toInclusive);
                    IndexQuery.RangePredicate <object> range = IndexQuery.range(prop, from.OnlyValue, fromInclusive, to.OnlyValue, toInclusive);

                    using (NodeValueIndexCursor node = Cursors.allocateNodeValueIndexCursor())
                    {
                        Read.nodeIndexSeek(index, node, indexOrder, false, range);

                        IList <long> expectedIdsInOrder = expectedIdsInOrder(from, fromInclusive, to, toInclusive, indexOrder);
                        IList <long> actualIdsInOrder   = new List <long>();
                        while (node.Next())
                        {
                            actualIdsInOrder.Add(node.NodeReference());
                        }

                        assertEquals(expectedIdsInOrder, actualIdsInOrder, "actual node ids not in same order as expected");
                    }
                }
            }
        }
Exemple #10
0
        private void RangeQuery <T1>(IndexDescriptor descriptor, IndexQuery.RangePredicate <T1> predicate)
        {
            TransactionState txState = _read.txState();

            if (_needsValues)
            {
                AddedWithValuesAndRemoved changes = indexUpdatesWithValuesForRangeSeek(txState, descriptor, predicate, _indexOrder);
                _addedWithValues = changes.Added.GetEnumerator();
                _removed         = _removed(txState, changes.Removed);
            }
            else
            {
                AddedAndRemoved changes = indexUpdatesForRangeSeek(txState, descriptor, predicate, _indexOrder);
                _added   = changes.Added.longIterator();
                _removed = _removed(txState, changes.Removed);
            }
        }
 private static NativeIndexKey.Inclusion ToInclusion <T1>(IndexQuery.RangePredicate <T1> rangePredicate)
 {
     return(rangePredicate.ToInclusive() ? HIGH : LOW);
 }
 private static NativeIndexKey.Inclusion FromInclusion <T1>(IndexQuery.RangePredicate <T1> rangePredicate)
 {
     return(rangePredicate.FromInclusive() ? LOW : HIGH);
 }
Exemple #13
0
        internal static AddedWithValuesAndRemoved IndexUpdatesWithValuesForRangeSeek <T1>(ReadableTransactionState txState, IndexDescriptor descriptor, IndexQuery.RangePredicate <T1> predicate, IndexOrder indexOrder)
        {
            Value lower = predicate.FromValue();
            Value upper = predicate.ToValue();

            if (lower == null || upper == null)
            {
                throw new System.InvalidOperationException("Use Values.NO_VALUE to encode the lack of a bound");
            }

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.NavigableMap<org.neo4j.values.storable.ValueTuple, ? extends org.neo4j.storageengine.api.txstate.LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
            NavigableMap <ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.GetSortedIndexUpdates(descriptor.Schema());

            if (sortedUpdates == null)
            {
                return(_emptyAddedAndRemovedWithValues);
            }

            ValueTuple selectedLower;
            bool       selectedIncludeLower;

            ValueTuple selectedUpper;
            bool       selectedIncludeUpper;

            if (lower == NO_VALUE)
            {
                selectedLower        = ValueTuple.of(Values.minValue(predicate.ValueGroup(), upper));
                selectedIncludeLower = true;
            }
            else
            {
                selectedLower        = ValueTuple.of(lower);
                selectedIncludeLower = predicate.FromInclusive();
            }

            if (upper == NO_VALUE)
            {
                selectedUpper        = ValueTuple.of(Values.maxValue(predicate.ValueGroup(), lower));
                selectedIncludeUpper = false;
            }
            else
            {
                selectedUpper        = ValueTuple.of(upper);
                selectedIncludeUpper = predicate.ToInclusive();
            }

            MutableList <NodeWithPropertyValues> added = Lists.mutable.empty();
            MutableLongSet removed = LongSets.mutable.empty();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper);
            IDictionary <ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> entry : inRange.entrySet())
            foreach (KeyValuePair <ValueTuple, ? extends LongDiffSets> entry in inRange.SetOfKeyValuePairs())
            {
                ValueTuple   values               = entry.Key;
                Value[]      valuesArray          = values.Values;
                LongDiffSets diffForSpecificValue = entry.Value;

                // The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
                // TODO: If the composite index starts to be able to handle spatial types the line below needs enhancement
                if (predicate.RegularOrder || predicate.AcceptsValue(values.OnlyValue))
                {
                    diffForSpecificValue.Added.each(nodeId => added.add(new NodeWithPropertyValues(nodeId, valuesArray)));
                    removed.addAll(diffForSpecificValue.Removed);
                }
            }
            return(new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed));
        }