@Test public void testPostAggregationFunction() { PostAggregationFunction function = new PostAggregationFunction("plus", new ColumnDataType[]{ColumnDataType.INT, ColumnDataType.LONG}); assertEquals(function.getResultType(), ColumnDataType.DOUBLE); assertEquals(function.invoke(new Object[]{1, 2L}), 3.0); function = new PostAggregationFunction("MINUS", new ColumnDataType[]{ColumnDataType.FLOAT, ColumnDataType.DOUBLE}); assertEquals(function.getResultType(), ColumnDataType.DOUBLE); assertEquals(function.invoke(new Object[]{3f, 4.0}), -1.0); function = new PostAggregationFunction("tImEs", new ColumnDataType[]{ColumnDataType.STRING, ColumnDataType.INT}); assertEquals(function.getResultType(), ColumnDataType.DOUBLE); assertEquals(function.invoke(new Object[]{"5", 6}), 30.0); function = new PostAggregationFunction("reverse", new ColumnDataType[]{ColumnDataType.LONG}); assertEquals(function.getResultType(), ColumnDataType.STRING); assertEquals(function.invoke(new Object[]{"1234567890"}), "0987654321"); function = new PostAggregationFunction("ST_AsText", new ColumnDataType[]{ColumnDataType.BYTES}); assertEquals(function.getResultType(), ColumnDataType.STRING); assertEquals(function.invoke( new Object[]{GeometrySerializer.serialize(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(10, 20)))}), "POINT (10 20)"); }
public PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes) { int numArguments = argumentTypes.length; FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); Preconditions .checkArgument(functionInfo != null, "Unsupported function: %s with %s parameters", functionName, numArguments); _functionInvoker = new FunctionInvoker(functionInfo); PinotDataType[] parameterTypes = _functionInvoker.getParameterTypes(); Preconditions.checkArgument(numArguments == parameterTypes.length, "Wrong number of arguments for method: %s, expected: %s, actual: %s", functionInfo.getMethod(), parameterTypes.length, numArguments); _argumentTypes = new PinotDataType[numArguments]; for (int i = 0; i < numArguments; i++) { _argumentTypes[i] = PinotDataType.getPinotDataType(argumentTypes[i]); } ColumnDataType resultType = FunctionUtils.getColumnDataType(_functionInvoker.getResultClass()); _resultType = resultType != null ? resultType : ColumnDataType.STRING; }
PostAggregationFunction { public PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes) { int numArguments = argumentTypes.length; FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); Preconditions .checkArgument(functionInfo != null, "Unsupported function: %s with %s parameters", functionName, numArguments); _functionInvoker = new FunctionInvoker(functionInfo); PinotDataType[] parameterTypes = _functionInvoker.getParameterTypes(); Preconditions.checkArgument(numArguments == parameterTypes.length, "Wrong number of arguments for method: %s, expected: %s, actual: %s", functionInfo.getMethod(), parameterTypes.length, numArguments); _argumentTypes = new PinotDataType[numArguments]; for (int i = 0; i < numArguments; i++) { _argumentTypes[i] = PinotDataType.getPinotDataType(argumentTypes[i]); } ColumnDataType resultType = FunctionUtils.getColumnDataType(_functionInvoker.getResultClass()); _resultType = resultType != null ? resultType : ColumnDataType.STRING; } }
PostAggregationFunction { public PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes) { int numArguments = argumentTypes.length; FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); Preconditions .checkArgument(functionInfo != null, "Unsupported function: %s with %s parameters", functionName, numArguments); _functionInvoker = new FunctionInvoker(functionInfo); PinotDataType[] parameterTypes = _functionInvoker.getParameterTypes(); Preconditions.checkArgument(numArguments == parameterTypes.length, "Wrong number of arguments for method: %s, expected: %s, actual: %s", functionInfo.getMethod(), parameterTypes.length, numArguments); _argumentTypes = new PinotDataType[numArguments]; for (int i = 0; i < numArguments; i++) { _argumentTypes[i] = PinotDataType.getPinotDataType(argumentTypes[i]); } ColumnDataType resultType = FunctionUtils.getColumnDataType(_functionInvoker.getResultClass()); _resultType = resultType != null ? resultType : ColumnDataType.STRING; } PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes); }
PostAggregationFunction { public PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes) { int numArguments = argumentTypes.length; FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); Preconditions .checkArgument(functionInfo != null, "Unsupported function: %s with %s parameters", functionName, numArguments); _functionInvoker = new FunctionInvoker(functionInfo); PinotDataType[] parameterTypes = _functionInvoker.getParameterTypes(); Preconditions.checkArgument(numArguments == parameterTypes.length, "Wrong number of arguments for method: %s, expected: %s, actual: %s", functionInfo.getMethod(), parameterTypes.length, numArguments); _argumentTypes = new PinotDataType[numArguments]; for (int i = 0; i < numArguments; i++) { _argumentTypes[i] = PinotDataType.getPinotDataType(argumentTypes[i]); } ColumnDataType resultType = FunctionUtils.getColumnDataType(_functionInvoker.getResultClass()); _resultType = resultType != null ? resultType : ColumnDataType.STRING; } PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes); ColumnDataType getResultType(); Object invoke(Object[] arguments); }
PostAggregationFunction { public PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes) { int numArguments = argumentTypes.length; FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); Preconditions .checkArgument(functionInfo != null, "Unsupported function: %s with %s parameters", functionName, numArguments); _functionInvoker = new FunctionInvoker(functionInfo); PinotDataType[] parameterTypes = _functionInvoker.getParameterTypes(); Preconditions.checkArgument(numArguments == parameterTypes.length, "Wrong number of arguments for method: %s, expected: %s, actual: %s", functionInfo.getMethod(), parameterTypes.length, numArguments); _argumentTypes = new PinotDataType[numArguments]; for (int i = 0; i < numArguments; i++) { _argumentTypes[i] = PinotDataType.getPinotDataType(argumentTypes[i]); } ColumnDataType resultType = FunctionUtils.getColumnDataType(_functionInvoker.getResultClass()); _resultType = resultType != null ? resultType : ColumnDataType.STRING; } PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes); ColumnDataType getResultType(); Object invoke(Object[] arguments);  }