/// <summary> /// Creates an all expression with argument /// </summary> /// <param name="arg">argument expression for the expression created</param> /// <param name="returnType">runtime type</param> /// <param name="selected">type of the all expression to be created</param> /// <returns>an expression representing an ALL or an ALLSELECTED DAX function</returns> private Expression GetAllExpression(Expression arg, Type returnType, AllType selected) { if (arg.NodeType == ExpressionType.Parameter) { if (selected == AllType.AllSelected) { return(new AllSelectedExpression(returnType, arg)); } return(new AllExpression(returnType, arg)); } if (arg.NodeType == ExpressionType.MemberAccess) { var m = (MemberExpression)arg; var te = TableFactory.GetTableExpression(m) as TableExpression; if (te != null && (selected == AllType.AllSelected)) { return(new AllSelectedExpression(returnType, te)); } if (te != null) { return(new AllExpression(returnType, te)); } } Expression argument = _binder.Visit(arg); if (selected == AllType.AllSelected) { return(new AllSelectedExpression(returnType, argument)); } return(new AllExpression(returnType, argument)); }
/// <summary> /// Creates a measure expression /// </summary> /// <param name="node">method call node</param> /// <returns>a measure expression corresponding to the node</returns> internal Expression CreateMeasureExpression(MethodCallExpression node) { _measureCounter++; Expression c = _binder.Visit(node.Arguments[0]); Type t = node.Method.ReturnType; if (c is GroupingProjection) { GroupingProjection grp = ((GroupingProjection)c); c = grp.SubQueryProjectionExpression.Projector; t = grp.SubQueryProjectionExpression.Projector.Type; } if (c is ProjectionExpression) { c = ((ProjectionExpression)c).Projector; } var col = c as ColumnExpression; if (col != null) { var table = col.TableName; // TODO: Add a level of indirection here as well see XAggregations string dbname = node.Method.Name.ToUpper() + "(" + col.DbName + ")"; string name = string.Format("[{0}Of{1}{2}]", node.Method.Name, col.Name, _measureCounter); if (node.Arguments.Count() == 1) { return(new MeasureExpression( t, //node.Method.ReturnType, name, dbname, name, table)); } Expression filter; switch (node.Arguments[1].NodeType) { case ExpressionType.Parameter: filter = TableFactory.GetTableExpression(node.Arguments[1]); break; default: filter = _binder.Visit(node.Arguments[1]); break; } return(new MeasureExpression(t, (ExpressionType)DaxExpressionType.Measure, name, dbname, name, table, filter)); } throw new TabularException("could not create measure: the column reference was not found"); }