Esempio n. 1
0
 private static void AssertValueIsString(string fieldName, ValueTokenType fieldType)
 {
     if (fieldType != ValueTokenType.String)
     {
         ThrowValueTypeMismatch(fieldName, fieldType, ValueTokenType.String);
     }
 }
Esempio n. 2
0
        public static SelectField CreateValue(string val, string alias, ValueTokenType type)
        {
            object finalVal = val;

            switch (type)
            {
            case AST.ValueTokenType.Long:
                finalVal = QueryBuilder.ParseInt64WithSeparators(val);
                break;

            case AST.ValueTokenType.Double:
                finalVal = double.Parse(val, CultureInfo.InvariantCulture);
                break;

            case AST.ValueTokenType.True:
                finalVal = true;
                break;

            case AST.ValueTokenType.False:
                finalVal = false;
                break;

            case AST.ValueTokenType.Null:
                finalVal = null;
                break;
            }

            return(new SelectField
            {
                Value = finalVal,
                Alias = alias ?? val,
                ValueTokenType = type
            });
        }
Esempio n. 3
0
 private static void AssertValueIsNumber(string fieldName, ValueTokenType fieldType)
 {
     if (fieldType != ValueTokenType.Double && fieldType != ValueTokenType.Long)
     {
         ThrowValueTypeMismatch(fieldName, fieldType, ValueTokenType.Double);
     }
 }
Esempio n. 4
0
        public static SelectField CreateValue(string val, string alias, ValueTokenType type)
        {
            object finalVal = val;
            switch (type)
            {
                case Parser.ValueTokenType.Long:
                    finalVal = long.Parse(val, CultureInfo.InvariantCulture);
                    break;
                case Parser.ValueTokenType.Double:
                    finalVal = double.Parse(val, CultureInfo.InvariantCulture);
                    break;
                case Parser.ValueTokenType.True:
                    finalVal = true;
                    break;
                case Parser.ValueTokenType.False:
                    finalVal = false;
                    break;
                case Parser.ValueTokenType.Null:
                    finalVal = null;
                    break;
            }

            return new SelectField
            {
                Value = finalVal,
                Alias = alias,
                ValueTokenType = type
            };
        }
Esempio n. 5
0
        public static T GetOptions <T>(string optionsAsStringOrParameterName, ValueTokenType optionsType, BlittableJsonReaderObject parameters, JsonOperationContext context)
        {
            BlittableJsonReaderObject optionsJson;

            if (optionsType == ValueTokenType.Parameter)
            {
                if (parameters == null)
                {
                    throw new ArgumentNullException(nameof(parameters));
                }

                if (parameters.TryGetMember(optionsAsStringOrParameterName, out var optionsObject) == false)
                {
                    throw new InvalidOperationException($"Parameter '{optionsAsStringOrParameterName}' containing '{typeof(T).Name}' was not present in the list of parameters.");
                }

                optionsJson = optionsObject as BlittableJsonReaderObject;

                if (optionsJson == null)
                {
                    throw new InvalidOperationException($"Parameter '{optionsAsStringOrParameterName}' should contain JSON object.");
                }
            }
            else if (optionsType == ValueTokenType.String)
            {
                optionsJson = IndexReadOperation.ParseJsonStringIntoBlittable(optionsAsStringOrParameterName, context);
            }
            else
            {
                throw new InvalidOperationException($"Unknown options type '{optionsType}'.");
            }

            return(DocumentConventions.DefaultForServer.Serialization.DefaultConverter.FromBlittable <T>(optionsJson, "options"));
        }
Esempio n. 6
0
        public void AddOptions(string optionsAsStringOrParameterName, ValueTokenType type)
        {
            FieldOptionsHelper.ValidateOptions <FacetOptions>(optionsAsStringOrParameterName, type);

            _optionsAsStringOrParameterName = optionsAsStringOrParameterName;
            _optionsType = type;
        }
Esempio n. 7
0
        public void AddTerm(string termAsStringOrParameterName, ValueTokenType type)
        {
            if (type != AST.ValueTokenType.String && type != AST.ValueTokenType.Parameter)
            {
                throw new InvalidOperationException($"Term can only be passed as string or as a parameter pointing to string, but was '{type}'.");
            }

            _termAsStringOrParameterName = termAsStringOrParameterName;
            _termType = type;
        }
Esempio n. 8
0
        public void AddOptions(string optionsAsStringOrParameterName, ValueTokenType type)
        {
            if (type != AST.ValueTokenType.String && type != AST.ValueTokenType.Parameter)
            {
                throw new InvalidOperationException($"{nameof(FacetOptions)} can only be passed as JSON string or as a parameter pointing to JSON object, but was '{type}'.");
            }

            _optionsAsStringOrParameterName = optionsAsStringOrParameterName;
            _optionsType = type;
        }
Esempio n. 9
0
        public void AddFragmentCount(string fragmentCountAsString, ValueTokenType type)
        {
            if (type != ValueTokenType.Long)
            {
                throw new InvalidOperationException($"FragmentCount can only be passed as long, but was '{type}'.");
            }

            if (int.TryParse(fragmentCountAsString, out _fragmentCount) == false)
            {
                throw new InvalidOperationException($"FragmentCount needs to be a number, but was '{fragmentCountAsString}'.");
            }
        }
Esempio n. 10
0
        public static bool AreValueTokenTypesValid(ValueTokenType previous, ValueTokenType current)
        {
            if (previous == ValueTokenType.Null)
            {
                return(true);
            }

            if (current == ValueTokenType.Null)
            {
                return(true);
            }

            return(previous == current);
        }
Esempio n. 11
0
        private static object GetFieldValue(string value, ValueTokenType type, BlittableJsonReaderObject queryParameters)
        {
            switch (type)
            {
            case ValueTokenType.Long:
                return(QueryBuilder.ParseInt64WithSeparators(value));

            case ValueTokenType.Double:
                return(double.Parse(value, CultureInfo.InvariantCulture));

            case ValueTokenType.Parameter:
                queryParameters.TryGet(value, out object o);
                return(o);

            default:
                return(value);
            }
        }
Esempio n. 12
0
        private static object UnwrapParameter(object parameterValue, ValueTokenType parameterType)
        {
            switch (parameterType)
            {
            case ValueTokenType.Long:
                return(parameterValue);

            case ValueTokenType.Double:
                var dlnv = (LazyNumberValue)parameterValue;
                return(dlnv.ToDouble(CultureInfo.InvariantCulture));

            case ValueTokenType.String:
                if (parameterValue == null)
                {
                    return(null);
                }

                var lsv = parameterValue as LazyStringValue;
                if (lsv != null)
                {
                    return(lsv.ToString());
                }

                var lcsv = parameterValue as LazyCompressedStringValue;
                if (lcsv != null)
                {
                    return(lcsv.ToString());
                }

                return(parameterValue.ToString());

            case ValueTokenType.True:
                return(LuceneDocumentConverterBase.TrueString);

            case ValueTokenType.False:
                return(LuceneDocumentConverterBase.FalseString);

            case ValueTokenType.Null:
                return(null);

            default:
                throw new ArgumentOutOfRangeException(nameof(parameterType), parameterType, null);
            }
        }
Esempio n. 13
0
 public static void ValidateOptions <T>(string optionsAsStringOrParameterName, ValueTokenType optionsType)
 {
     if (optionsType != ValueTokenType.String && optionsType != ValueTokenType.Parameter)
     {
         throw new InvalidOperationException($"{typeof(T).Name} can only be passed as JSON string or as a parameter pointing to JSON object, but was '{optionsType}'.");
     }
 }
Esempio n. 14
0
        private static (string LuceneFieldName, LuceneFieldType LuceneFieldType, LuceneTermType LuceneTermType) GetLuceneField(string fieldName, ValueTokenType valueType)
        {
            switch (valueType)
            {
            case ValueTokenType.String:
                return(fieldName, LuceneFieldType.String, LuceneTermType.String);

            case ValueTokenType.Double:
                return(fieldName + Constants.Documents.Indexing.Fields.RangeFieldSuffixDouble, LuceneFieldType.Double, LuceneTermType.Double);

            case ValueTokenType.Long:
                return(fieldName + Constants.Documents.Indexing.Fields.RangeFieldSuffixLong, LuceneFieldType.Long, LuceneTermType.Long);

            case ValueTokenType.True:
            case ValueTokenType.False:
                return(fieldName, LuceneFieldType.String, LuceneTermType.String);

            case ValueTokenType.Null:
                return(fieldName, LuceneFieldType.String, LuceneTermType.String);

            default:
                ThrowUnhandledValueTokenType(valueType);
                break;
            }

            Debug.Assert(false);

            return(null, LuceneFieldType.String, LuceneTermType.String);
        }
Esempio n. 15
0
 private static void ThrowInvalidParameterType(ValueTokenType expectedValueType, (object Value, ValueTokenType Type) item, string queryText,
Esempio n. 16
0
 private static void ThrowUnhandledValueTokenType(ValueTokenType type)
 {
     throw new NotSupportedException($"Unhandled token type: {type}");
 }
Esempio n. 17
0
        private static (string Value, RangeType Type) ConvertFieldValue(string value, ValueTokenType type)
        {
            switch (type)
            {
            case ValueTokenType.Long:
                var lng = QueryBuilder.ParseInt64WithSeparators(value);
                return(NumericUtils.DoubleToPrefixCoded(lng), RangeType.Double);

            case ValueTokenType.Double:
                var dbl = double.Parse(value, CultureInfo.InvariantCulture);
                return(NumericUtils.DoubleToPrefixCoded(dbl), RangeType.Double);

            case ValueTokenType.String:
                return(value, RangeType.None);

            case ValueTokenType.Null:
                return(null, RangeType.None);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Esempio n. 18
0
 public Argument(string nameOrValue, ValueTokenType type)
 {
     NameOrValue = nameOrValue;
     Type        = type;
 }
Esempio n. 19
0
        public static ICollection<ValueToken> TokenizeString(string str)
        {
            List<ValueToken> tokens = new List<ValueToken>();

            StringReader sr = new StringReader(str);

            string text = "";

            while (sr.Peek() != -1)
            {
                char c = (char)sr.Read();

                if (c == '[' && sr.Peek() == (int)'$' || sr.Peek() == (int)'#')
                {
                    tokens.Add(new ValueToken(ValueTokenType.Text, text.TrimEnd(new char[] { '[' })));

                    ValueTokenType valType = new ValueTokenType();

                    if(sr.Peek() == (int)'$')
                        valType = ValueTokenType.Function;
                    else if(sr.Peek() == (int)'#')
                        valType = ValueTokenType.Property;

                    // consume '$' or '#'
                    sr.Read();

                    string val = "";

                    while (true)
                    {
                        val += (char)sr.Read();

                        if (valType == ValueTokenType.Function && sr.Peek() == ')')
                        {
                            sr.Read();

                            if (sr.Peek() == ']')
                            {
                                val += ")";

                                break;
                            }
                        }
                        else if (valType == ValueTokenType.Property && sr.Peek() == ']')
                        {
                            break;
                        }
                    }

                    // consume ']'
                    sr.Read();

                    tokens.Add(new ValueToken(valType, val));
                    text = "";
                }
                else
                {
                    text += c;
                }
            }

            tokens.Add(new ValueToken(ValueTokenType.Text, text));

            List<ValueToken> newTokens = new List<ValueToken>();

            foreach (ValueToken token in tokens)
            {
                if (token.Text.Length > 0)
                    newTokens.Add(token);
            }

            sr.Close();

            return newTokens;
        }
Esempio n. 20
0
        private static (string Value, RangeType Type) ConvertFieldValue(string value, ValueTokenType type, BlittableJsonReaderObject queryParameters)
        {
            switch (type)
            {
            case ValueTokenType.Long:
                var lng = QueryBuilder.ParseInt64WithSeparators(value);
                return(NumericUtils.DoubleToPrefixCoded(lng), RangeType.Double);

            case ValueTokenType.Double:
                var dbl = double.Parse(value, CultureInfo.InvariantCulture);
                return(NumericUtils.DoubleToPrefixCoded(dbl), RangeType.Double);

            case ValueTokenType.String:
                return(value, RangeType.None);

            case ValueTokenType.Null:
                return(null, RangeType.None);

            case ValueTokenType.Parameter:
                queryParameters.TryGet(value, out object o);
                var rangeType = RangeType.None;
                if (o is long l)
                {
                    o         = NumericUtils.DoubleToPrefixCoded(l);
                    rangeType = RangeType.Double;
                }
                else if (o is LazyNumberValue lnv)
                {
                    o         = NumericUtils.DoubleToPrefixCoded((double)lnv);
                    rangeType = RangeType.Double;
                }
                return(o?.ToString(), rangeType);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Esempio n. 21
0
        public static ICollection <ValueToken> TokenizeString(string str)
        {
            List <ValueToken> tokens = new List <ValueToken>();

            StringReader sr = new StringReader(str);

            string text = "";

            while (sr.Peek() != -1)
            {
                char c = (char)sr.Read();

                if (c == '[' && sr.Peek() == (int)'$' || sr.Peek() == (int)'#')
                {
                    tokens.Add(new ValueToken(ValueTokenType.Text, text.TrimEnd(new char[] { '[' })));

                    ValueTokenType valType = new ValueTokenType();

                    if (sr.Peek() == (int)'$')
                    {
                        valType = ValueTokenType.Function;
                    }
                    else if (sr.Peek() == (int)'#')
                    {
                        valType = ValueTokenType.Property;
                    }

                    // consume '$' or '#'
                    sr.Read();

                    string val = "";

                    while (true)
                    {
                        val += (char)sr.Read();

                        if (valType == ValueTokenType.Function && sr.Peek() == ')')
                        {
                            sr.Read();

                            if (sr.Peek() == ']')
                            {
                                val += ")";

                                break;
                            }
                        }
                        else if (valType == ValueTokenType.Property && sr.Peek() == ']')
                        {
                            break;
                        }
                    }

                    // consume ']'
                    sr.Read();

                    tokens.Add(new ValueToken(valType, val));
                    text = "";
                }
                else
                {
                    text += c;
                }
            }

            tokens.Add(new ValueToken(ValueTokenType.Text, text));

            List <ValueToken> newTokens = new List <ValueToken>();

            foreach (ValueToken token in tokens)
            {
                if (token.Text.Length > 0)
                {
                    newTokens.Add(token);
                }
            }

            sr.Close();

            return(newTokens);
        }
Esempio n. 22
0
 public ValueToken(ValueTokenType type, string text)
 {
     this.type = type;
     this.text = text;
 }
Esempio n. 23
0
 public ValueExpression(StringSegment token, ValueTokenType type)
 {
     Token = token;
     Value = type;
     Type  = ExpressionType.Value;
 }
Esempio n. 24
0
 public ValueToken(ValueTokenType type, string text)
 {
     this.type = type;
     this.text = text;
 }