Creates an AVG(expr) function expression that returns the average of all the number values
in the group of the values expressed by the given expression.

@param expression The expression.
@return The AVG(expr) function.
506059
@NonNull
    public static Expression avg(@NonNull Expression expression) {
        if (expression == null) {
            throw new IllegalArgumentException("expression cannot be null.");
        }
        return new Expression.FunctionExpression("AVG()", Arrays.asList(expression));
    }
1158125
private Object getAggregatedResult(InternalAggregations internalAggs, String identifier, Expression exp)
    {
        switch (identifier)
        {
        case Expression.MIN:
            return (((InternalMin) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.MAX:
            return (((InternalMax) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.AVG:
            return (((InternalAvg) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.SUM:
            return (((InternalSum) internalAggs.get(exp.toParsedText())).getValue());

        case Expression.COUNT:
            return (((InternalValueCount) internalAggs.get(exp.toParsedText())).getValue());
        }

        throw new KunderaException("No support for " + identifier + " aggregation.");
    }
1365076
public static String normalize(Object expression) {
        if (expression == null) {
            return null;
        }

        // If it's a number it's not an expression
        if (expression instanceof Number){
            return String.valueOf(expression);
        }

        String replacement;
        String conditionStr = StringUtils.mergeToSingleUnderscore(String.valueOf(expression));
        Matcher matcher = PATTERN.matcher(conditionStr);
        StringBuffer result = new StringBuffer(conditionStr.length());
        while (matcher.find()) {
            if (OPERATORS.containsKey(matcher.group())) {
                replacement = (String) OPERATORS.get(matcher.group());
            } else if (PREDEFINED_VARS.containsKey(matcher.group())) {
                replacement = (String) PREDEFINED_VARS.get(matcher.group());
            } else {
                replacement = matcher.group();
            }
            matcher.appendReplacement(result, replacement);
        }
        matcher.appendTail(result);
        return result.toString();
    }
1099677
public static double avg(Array array) throws ExpressionException {
	if (array.size() == 0) return 0;
	return sum(array) / array.size();
    }
6858
final Expression then(final Expression expression) {
    return new Expression(expression.resultType(), expression.features()) {
      @Override
      protected void doGen(CodeBuilder adapter) {
        Statement.this.gen(adapter);
        expression.gen(adapter);
      }
    };
  }
931126
public <V> ResultTransformer<List<V>> list(Expression<V> expression) {
        final Expression<V> lookup = getLookup(expression);
        return new GroupByList<K, V>(key, expression) {
            @Override
            protected V transform(Group group) {
                return group.getOne(lookup);
            }
        };
    }
131776
@NonNull
    @Override
    public GroupBy groupBy(@NonNull Expression... expressions) {
        if (expressions == null) {
            throw new IllegalArgumentException("expressions cannot be null.");
        }
        return new GroupBy(this, Arrays.asList(expressions));
    }
1092369
@NonNull
    public static SortOrder expression(@NonNull Expression expression) {
        if (expression == null) {
            throw new IllegalArgumentException("expression cannot be null.");
        }
        return new SortOrder(expression);
    }
33685
@NonNull
    public Expression in(@NonNull Expression... expressions) {
        if (expressions == null) {
            throw new IllegalArgumentException("expressions cannot be null.");
        }
        final Expression aggr = new AggregateExpression(Arrays.asList(expressions));
        return new BinaryExpression(this, aggr, BinaryExpression.OpType.In);
    }
618817
public static Expression numericConversion(final Expression expr, final Type to) {
    if (to.equals(expr.resultType())) {
      return expr;
    }
    if (!isNumericPrimitive(to) || !isNumericPrimitive(expr.resultType())) {
      throw new IllegalArgumentException("Cannot convert from " + expr.resultType() + " to " + to);
    }
    return new Expression(to, expr.features()) {
      @Override
      protected void doGen(CodeBuilder adapter) {
        expr.gen(adapter);
        adapter.cast(expr.resultType(), to);
      }
    };
  }
1133966
function groupBy(expression) {

        //Check arguments
        if (!expression)
            throw new Error("Expression is invalid");

        //Define output maps
        var maps = [];

        //For each element on array
        for (var i = 0; i < this.items.length; i++) {

            //Get group key of current element
            var groupKey = expression(this.items[i]);

            //Check if another element with the same key is on maps
            var existingMap = null;

            //For each existing element on maps
            for (var n = 0; n < maps.length; n++) {
			
                //If we have element with the same key
				if (equals(maps[n].key, groupKey)){

                    //Set on external variable and break
                    existingMap = maps[n];
                    break;
                }
            }

            //If not existing elements were found, create
            if (!existingMap) {

                //Create with base values
                existingMap = {
                    key: groupKey,
                    count: 0, 
					elements: []
                };

                //Add element to map array
                maps.push(existingMap);
            }

            //Increment the counter
            existingMap.count++;
			
			//Push current element to "elements" property
			existingMap.elements.push(this.items[i]);
        }

        //Return for chaining
        return new jslinq(maps);
    }
95065
public static boolean containsAggregateExpression(AbstractExpression expr) {
        AbstractExpression.SubexprFinderPredicate pred =
                new AbstractExpression.SubexprFinderPredicate() {
            @Override
            public boolean matches(AbstractExpression expr) {
                return expr.getExpressionType().isAggregateExpression();
            }
        };
        return expr.hasAnySubexpressionWithPredicate(pred);
    }
1151185
public static <E extends Comparable<? super E>> AbstractGroupExpression<E, E> min(Expression<E> expression) {
        return new GMin<E>(expression);
    }
1309438
protected Expression visitExpression(Expression expr) {
        if (expr == null) {
            return null;
        }

        Expression newExpr = (Expression)expr.accept(this);
        if (expr != newExpr) {
            Type newType = newExpr.getType();

            if (newType == null || !newType.equals(expr.getType())) {
                Iterator<Expression.Conversion> it =
                    expr.getConversionChain().iterator();
                while (it.hasNext()) {
                    Expression.Conversion conv = it.next();
                    newExpr.convertTo
                        (conv.getToType(), conv.isCastPreferred());
                }
            }
        }
        return newExpr;
    }
1278699
@Nonnull
  public static Value evalExpression(@Nonnull final String expression, @Nonnull final PreprocessorContext context) {
    try {
      final ExpressionTree tree = ExpressionParser.getInstance().parse(expression, context);
      return evalTree(tree, context);
    } catch (IOException unexpected) {
      throw context.makeException("[Expression]Wrong expression format detected [" + expression + ']', unexpected);
    }
  }
57847
public static <T extends Number> WindowOver<T> avg(Expression<T> expr) {
        return new WindowOver<T>(expr.getType(), Ops.AggOps.AVG_AGG, expr);
    }
1185705
public final CALC expression(String expression) throws ParseException {
        detectImplmentedExtension();
        
        if (infixParser == null)
            infixParser = new InfixParser();
        
        CList infix = infixParser.parse(useExtensions, getProperties(), expression);
        expression(infix, false);
        return getThis();
    }