@Test public void testCreateAggregateFunctionValid() throws InstantiationException, IllegalAccessException, Exception { String[] parts = new String[] { "derivative,10,smean" }; MiscUtils.createFunctionChain(parts, 0); }
public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception { Function[] arguments = new Function[parts.length - startIndex]; for (int k = startIndex, p = 0; k < parts.length; k++, p++) { String[] args = parts[k].split(","); Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]); if (lookupFunction == null) { throw new BadRequestException("Unknown function:" + args[0]); } Function instance = (Function) lookupFunction.newInstance(); if (args.length - 1 < instance.getNumberOfArgs()) { throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1)); } Object[] ary = new Object[args.length - 1]; for (int i = 1; i < args.length; i++) { Matcher matcher = NUMBER.matcher(args[i]); if (matcher.matches()) { if (matcher.group(1) != null) { ary[i - 1] = Double.parseDouble(args[i]); } else { ary[i - 1] = Integer.parseInt(args[i]); } } else { ary[i - 1] = args[i]; } } instance.init(ary); arguments[p] = instance; } ChainFunction function = new ChainFunction(); function.init(arguments); return function; }
MiscUtils { public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception { Function[] arguments = new Function[parts.length - startIndex]; for (int k = startIndex, p = 0; k < parts.length; k++, p++) { String[] args = parts[k].split(","); Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]); if (lookupFunction == null) { throw new BadRequestException("Unknown function:" + args[0]); } Function instance = (Function) lookupFunction.newInstance(); if (args.length - 1 < instance.getNumberOfArgs()) { throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1)); } Object[] ary = new Object[args.length - 1]; for (int i = 1; i < args.length; i++) { Matcher matcher = NUMBER.matcher(args[i]); if (matcher.matches()) { if (matcher.group(1) != null) { ary[i - 1] = Double.parseDouble(args[i]); } else { ary[i - 1] = Integer.parseInt(args[i]); } } else { ary[i - 1] = args[i]; } } instance.init(ary); arguments[p] = instance; } ChainFunction function = new ChainFunction(); function.init(arguments); return function; } }
MiscUtils { public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception { Function[] arguments = new Function[parts.length - startIndex]; for (int k = startIndex, p = 0; k < parts.length; k++, p++) { String[] args = parts[k].split(","); Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]); if (lookupFunction == null) { throw new BadRequestException("Unknown function:" + args[0]); } Function instance = (Function) lookupFunction.newInstance(); if (args.length - 1 < instance.getNumberOfArgs()) { throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1)); } Object[] ary = new Object[args.length - 1]; for (int i = 1; i < args.length; i++) { Matcher matcher = NUMBER.matcher(args[i]); if (matcher.matches()) { if (matcher.group(1) != null) { ary[i - 1] = Double.parseDouble(args[i]); } else { ary[i - 1] = Integer.parseInt(args[i]); } } else { ary[i - 1] = args[i]; } } instance.init(ary); arguments[p] = instance; } ChainFunction function = new ChainFunction(); function.init(arguments); return function; } private  MiscUtils(); }
MiscUtils { public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception { Function[] arguments = new Function[parts.length - startIndex]; for (int k = startIndex, p = 0; k < parts.length; k++, p++) { String[] args = parts[k].split(","); Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]); if (lookupFunction == null) { throw new BadRequestException("Unknown function:" + args[0]); } Function instance = (Function) lookupFunction.newInstance(); if (args.length - 1 < instance.getNumberOfArgs()) { throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1)); } Object[] ary = new Object[args.length - 1]; for (int i = 1; i < args.length; i++) { Matcher matcher = NUMBER.matcher(args[i]); if (matcher.matches()) { if (matcher.group(1) != null) { ary[i - 1] = Double.parseDouble(args[i]); } else { ary[i - 1] = Integer.parseInt(args[i]); } } else { ary[i - 1] = args[i]; } } instance.init(ary); arguments[p] = instance; } ChainFunction function = new ChainFunction(); function.init(arguments); return function; } private  MiscUtils(); static long bucketCounter(Series series); static String[] splitAndNormalizeString(String input); static List<String> readAllLines(File file); static DataPoint buildDataPoint(long timestamp, long value); static DataPoint buildDataPoint(long timestamp, double value); static void ls(File file); static boolean delete(File file); static String tagsToString(List<Tag> tags); static String tagToString(List<String> tags); static TagFilter buildTagFilter(String tagFilter); static SimpleTagFilter buildSimpleFilter(String item); static FunctionIteratorFactory createIteratorChain(String[] parts, int startIndex); static Function createFunctionChain(String[] parts, int startIndex); static TargetSeries extractTargetFromQuery(String query); static Point buildDP(String dbName, String measurementName, List<String> valueFieldName, List<Tag> tags,
			long timestamp, List<Long> value, List<Boolean> fp); static String printBuffer(ByteBuffer buffer, int counter); static void writeStringToBuffer(String str, ByteBuffer buf); static void writeByteStringToBuffer(byte[] str, ByteBuffer buf); static ByteString getByteStringFromBuffer(ByteBuffer buf); static String getStringFromBuffer(ByteBuffer buf); static Point buildDataPoint(String dbName, String measurementName, List<String> valueFieldName,
			List<Tag> taglist, long timestamp, List<Long> values, List<Boolean> fp); static Point buildDataPoint(String dbName, String measurementName, String valueFieldName, List<Tag> taglist,
			long timestamp, long value); static Point buildDataPoint(String dbName, String measurementName, String valueFieldName, List<Tag> taglist,
			long timestamp, double value); static int tagHashCode(List<Tag> tags); }
MiscUtils { public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception { Function[] arguments = new Function[parts.length - startIndex]; for (int k = startIndex, p = 0; k < parts.length; k++, p++) { String[] args = parts[k].split(","); Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]); if (lookupFunction == null) { throw new BadRequestException("Unknown function:" + args[0]); } Function instance = (Function) lookupFunction.newInstance(); if (args.length - 1 < instance.getNumberOfArgs()) { throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1)); } Object[] ary = new Object[args.length - 1]; for (int i = 1; i < args.length; i++) { Matcher matcher = NUMBER.matcher(args[i]); if (matcher.matches()) { if (matcher.group(1) != null) { ary[i - 1] = Double.parseDouble(args[i]); } else { ary[i - 1] = Integer.parseInt(args[i]); } } else { ary[i - 1] = args[i]; } } instance.init(ary); arguments[p] = instance; } ChainFunction function = new ChainFunction(); function.init(arguments); return function; } private  MiscUtils(); static long bucketCounter(Series series); static String[] splitAndNormalizeString(String input); static List<String> readAllLines(File file); static DataPoint buildDataPoint(long timestamp, long value); static DataPoint buildDataPoint(long timestamp, double value); static void ls(File file); static boolean delete(File file); static String tagsToString(List<Tag> tags); static String tagToString(List<String> tags); static TagFilter buildTagFilter(String tagFilter); static SimpleTagFilter buildSimpleFilter(String item); static FunctionIteratorFactory createIteratorChain(String[] parts, int startIndex); static Function createFunctionChain(String[] parts, int startIndex); static TargetSeries extractTargetFromQuery(String query); static Point buildDP(String dbName, String measurementName, List<String> valueFieldName, List<Tag> tags,
			long timestamp, List<Long> value, List<Boolean> fp); static String printBuffer(ByteBuffer buffer, int counter); static void writeStringToBuffer(String str, ByteBuffer buf); static void writeByteStringToBuffer(byte[] str, ByteBuffer buf); static ByteString getByteStringFromBuffer(ByteBuffer buf); static String getStringFromBuffer(ByteBuffer buf); static Point buildDataPoint(String dbName, String measurementName, List<String> valueFieldName,
			List<Tag> taglist, long timestamp, List<Long> values, List<Boolean> fp); static Point buildDataPoint(String dbName, String measurementName, String valueFieldName, List<Tag> taglist,
			long timestamp, long value); static Point buildDataPoint(String dbName, String measurementName, String valueFieldName, List<Tag> taglist,
			long timestamp, double value); static int tagHashCode(List<Tag> tags);  }