Ejemplo n.º 1
0
 public static bool IsDonutAggregateFunction(this IExpression expr)
 {
     if (expr is CallExpression callExpr)
     {
         var df = new DonutFunctions();
         return(df.IsAggregate(callExpr));
     }
     return(false);
 }
 public AggregateFeatureGeneratingExpressionVisitor(IDonutScript script) : base()
 {
     Variables        = new Dictionary <NameExpression, string>();
     Aggregates       = new Queue <IDonutFunction>();
     FeatureFunctions = new Queue <IDonutFunction>();
     _functionDict    = new DonutFunctions();
     _script          = script;
     _aggTree         = new AggregateJobTree(_script);
 }
Ejemplo n.º 3
0
        public static bool IsDonutNativeFeature(this AssignmentExpression fExpr)
        {
            var fExpression = fExpr.Value;

            if (fExpression is CallExpression callExpr)
            {
                var df = new DonutFunctions();
                if (df.IsAggregate(callExpr))
                {
                    return(false);
                }
                var fnType = df.GetFunctionType(callExpr);
                return(fnType == DonutFunctionType.Donut);
            }
            return(false);
        }
Ejemplo n.º 4
0
        private string GetFeatureYieldsContent(DonutScript script)
        {
            var fBuilder        = new StringBuilder();
            var donutFnResolver = new DonutFunctions();

            foreach (var feature in script.Features)
            {
                IExpression accessor       = feature.Value;
                string      fName          = feature.Member.ToString();
                string      featureContent = "";
                var         featureFType   = accessor.GetType();
                if (featureFType == typeof(NameExpression))
                {
                    var member = (accessor as NameExpression).Member?.ToString();
                    //In some cases we might just use the field
                    if (string.IsNullOrEmpty(member))
                    {
                        member = accessor.ToString();
                    }
                    featureContent = $"yield return pair(\"{fName}\", doc[\"{member}\"]);";
                }
                else if (featureFType == typeof(CallExpression))
                {
                    if (donutFnResolver.IsAggregate(accessor as CallExpression))
                    {
                        //We're dealing with an aggregate call
                        //var aggregateContent = GenerateFeatureFunctionCall(accessor as CallExpression, feature);
                    }
                    else
                    {
                        //We're dealing with a function call
                        //featureContent = GenerateFeatureFunctionCall(accessor as CallExpression, feature).Content;
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                if (!string.IsNullOrEmpty(featureContent))
                {
                    fBuilder.AppendLine(featureContent);
                }
            }
            return(fBuilder.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="callExpression"></param>
        /// <param name="feature"></param>
        /// <returns></returns>
        public FeatureFunctionsCodeResult GenerateFeatureFunctionCall(CallExpression callExpression, AssignmentExpression feature = null)
        {
            var fnDict       = new DonutFunctions();
            var isAggregate  = fnDict.IsAggregate(callExpression);
            var functionType = fnDict.GetFunctionType(callExpression);

            Clean();
            _expVisitor.Clear();
            var strValues = VisitCall(callExpression, null, _expVisitor);

            if (string.IsNullOrEmpty(strValues))
            {
                return(null);
            }
            if (isAggregate)
            {
                var aggregateField = new BsonDocument();
                if (feature == null)
                {
                    try
                    {
                        aggregateField = BsonDocument.Parse(strValues);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine($"Failed to parse expression: {callExpression}\nError: {ex.Message}");
                        return(null);
                    }
                }
                else
                {
                    aggregateField[feature.Member.ToString()] = BsonDocument.Parse(strValues);
                }
                var result = new FeatureFunctionsCodeResult(functionType, aggregateField.ToString());
                return(result);
            }
            else
            {
                return(new FeatureFunctionsCodeResult(strValues));
            }
        }
Ejemplo n.º 6
0
 public DonutFeatureCodeGenerator(DonutScript script, DonutFeatureGeneratingExpressionVisitor expVisitor) : base(script)
 {
     _donutFnResolver = new DonutFunctions();
     _rootIntegration = script.Integrations.FirstOrDefault();
     if (_rootIntegration == null)
     {
         throw new InvalidIntegrationException("Script has no integrations");
     }
     if (_rootIntegration.Fields == null || _rootIntegration.Fields.Count == 0)
     {
         throw new InvalidIntegrationException("Integration has no fields");
     }
     _rootDataMember   = script.GetDatasetMember(_rootIntegration.Name);
     _outputCollection = _rootIntegration.FeaturesCollection;
     if (string.IsNullOrEmpty(_outputCollection))
     {
         throw new InvalidOperationException("Root integration must have a features collection set.");
     }
     _expVisitor = expVisitor ?? throw new ArgumentNullException(nameof(expVisitor));
     _functions  = new List <IDonutFunction>();
 }
 public DonutFeatureGeneratingExpressionVisitor(IDonutScript ds)
 {
     _script          = ds;
     FeatureFunctions = new Queue <IDonutFunction>();
     _functionDict    = new DonutFunctions();
 }