public static ScalarFunction Create(string name, List <ScalarValue> args)
        {
            MethodInfo method = null;

            if (CustomFunctions.TryGetValue(name, out method))
            {
                ScalarFunction newFunction = new CustomFunction(name, method)
                {
                    Arguments = args
                };

                return(newFunction);
            }

            if (mapping.TryGetValue(name, out ConstructorInfo constructor))
            {
                ScalarFunction newFunction = (ScalarFunction)constructor.Invoke(new object[] { });
                newFunction.Name      = name;
                newFunction.Arguments = args;
                return(newFunction);
            }

            if (GlobalFunctions.KqlFunctions.TryGetValue(name, out var cslFun))
            {
                return(new UserDefinedFunction
                {
                    Name = name,
                    Parameters = cslFun.Arguments,
                    Body = cslFun.Body,
                    Arguments = args,
                });
            }

            throw new UnknownFunctionException($"Unknown function: '{name}'");
        }
Beispiel #2
0
        public EvaluateOperator(string args)
        {
            args = args.Replace("evaluate ", string.Empty);

            KustoCode query;

            lock (parserLock)
            {
                query = KustoCode.Parse(args);
            }
            var diagnostics = query.GetSyntaxDiagnostics()
                              .Select(d => $"({d.Start}..{d.Start + d.Length}): {d.Message}");

            if (diagnostics.Any())
            {
                var errors = string.Join("\n", diagnostics);
                throw new QueryParsingException($"Error parsing expression {args}: {errors}");
            }

            var syntax = query.Syntax.GetDescendants <Statement>()[0];

            Expression = syntax.Visit(new ScalarValueConverter()) as ScalarFunction;
        }