예제 #1
0
        public static string ToString(RangePredicate predicate)
        {
            var visitor = new SnQueryToStringVisitor();

            visitor.VisitRangePredicate(predicate);
            return(visitor.Output);
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNumRange_ComparingBigDoublesAndLongs()
        public virtual void TestNumRangeComparingBigDoublesAndLongs()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, 9007199254740993L, true, null, true);
            RangePredicate <object> p = IndexQuery.Range(_propId, 9007199254740993L, true, null, true);

            assertFalse(Test(p, 9007199254740992D));
        }
예제 #3
0
        //TODO: Also insert points which can't be compared e.g. Cartesian and (-100, 100)

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testGeometryRange_FalseForIrrelevant()
        public virtual void TestGeometryRangeFalseForIrrelevant()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, gps2, true, gps5, true);
            RangePredicate <object> p = IndexQuery.Range(_propId, _gps2, true, _gps5, true);

            AssertFalseForOtherThings(p);
        }
예제 #4
0
        public void RenderRangePredicate()
        {
            Column column = new Column("Column1");
            IntegerLiteralValue stringLiteralValue1 = new IntegerLiteralValue(1);
            IntegerLiteralValue stringLiteralValue2 = new IntegerLiteralValue(3);
            RangePredicate      rangePredicate      = new RangePredicate(column, stringLiteralValue1, stringLiteralValue2);

            Assert.AreEqual("[Column1] BETWEEN 1 AND 3", sqlClientRenderer.Render(rangePredicate));
        }
예제 #5
0
 public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
 {
     if (!SharingRelatedFieldNames.Contains(range.FieldName))
     {
         _isSharingStack.Push(false);
         return(range);
     }
     throw new InvalidContentSharingQueryException("Range query cannot be used in a sharing related query clause.");
 }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testStringRange_LowerUnbounded()
        public virtual void TestStringRangeLowerUnbounded()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, null, false, "bee", false);
            RangePredicate <object> p = IndexQuery.Range(_propId, null, false, "bee", false);

            assertTrue(Test(p, ""));
            assertTrue(Test(p, "bed"));
            assertFalse(Test(p, "bee"));
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNumRange_ExclusiveLowerExclusiveLower()
        public virtual void TestNumRangeExclusiveLowerExclusiveLower()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, 11, false, 13, false);
            RangePredicate <object> p = IndexQuery.Range(_propId, 11, false, 13, false);

            assertFalse(Test(p, 11));
            assertTrue(Test(p, 12));
            assertFalse(Test(p, 13));
        }
예제 #8
0
            public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
            {
                var visitedField = range.FieldName;

                if (!_fieldNames.Contains(visitedField))
                {
                    _fieldNames.Add(visitedField);
                }
                return(base.VisitRangePredicate(range));
            }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testStringRange_InclusiveLowerInclusiveUpper()
        public virtual void TestStringRangeInclusiveLowerInclusiveUpper()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, "bbb", true, "bee", true);
            RangePredicate <object> p = IndexQuery.Range(_propId, "bbb", true, "bee", true);

            assertFalse(Test(p, "bba"));
            assertTrue(Test(p, "bbb"));
            assertTrue(Test(p, "bee"));
            assertFalse(Test(p, "beea"));
            assertFalse(Test(p, "bef"));
        }
예제 #10
0
        // VALUE GROUP SCAN
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testValueGroupRange()
        public virtual void TestValueGroupRange()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, org.neo4j.values.storable.ValueGroup.DATE);
            RangePredicate <object> p = IndexQuery.Range(_propId, ValueGroup.DATE);

            assertTrue(Test(p, DateValue.date(-4000, 1, 31)));
            assertTrue(Test(p, DateValue.date(2018, 3, 7)));
            assertFalse(Test(p, DateTimeValue.datetime(2018, 3, 7, 0, 0, 0, 0, ZoneOffset.UTC)));
            assertFalse(Test(p, stringValue("hej")));
            assertFalse(Test(p, _gps2_3d));
        }
예제 #11
0
        public void CreateRangePredicate()
        {
            Column column = new Column("Column1");
            IntegerLiteralValue stringLiteralValue1 = new IntegerLiteralValue(1);
            IntegerLiteralValue stringLiteralValue2 = new IntegerLiteralValue(3);
            RangePredicate      rangePredicate      = new RangePredicate(column, stringLiteralValue1, stringLiteralValue2);

            Assert.AreEqual(column, rangePredicate.LeftExpression);
            Assert.IsNull(rangePredicate.NotModifier);
            Assert.AreEqual(stringLiteralValue1, rangePredicate.MiddleExpression);
            Assert.AreEqual(stringLiteralValue2, rangePredicate.RightExpression);
        }
예제 #12
0
        public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
        {
            var result = false;

            if (_indexDoc.Fields.TryGetValue(range.FieldName, out var field))
            {
                var min = range.Min;
                var max = range.Max;

                // play permutation of min, max and exclusiveness
                if (min != null && max != null)
                {
                    if (min.Type == field.Type && max.Type == field.Type)
                    {
                        if (!range.MinExclusive && !range.MaxExclusive)
                        {
                            result = field >= min && field <= max;
                        }
                        else if (!range.MinExclusive && range.MaxExclusive)
                        {
                            result = field >= min && field < max;
                        }
                        else if (range.MinExclusive && !range.MaxExclusive)
                        {
                            result = field > min && field <= max;
                        }
                        else
                        {
                            result = field > min && field < max;
                        }
                    }
                }
                else if (min != null)
                {
                    if (min.Type == field.Type)
                    {
                        result = range.MinExclusive ? field > min : field >= min;
                    }
                }
                else
                {
                    if (max.Type == field.Type)
                    {
                        result = range.MaxExclusive ? field < max : field <= max;
                    }
                }
            }

            _hitStack.Push(result);

            return(range);
        }
예제 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testCRSRange()
        public virtual void TestCRSRange()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, org.neo4j.values.storable.CoordinateReferenceSystem.WGS84);
            RangePredicate <object> p = IndexQuery.Range(_propId, CoordinateReferenceSystem.WGS84);

            assertTrue(Test(p, _gps2));
            assertFalse(Test(p, DateValue.date(-4000, 1, 31)));
            assertFalse(Test(p, stringValue("hej")));
            assertFalse(Test(p, _car1));
            assertFalse(Test(p, _car4));
            assertFalse(Test(p, _gps1_3d));
        }
예제 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testDateRange()
        public virtual void TestDateRange()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, org.neo4j.values.storable.DateValue.date(2014, 7, 7), true, org.neo4j.values.storable.DateValue.date(2017,3, 7), false);
            RangePredicate <object> p = IndexQuery.Range(_propId, DateValue.date(2014, 7, 7), true, DateValue.date(2017, 3, 7), false);

            assertFalse(Test(p, DateValue.date(2014, 6, 8)));
            assertTrue(Test(p, DateValue.date(2014, 7, 7)));
            assertTrue(Test(p, DateValue.date(2016, 6, 8)));
            assertFalse(Test(p, DateValue.date(2017, 3, 7)));
            assertFalse(Test(p, DateValue.date(2017, 3, 8)));
            assertFalse(Test(p, LocalDateTimeValue.localDateTime(2016, 3, 8, 0, 0, 0, 0)));
        }
예제 #15
0
        public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
        {
            var fieldName = range.FieldName;
            var minIncl   = !range.MinExclusive;
            var maxIncl   = !range.MaxExclusive;

            var min = ConvertRangeValue(range.Min);
            var max = ConvertRangeValue(range.Max);

            if (min == null && max == null)
            {
                throw new CompilerException("Range is not supported if both min and max values are null.");
            }

            if (min != null && max != null && (min.Type != max.Type))
            {
                throw new CompilerException(
                          $"Range is not supported for different types: min value is {min.Type} but max value is {max.Type}");
            }

            Query query;

            switch (min?.Type ?? max.Type)
            {
            case IndexValueType.String:
                query = new TermRangeQuery(fieldName, min?.StringValue, max?.StringValue, minIncl, maxIncl);
                break;

            case IndexValueType.Int:
                query = NumericRangeQuery.NewIntRange(fieldName, min?.IntegerValue, max?.IntegerValue, minIncl, maxIncl);
                break;

            case IndexValueType.Long:
                query = NumericRangeQuery.NewLongRange(fieldName, min?.LongValue, max?.LongValue, minIncl, maxIncl);
                break;

            case IndexValueType.Float:
                query = NumericRangeQuery.NewFloatRange(fieldName, min?.SingleValue ?? float.MinValue, max?.SingleValue ?? float.MaxValue, minIncl, maxIncl);
                break;

            case IndexValueType.Double:
                query = NumericRangeQuery.NewDoubleRange(fieldName, min?.DoubleValue ?? double.MinValue, max?.DoubleValue ?? double.MaxValue, minIncl, maxIncl);
                break;

            default:
                throw new CompilerException("Cannot create range query from this type");
            }
            _queryTree.Push(query);

            return(range);
        }
예제 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testGeometryRange_LowerUnbounded()
        public virtual void TestGeometryRangeLowerUnbounded()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> p = IndexQuery.range(propId, null, false, gps5, false);
            RangePredicate <object> p = IndexQuery.Range(_propId, null, false, _gps5, false);

            assertTrue(Test(p, _gps1));
            assertTrue(Test(p, _gps3));
            assertFalse(Test(p, _gps5));
            assertFalse(Test(p, _car1));
            assertFalse(Test(p, _car2));
            assertFalse(Test(p, _car3));
            assertFalse(Test(p, _gps1_3d));
        }
예제 #17
0
            public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
            {
                if (!_queryInfo.QueryFieldNames.Contains(range.FieldName))
                {
                    _queryInfo.QueryFieldNames.Add(range.FieldName);
                }

                _queryInfo.RangeQueries++;
                if (range.Min != null && range.Max != null)
                {
                    _queryInfo.FullRangeQueries++;
                }

                return(base.VisitRangePredicate(range));
            }
예제 #18
0
        public override string Render(RangePredicate rangePredicate)
        {
            StringBuilder text = new StringBuilder();

            text.AppendFormat("{0} ", rangePredicate.LeftExpression.Render(this));

            if (rangePredicate.NotModifier != null)
            {
                text.AppendFormat("{0} ", rangePredicate.NotModifier.Render(this));
            }

            text.AppendFormat("BETWEEN {0} ", rangePredicate.MiddleExpression.Render(this));

            text.AppendFormat("AND {0} ", rangePredicate.RightExpression.Render(this));

            return(text.ToString().Trim());
        }
예제 #19
0
        public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
        {
            var min          = range.Min;
            var max          = range.Max;
            var minExclusive = range.MinExclusive;
            var maxExclusive = range.MaxExclusive;

            IndexValue oneTerm = null;

            _output.Append(range.FieldName);
            _output.Append(":");

            string op = null;

            if (min == null)
            {
                op      = !maxExclusive ? "<=" : "<";
                oneTerm = max;
            }
            if (max == null)
            {
                op      = !minExclusive ? ">=" : ">";
                oneTerm = min;
            }

            if (op == null)
            {
                _output.Append(!minExclusive ? '[' : '{');
                _output.Append(Escape(min));
                _output.Append(" TO ");
                _output.Append(Escape(max));
                _output.Append(!maxExclusive ? ']' : '}');
            }
            else
            {
                _output.Append(op).Append(Escape(oneTerm));
            }
            BoostTostring(range.Boost);

            return(base.VisitRangePredicate(range));
        }
예제 #20
0
 /// <summary>
 /// Visits the given RangePredicate.
 /// </summary>
 /// <param name="range">The predicate to visit.</param>
 /// <returns>The modified predicate, if it was modified; otherwise, returns the original predicate.</returns>
 public virtual SnQueryPredicate VisitRangePredicate(RangePredicate range)
 {
     return(range);
 }
예제 #21
0
            public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
            {
                var result = new List <int>();

                if (_index.IndexData.TryGetValue(range.FieldName, out var fieldValues))
                {
                    var min = InMemoryIndex.IndexValueToString(range.Min);
                    var max = InMemoryIndex.IndexValueToString(range.Max);
                    IEnumerable <KeyValuePair <string, List <int> > > expression;

                    // play permutation of min, max and exclusiveness
                    if (min != null && max != null)
                    {
                        if (!range.MinExclusive && !range.MaxExclusive)
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) >= 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) <= 0));
                        }
                        else if (!range.MinExclusive && range.MaxExclusive)
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) >= 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) < 0));
                        }
                        else if (range.MinExclusive && !range.MaxExclusive)
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) > 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) <= 0));
                        }
                        else
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) > 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) < 0));
                        }
                    }
                    else if (min != null)
                    {
                        expression = !range.MinExclusive
                            ? fieldValues.Where(x => string.Compare(x.Key, min, StringComparison.Ordinal) >= 0)
                            : fieldValues.Where(x => string.Compare(x.Key, min, StringComparison.Ordinal) > 0);
                    }
                    else
                    {
                        expression = !range.MaxExclusive
                            ? fieldValues.Where(x => string.Compare(x.Key, max, StringComparison.Ordinal) <= 0)
                            : fieldValues.Where(x => string.Compare(x.Key, max, StringComparison.Ordinal) < 0);
                    }

                    var lists = expression.Select(x => x.Value).ToArray();

                    // aggregate
                    var aggregation = new int[0].AsEnumerable();
                    foreach (var item in lists)
                    {
                        aggregation = aggregation.Union(item);
                    }
                    result = aggregation.Distinct().ToList();
                }

                _hitStack.Push(result);

                return(range);
            }
예제 #22
0
        private static SnQuery BuildSnQuery(Expression expression, Type sourceCollectionItemType, string contextPath, ChildrenDefinition childrenDef, out string elementSelection)
        {
            SnQueryPredicate q0 = null;

            elementSelection = null;

            SnLinqVisitor v = null;

            // #1 compiling linq expression
            if (expression != null)
            {
                var v1    = new SetExecVisitor();
                var expr1 = v1.Visit(expression);
                var expr2 = expr1;
                if (v1.HasParameter)
                {
                    var v2 = new ExecutorVisitor(v1.GetExpressions());
                    expr2 = v2.Visit(expr1);
                }
                v = new SnLinqVisitor();
                v.Visit(expr2);
                q0 = v.GetPredicate(sourceCollectionItemType, childrenDef);
                elementSelection = v.ElementSelection;
            }

            // #2 combining with additional query clause
            SnQuery lq = null;

            if (!string.IsNullOrEmpty(childrenDef?.ContentQuery))
            {
                var queryText = TemplateManager.Replace(typeof(ContentQueryTemplateReplacer), childrenDef.ContentQuery);

                lq = SnQuery.Parse(queryText, new SnQueryContext(QuerySettings.Default, User.Current.Id));
                q0 = q0 == null
                    ? lq.QueryTree
                    : CombineQueries(q0, lq.QueryTree);
            }

            // #3 combining with context path
            if (q0 == null)
            {
                if (childrenDef != null && childrenDef.PathUsage != PathUsageMode.NotUsed && contextPath != null)
                {
                    q0 = GetPathPredicate(contextPath, childrenDef.PathUsage == PathUsageMode.InTreeAnd || childrenDef.PathUsage == PathUsageMode.InTreeOr);
                }
            }
            else
            {
                if (childrenDef != null && childrenDef.PathUsage != PathUsageMode.NotUsed && contextPath != null)
                {
                    q0 = CombinePathPredicate(q0, contextPath, childrenDef.PathUsage);
                }
            }

            // #4 empty query substitution
            if (q0 == null)
            {
                q0 = new RangePredicate(IndexFieldName.NodeId, new IndexValue(0), null, true, false);
            }

            var q1 = OptimizeBooleans(q0);

            // #5 configuring query by linq expression (the smallest priority)
            var query = SnQuery.Create(q1);

            if (v != null)
            {
                query.Skip          = v.Skip;
                query.Top           = v.Top;
                query.CountOnly     = v.CountOnly;
                query.Sort          = v.Sort.ToArray();
                query.ThrowIfEmpty  = v.ThrowIfEmpty;
                query.ExistenceOnly = v.ExistenceOnly;
            }
            // #6 configuring query by children definition
            if (childrenDef != null)
            {
                if (childrenDef.Skip > 0)
                {
                    query.Skip = childrenDef.Skip;
                }
                if (childrenDef.Top > 0)
                {
                    query.Top = childrenDef.Top;
                }
                if (childrenDef.Sort != null)
                {
                    query.Sort = childrenDef.Sort.ToArray();
                }
                if (childrenDef.CountAllPages != null)
                {
                    query.CountAllPages = childrenDef.CountAllPages.Value;
                }
                if (childrenDef.EnableAutofilters != FilterStatus.Default)
                {
                    query.EnableAutofilters = childrenDef.EnableAutofilters;
                }
                if (childrenDef.EnableLifespanFilter != FilterStatus.Default)
                {
                    query.EnableLifespanFilter = childrenDef.EnableLifespanFilter;
                }
                if (childrenDef.QueryExecutionMode != QueryExecutionMode.Default)
                {
                    query.QueryExecutionMode = childrenDef.QueryExecutionMode;
                }
            }

            // #7 configuring query by additional query clause (the biggest priority)
            if (lq != null)
            {
                if (lq.Skip > 0)
                {
                    query.Skip = lq.Skip;
                }
                if (lq.Top > 0 && lq.Top != int.MaxValue)
                {
                    query.Top = lq.Top;
                }
                if (lq.Sort != null && lq.Sort.Length > 0)
                {
                    query.Sort = lq.Sort;
                }
                if (lq.EnableAutofilters != FilterStatus.Default)
                {
                    query.EnableAutofilters = lq.EnableAutofilters;
                }
                if (lq.EnableLifespanFilter != FilterStatus.Default)
                {
                    query.EnableLifespanFilter = lq.EnableLifespanFilter;
                }
                if (lq.QueryExecutionMode != QueryExecutionMode.Default)
                {
                    query.QueryExecutionMode = lq.QueryExecutionMode;
                }
                if (lq.AllVersions)
                {
                    query.AllVersions = true;
                }
            }

            return(query);
        }
예제 #23
0
 public abstract string Render(RangePredicate rangePredicate);
 public RangePredicator(RangePredicate <T> predicate)
 {
     this.predicate = predicate;
 }
예제 #25
0
 public bool TryFindRangeData(RangePredicate <TEl> rangePredicate, out TRange data)
 {
     return(TryFindRangeData(Root, new RangePredicator <TEl>(rangePredicate), out data));
 }