Beispiel #1
0
 private static IndexQuery.ExactPredicate[] AssertOnlyExactPredicates(IndexQuery[] predicates)
 {
     IndexQuery.ExactPredicate[] exactPredicates;
     if (predicates.GetType() == typeof(IndexQuery.ExactPredicate[]))
     {
         exactPredicates = (IndexQuery.ExactPredicate[])predicates;
     }
     else
     {
         exactPredicates = new IndexQuery.ExactPredicate[predicates.Length];
         for (int i = 0; i < predicates.Length; i++)
         {
             if (predicates[i] is IndexQuery.ExactPredicate)
             {
                 exactPredicates[i] = (IndexQuery.ExactPredicate)predicates[i];
             }
             else
             {
                 // TODO: what to throw?
                 throw new System.ArgumentException("Query not supported: " + Arrays.ToString(predicates));
             }
         }
     }
     return(exactPredicates);
 }
        /// <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);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void seekOverAllPartitions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SeekOverAllPartitions()
        {
            PartitionedIndexReader indexReader = CreatePartitionedReaderFromReaders();

            IndexQuery.ExactPredicate query = IndexQuery.exact(1, "Test");
            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);
        }
Beispiel #4
0
        /// <summary>
        /// Performs an index seek.
        /// </summary>
        /// <param name="read"> The Read instance to use for seeking </param>
        /// <param name="cursors"> Used for cursor allocation </param>
        /// <param name="index"> A reference to an index </param>
        /// <param name="value"> The value to seek for </param>
        /// <returns> A cursor positioned at the data found in index. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static org.neo4j.internal.kernel.api.NodeValueIndexCursor indexSeek(org.neo4j.internal.kernel.api.Read read, org.neo4j.internal.kernel.api.CursorFactory cursors, org.neo4j.internal.kernel.api.IndexReference index, Object value) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        public static NodeValueIndexCursor IndexSeek(Read read, CursorFactory cursors, IndexReference index, object value)
        {
            Debug.Assert(index.Properties().Length == 1);
            if (value == Values.NO_VALUE || value == null)
            {
                return([email protected]_Fields.Empty);
            }
            else
            {
                NodeValueIndexCursor      cursor = cursors.AllocateNodeValueIndexCursor();
                IndexQuery.ExactPredicate query  = exact(index.Properties()[0], makeValueNeoSafe(value));
                read.NodeIndexSeek(index, cursor, IndexOrder.NONE, false, query);
                return(cursor);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void exactMatchOnAllValues(java.util.List<org.neo4j.values.storable.Value> values) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException
        private void ExactMatchOnAllValues(IList <Value> values)
        {
            using (IndexReader indexReader = _accessor.newReader())
            {
                SimpleNodeValueClient client = new SimpleNodeValueClient();
                foreach (Value value in values)
                {
                    IndexQuery.ExactPredicate exact = IndexQuery.exact(_descriptor.schema().PropertyId, value);
                    indexReader.Query(client, IndexOrder.NONE, true, exact);

                    // then
                    assertTrue(client.Next());
                    assertEquals(value, client.Values[0]);
                    assertFalse(client.Next());
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyIndex(org.neo4j.kernel.impl.api.TransactionToApply tx) throws Exception
            internal virtual void VerifyIndex(TransactionToApply tx)
            {
                using (IndexReader reader = Index.newReader())
                {
                    NodeVisitor visitor = new NodeVisitor();
                    for (int i = 0; tx != null; i++)
                    {
                        tx.TransactionRepresentation().accept(visitor.Clear());

                        Value propertyValue             = propertyValue(Id, Base + i);
                        IndexQuery.ExactPredicate query = IndexQuery.exact(outerInstance.descriptor.PropertyId, propertyValue);
                        LongIterator hits = reader.Query(query);
                        assertEquals("Index doesn't contain " + visitor.NodeId + " " + propertyValue, visitor.NodeId, hits.next());
                        assertFalse(hits.hasNext());
                        tx = tx.Next();
                    }
                }
            }