@Test public void testAggregationFunctionWithMultipleArgs() { QueryContext queryContext = QueryContextConverterUtils.getQueryContextFromPQL("SELECT distinct(column1, column2, column3) FROM testTable"); AggregationFunction aggregationFunction = AggregationFunctionFactory .getAggregationFunction(queryContext.getSelectExpressions().get(0).getFunction(), queryContext); assertTrue(aggregationFunction instanceof DistinctAggregationFunction); assertEquals(aggregationFunction.getType(), AggregationFunctionType.DISTINCT); assertEquals(aggregationFunction.getColumnName(), "distinct_column1:column2:column3"); assertEquals(aggregationFunction.getResultColumnName(), "distinct(column1:column2:column3)"); }
public static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext) { try { String upperCaseFunctionName = StringUtils.remove(function.getFunctionName(), '_').toUpperCase(); List<ExpressionContext> arguments = function.getArguments(); ExpressionContext firstArgument = arguments.get(0); if (upperCaseFunctionName.startsWith("PERCENTILE")) { String remainingFunctionName = upperCaseFunctionName.substring(10); int numArguments = arguments.size(); if (numArguments == 1) { if (remainingFunctionName.matches("\\d+")) { return new PercentileAggregationFunction(firstArgument, parsePercentile(remainingFunctionName)); } else if (remainingFunctionName.matches("EST\\d+")) { String percentileString = remainingFunctionName.substring(3); return new PercentileEstAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+")) { String percentileString = remainingFunctionName.substring(7); return new PercentileTDigestAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("\\d+MV")) { String percentileString = remainingFunctionName.substring(0, remainingFunctionName.length() - 2); return new PercentileMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("EST\\d+MV")) { String percentileString = remainingFunctionName.substring(3, remainingFunctionName.length() - 2); return new PercentileEstMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+MV")) { String percentileString = remainingFunctionName.substring(7, remainingFunctionName.length() - 2); return new PercentileTDigestMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } } else if (numArguments == 2) { int percentile = parsePercentile(arguments.get(1).getLiteral()); if (remainingFunctionName.isEmpty()) { return new PercentileAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("EST")) { return new PercentileEstAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGEST")) { return new PercentileTDigestAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("MV")) { return new PercentileMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("ESTMV")) { return new PercentileEstMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGESTMV")) { return new PercentileTDigestMVAggregationFunction(firstArgument, percentile); } } throw new IllegalArgumentException("Invalid percentile function: " + function); } else { switch (AggregationFunctionType.valueOf(upperCaseFunctionName)) { case COUNT: return new CountAggregationFunction(); case MIN: return new MinAggregationFunction(firstArgument); case MAX: return new MaxAggregationFunction(firstArgument); case SUM: return new SumAggregationFunction(firstArgument); case SUMPRECISION: return new SumPrecisionAggregationFunction(arguments); case AVG: return new AvgAggregationFunction(firstArgument); case MINMAXRANGE: return new MinMaxRangeAggregationFunction(firstArgument); case DISTINCTCOUNT: return new DistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAP: return new DistinctCountBitmapAggregationFunction(firstArgument); case SEGMENTPARTITIONEDDISTINCTCOUNT: return new SegmentPartitionedDistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTHLL: return new DistinctCountHLLAggregationFunction(arguments); case DISTINCTCOUNTRAWHLL: return new DistinctCountRawHLLAggregationFunction(arguments); case FASTHLL: return new FastHLLAggregationFunction(firstArgument); case DISTINCTCOUNTTHETASKETCH: return new DistinctCountThetaSketchAggregationFunction(arguments); case DISTINCTCOUNTRAWTHETASKETCH: return new DistinctCountRawThetaSketchAggregationFunction(arguments); case IDSET: return new IdSetAggregationFunction(arguments); case COUNTMV: return new CountMVAggregationFunction(firstArgument); case MINMV: return new MinMVAggregationFunction(firstArgument); case MAXMV: return new MaxMVAggregationFunction(firstArgument); case SUMMV: return new SumMVAggregationFunction(firstArgument); case AVGMV: return new AvgMVAggregationFunction(firstArgument); case MINMAXRANGEMV: return new MinMaxRangeMVAggregationFunction(firstArgument); case DISTINCTCOUNTMV: return new DistinctCountMVAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAPMV: return new DistinctCountBitmapMVAggregationFunction(firstArgument); case DISTINCTCOUNTHLLMV: return new DistinctCountHLLMVAggregationFunction(arguments); case DISTINCTCOUNTRAWHLLMV: return new DistinctCountRawHLLMVAggregationFunction(arguments); case DISTINCT: return new DistinctAggregationFunction(arguments, queryContext.getOrderByExpressions(), queryContext.getLimit()); case STUNION: return new StUnionAggregationFunction(firstArgument); default: throw new IllegalArgumentException(); } } } catch (Exception e) { throw new BadQueryRequestException("Invalid aggregation function: " + function); } }
AggregationFunctionFactory { public static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext) { try { String upperCaseFunctionName = StringUtils.remove(function.getFunctionName(), '_').toUpperCase(); List<ExpressionContext> arguments = function.getArguments(); ExpressionContext firstArgument = arguments.get(0); if (upperCaseFunctionName.startsWith("PERCENTILE")) { String remainingFunctionName = upperCaseFunctionName.substring(10); int numArguments = arguments.size(); if (numArguments == 1) { if (remainingFunctionName.matches("\\d+")) { return new PercentileAggregationFunction(firstArgument, parsePercentile(remainingFunctionName)); } else if (remainingFunctionName.matches("EST\\d+")) { String percentileString = remainingFunctionName.substring(3); return new PercentileEstAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+")) { String percentileString = remainingFunctionName.substring(7); return new PercentileTDigestAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("\\d+MV")) { String percentileString = remainingFunctionName.substring(0, remainingFunctionName.length() - 2); return new PercentileMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("EST\\d+MV")) { String percentileString = remainingFunctionName.substring(3, remainingFunctionName.length() - 2); return new PercentileEstMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+MV")) { String percentileString = remainingFunctionName.substring(7, remainingFunctionName.length() - 2); return new PercentileTDigestMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } } else if (numArguments == 2) { int percentile = parsePercentile(arguments.get(1).getLiteral()); if (remainingFunctionName.isEmpty()) { return new PercentileAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("EST")) { return new PercentileEstAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGEST")) { return new PercentileTDigestAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("MV")) { return new PercentileMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("ESTMV")) { return new PercentileEstMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGESTMV")) { return new PercentileTDigestMVAggregationFunction(firstArgument, percentile); } } throw new IllegalArgumentException("Invalid percentile function: " + function); } else { switch (AggregationFunctionType.valueOf(upperCaseFunctionName)) { case COUNT: return new CountAggregationFunction(); case MIN: return new MinAggregationFunction(firstArgument); case MAX: return new MaxAggregationFunction(firstArgument); case SUM: return new SumAggregationFunction(firstArgument); case SUMPRECISION: return new SumPrecisionAggregationFunction(arguments); case AVG: return new AvgAggregationFunction(firstArgument); case MINMAXRANGE: return new MinMaxRangeAggregationFunction(firstArgument); case DISTINCTCOUNT: return new DistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAP: return new DistinctCountBitmapAggregationFunction(firstArgument); case SEGMENTPARTITIONEDDISTINCTCOUNT: return new SegmentPartitionedDistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTHLL: return new DistinctCountHLLAggregationFunction(arguments); case DISTINCTCOUNTRAWHLL: return new DistinctCountRawHLLAggregationFunction(arguments); case FASTHLL: return new FastHLLAggregationFunction(firstArgument); case DISTINCTCOUNTTHETASKETCH: return new DistinctCountThetaSketchAggregationFunction(arguments); case DISTINCTCOUNTRAWTHETASKETCH: return new DistinctCountRawThetaSketchAggregationFunction(arguments); case IDSET: return new IdSetAggregationFunction(arguments); case COUNTMV: return new CountMVAggregationFunction(firstArgument); case MINMV: return new MinMVAggregationFunction(firstArgument); case MAXMV: return new MaxMVAggregationFunction(firstArgument); case SUMMV: return new SumMVAggregationFunction(firstArgument); case AVGMV: return new AvgMVAggregationFunction(firstArgument); case MINMAXRANGEMV: return new MinMaxRangeMVAggregationFunction(firstArgument); case DISTINCTCOUNTMV: return new DistinctCountMVAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAPMV: return new DistinctCountBitmapMVAggregationFunction(firstArgument); case DISTINCTCOUNTHLLMV: return new DistinctCountHLLMVAggregationFunction(arguments); case DISTINCTCOUNTRAWHLLMV: return new DistinctCountRawHLLMVAggregationFunction(arguments); case DISTINCT: return new DistinctAggregationFunction(arguments, queryContext.getOrderByExpressions(), queryContext.getLimit()); case STUNION: return new StUnionAggregationFunction(firstArgument); default: throw new IllegalArgumentException(); } } } catch (Exception e) { throw new BadQueryRequestException("Invalid aggregation function: " + function); } } }
AggregationFunctionFactory { public static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext) { try { String upperCaseFunctionName = StringUtils.remove(function.getFunctionName(), '_').toUpperCase(); List<ExpressionContext> arguments = function.getArguments(); ExpressionContext firstArgument = arguments.get(0); if (upperCaseFunctionName.startsWith("PERCENTILE")) { String remainingFunctionName = upperCaseFunctionName.substring(10); int numArguments = arguments.size(); if (numArguments == 1) { if (remainingFunctionName.matches("\\d+")) { return new PercentileAggregationFunction(firstArgument, parsePercentile(remainingFunctionName)); } else if (remainingFunctionName.matches("EST\\d+")) { String percentileString = remainingFunctionName.substring(3); return new PercentileEstAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+")) { String percentileString = remainingFunctionName.substring(7); return new PercentileTDigestAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("\\d+MV")) { String percentileString = remainingFunctionName.substring(0, remainingFunctionName.length() - 2); return new PercentileMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("EST\\d+MV")) { String percentileString = remainingFunctionName.substring(3, remainingFunctionName.length() - 2); return new PercentileEstMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+MV")) { String percentileString = remainingFunctionName.substring(7, remainingFunctionName.length() - 2); return new PercentileTDigestMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } } else if (numArguments == 2) { int percentile = parsePercentile(arguments.get(1).getLiteral()); if (remainingFunctionName.isEmpty()) { return new PercentileAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("EST")) { return new PercentileEstAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGEST")) { return new PercentileTDigestAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("MV")) { return new PercentileMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("ESTMV")) { return new PercentileEstMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGESTMV")) { return new PercentileTDigestMVAggregationFunction(firstArgument, percentile); } } throw new IllegalArgumentException("Invalid percentile function: " + function); } else { switch (AggregationFunctionType.valueOf(upperCaseFunctionName)) { case COUNT: return new CountAggregationFunction(); case MIN: return new MinAggregationFunction(firstArgument); case MAX: return new MaxAggregationFunction(firstArgument); case SUM: return new SumAggregationFunction(firstArgument); case SUMPRECISION: return new SumPrecisionAggregationFunction(arguments); case AVG: return new AvgAggregationFunction(firstArgument); case MINMAXRANGE: return new MinMaxRangeAggregationFunction(firstArgument); case DISTINCTCOUNT: return new DistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAP: return new DistinctCountBitmapAggregationFunction(firstArgument); case SEGMENTPARTITIONEDDISTINCTCOUNT: return new SegmentPartitionedDistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTHLL: return new DistinctCountHLLAggregationFunction(arguments); case DISTINCTCOUNTRAWHLL: return new DistinctCountRawHLLAggregationFunction(arguments); case FASTHLL: return new FastHLLAggregationFunction(firstArgument); case DISTINCTCOUNTTHETASKETCH: return new DistinctCountThetaSketchAggregationFunction(arguments); case DISTINCTCOUNTRAWTHETASKETCH: return new DistinctCountRawThetaSketchAggregationFunction(arguments); case IDSET: return new IdSetAggregationFunction(arguments); case COUNTMV: return new CountMVAggregationFunction(firstArgument); case MINMV: return new MinMVAggregationFunction(firstArgument); case MAXMV: return new MaxMVAggregationFunction(firstArgument); case SUMMV: return new SumMVAggregationFunction(firstArgument); case AVGMV: return new AvgMVAggregationFunction(firstArgument); case MINMAXRANGEMV: return new MinMaxRangeMVAggregationFunction(firstArgument); case DISTINCTCOUNTMV: return new DistinctCountMVAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAPMV: return new DistinctCountBitmapMVAggregationFunction(firstArgument); case DISTINCTCOUNTHLLMV: return new DistinctCountHLLMVAggregationFunction(arguments); case DISTINCTCOUNTRAWHLLMV: return new DistinctCountRawHLLMVAggregationFunction(arguments); case DISTINCT: return new DistinctAggregationFunction(arguments, queryContext.getOrderByExpressions(), queryContext.getLimit()); case STUNION: return new StUnionAggregationFunction(firstArgument); default: throw new IllegalArgumentException(); } } } catch (Exception e) { throw new BadQueryRequestException("Invalid aggregation function: " + function); } } private  AggregationFunctionFactory(); }
AggregationFunctionFactory { public static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext) { try { String upperCaseFunctionName = StringUtils.remove(function.getFunctionName(), '_').toUpperCase(); List<ExpressionContext> arguments = function.getArguments(); ExpressionContext firstArgument = arguments.get(0); if (upperCaseFunctionName.startsWith("PERCENTILE")) { String remainingFunctionName = upperCaseFunctionName.substring(10); int numArguments = arguments.size(); if (numArguments == 1) { if (remainingFunctionName.matches("\\d+")) { return new PercentileAggregationFunction(firstArgument, parsePercentile(remainingFunctionName)); } else if (remainingFunctionName.matches("EST\\d+")) { String percentileString = remainingFunctionName.substring(3); return new PercentileEstAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+")) { String percentileString = remainingFunctionName.substring(7); return new PercentileTDigestAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("\\d+MV")) { String percentileString = remainingFunctionName.substring(0, remainingFunctionName.length() - 2); return new PercentileMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("EST\\d+MV")) { String percentileString = remainingFunctionName.substring(3, remainingFunctionName.length() - 2); return new PercentileEstMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+MV")) { String percentileString = remainingFunctionName.substring(7, remainingFunctionName.length() - 2); return new PercentileTDigestMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } } else if (numArguments == 2) { int percentile = parsePercentile(arguments.get(1).getLiteral()); if (remainingFunctionName.isEmpty()) { return new PercentileAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("EST")) { return new PercentileEstAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGEST")) { return new PercentileTDigestAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("MV")) { return new PercentileMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("ESTMV")) { return new PercentileEstMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGESTMV")) { return new PercentileTDigestMVAggregationFunction(firstArgument, percentile); } } throw new IllegalArgumentException("Invalid percentile function: " + function); } else { switch (AggregationFunctionType.valueOf(upperCaseFunctionName)) { case COUNT: return new CountAggregationFunction(); case MIN: return new MinAggregationFunction(firstArgument); case MAX: return new MaxAggregationFunction(firstArgument); case SUM: return new SumAggregationFunction(firstArgument); case SUMPRECISION: return new SumPrecisionAggregationFunction(arguments); case AVG: return new AvgAggregationFunction(firstArgument); case MINMAXRANGE: return new MinMaxRangeAggregationFunction(firstArgument); case DISTINCTCOUNT: return new DistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAP: return new DistinctCountBitmapAggregationFunction(firstArgument); case SEGMENTPARTITIONEDDISTINCTCOUNT: return new SegmentPartitionedDistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTHLL: return new DistinctCountHLLAggregationFunction(arguments); case DISTINCTCOUNTRAWHLL: return new DistinctCountRawHLLAggregationFunction(arguments); case FASTHLL: return new FastHLLAggregationFunction(firstArgument); case DISTINCTCOUNTTHETASKETCH: return new DistinctCountThetaSketchAggregationFunction(arguments); case DISTINCTCOUNTRAWTHETASKETCH: return new DistinctCountRawThetaSketchAggregationFunction(arguments); case IDSET: return new IdSetAggregationFunction(arguments); case COUNTMV: return new CountMVAggregationFunction(firstArgument); case MINMV: return new MinMVAggregationFunction(firstArgument); case MAXMV: return new MaxMVAggregationFunction(firstArgument); case SUMMV: return new SumMVAggregationFunction(firstArgument); case AVGMV: return new AvgMVAggregationFunction(firstArgument); case MINMAXRANGEMV: return new MinMaxRangeMVAggregationFunction(firstArgument); case DISTINCTCOUNTMV: return new DistinctCountMVAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAPMV: return new DistinctCountBitmapMVAggregationFunction(firstArgument); case DISTINCTCOUNTHLLMV: return new DistinctCountHLLMVAggregationFunction(arguments); case DISTINCTCOUNTRAWHLLMV: return new DistinctCountRawHLLMVAggregationFunction(arguments); case DISTINCT: return new DistinctAggregationFunction(arguments, queryContext.getOrderByExpressions(), queryContext.getLimit()); case STUNION: return new StUnionAggregationFunction(firstArgument); default: throw new IllegalArgumentException(); } } } catch (Exception e) { throw new BadQueryRequestException("Invalid aggregation function: " + function); } } private  AggregationFunctionFactory(); static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext); }
AggregationFunctionFactory { public static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext) { try { String upperCaseFunctionName = StringUtils.remove(function.getFunctionName(), '_').toUpperCase(); List<ExpressionContext> arguments = function.getArguments(); ExpressionContext firstArgument = arguments.get(0); if (upperCaseFunctionName.startsWith("PERCENTILE")) { String remainingFunctionName = upperCaseFunctionName.substring(10); int numArguments = arguments.size(); if (numArguments == 1) { if (remainingFunctionName.matches("\\d+")) { return new PercentileAggregationFunction(firstArgument, parsePercentile(remainingFunctionName)); } else if (remainingFunctionName.matches("EST\\d+")) { String percentileString = remainingFunctionName.substring(3); return new PercentileEstAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+")) { String percentileString = remainingFunctionName.substring(7); return new PercentileTDigestAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("\\d+MV")) { String percentileString = remainingFunctionName.substring(0, remainingFunctionName.length() - 2); return new PercentileMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("EST\\d+MV")) { String percentileString = remainingFunctionName.substring(3, remainingFunctionName.length() - 2); return new PercentileEstMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } else if (remainingFunctionName.matches("TDIGEST\\d+MV")) { String percentileString = remainingFunctionName.substring(7, remainingFunctionName.length() - 2); return new PercentileTDigestMVAggregationFunction(firstArgument, parsePercentile(percentileString)); } } else if (numArguments == 2) { int percentile = parsePercentile(arguments.get(1).getLiteral()); if (remainingFunctionName.isEmpty()) { return new PercentileAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("EST")) { return new PercentileEstAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGEST")) { return new PercentileTDigestAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("MV")) { return new PercentileMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("ESTMV")) { return new PercentileEstMVAggregationFunction(firstArgument, percentile); } if (remainingFunctionName.equals("TDIGESTMV")) { return new PercentileTDigestMVAggregationFunction(firstArgument, percentile); } } throw new IllegalArgumentException("Invalid percentile function: " + function); } else { switch (AggregationFunctionType.valueOf(upperCaseFunctionName)) { case COUNT: return new CountAggregationFunction(); case MIN: return new MinAggregationFunction(firstArgument); case MAX: return new MaxAggregationFunction(firstArgument); case SUM: return new SumAggregationFunction(firstArgument); case SUMPRECISION: return new SumPrecisionAggregationFunction(arguments); case AVG: return new AvgAggregationFunction(firstArgument); case MINMAXRANGE: return new MinMaxRangeAggregationFunction(firstArgument); case DISTINCTCOUNT: return new DistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAP: return new DistinctCountBitmapAggregationFunction(firstArgument); case SEGMENTPARTITIONEDDISTINCTCOUNT: return new SegmentPartitionedDistinctCountAggregationFunction(firstArgument); case DISTINCTCOUNTHLL: return new DistinctCountHLLAggregationFunction(arguments); case DISTINCTCOUNTRAWHLL: return new DistinctCountRawHLLAggregationFunction(arguments); case FASTHLL: return new FastHLLAggregationFunction(firstArgument); case DISTINCTCOUNTTHETASKETCH: return new DistinctCountThetaSketchAggregationFunction(arguments); case DISTINCTCOUNTRAWTHETASKETCH: return new DistinctCountRawThetaSketchAggregationFunction(arguments); case IDSET: return new IdSetAggregationFunction(arguments); case COUNTMV: return new CountMVAggregationFunction(firstArgument); case MINMV: return new MinMVAggregationFunction(firstArgument); case MAXMV: return new MaxMVAggregationFunction(firstArgument); case SUMMV: return new SumMVAggregationFunction(firstArgument); case AVGMV: return new AvgMVAggregationFunction(firstArgument); case MINMAXRANGEMV: return new MinMaxRangeMVAggregationFunction(firstArgument); case DISTINCTCOUNTMV: return new DistinctCountMVAggregationFunction(firstArgument); case DISTINCTCOUNTBITMAPMV: return new DistinctCountBitmapMVAggregationFunction(firstArgument); case DISTINCTCOUNTHLLMV: return new DistinctCountHLLMVAggregationFunction(arguments); case DISTINCTCOUNTRAWHLLMV: return new DistinctCountRawHLLMVAggregationFunction(arguments); case DISTINCT: return new DistinctAggregationFunction(arguments, queryContext.getOrderByExpressions(), queryContext.getLimit()); case STUNION: return new StUnionAggregationFunction(firstArgument); default: throw new IllegalArgumentException(); } } } catch (Exception e) { throw new BadQueryRequestException("Invalid aggregation function: " + function); } } private  AggregationFunctionFactory(); static AggregationFunction getAggregationFunction(FunctionContext function, QueryContext queryContext);  }