@Test public void testBuildTagFilter() throws InvalidFilterException { TagFilter filter = MiscUtils.buildTagFilter("host=1&test=2|tree=LTS.12"); assertEquals(ComplexTagFilter.class, filter.getClass()); ComplexTagFilter complex = ((ComplexTagFilter) filter); assertEquals(ComplexFilterType.OR, complex.getType()); assertEquals(2, complex.getFilters().size()); assertEquals(ComplexTagFilter.class, complex.getFilters().get(0).getClass()); assertEquals(SimpleTagFilter.class, complex.getFilters().get(1).getClass()); filter = MiscUtils.buildTagFilter("user>=test@sss&test<LTS.212"); complex = ((ComplexTagFilter) filter); assertEquals(ComplexFilterType.AND, complex.getType()); assertEquals(2, complex.getFilters().size()); SimpleTagFilter sfilter = ((SimpleTagFilter) complex.getFilters().get(0)); assertEquals("user", sfilter.getTagKey()); assertEquals("test@sss", sfilter.getComparedValue()); assertEquals(FilterType.GREATER_THAN_EQUALS, sfilter.getFilterType()); sfilter = ((SimpleTagFilter) complex.getFilters().get(1)); assertEquals(FilterType.LESS_THAN, sfilter.getFilterType()); assertEquals("test", sfilter.getTagKey()); assertEquals("LTS.212", sfilter.getComparedValue()); filter = MiscUtils.buildTagFilter("user<=1_2122|test>1"); complex = ((ComplexTagFilter) filter); assertEquals(ComplexFilterType.OR, complex.getType()); assertEquals(2, complex.getFilters().size()); sfilter = ((SimpleTagFilter) complex.getFilters().get(0)); assertEquals("user", sfilter.getTagKey()); assertEquals("1_2122", sfilter.getComparedValue()); assertEquals(FilterType.LESS_THAN_EQUALS, sfilter.getFilterType()); sfilter = ((SimpleTagFilter) complex.getFilters().get(1)); assertEquals(FilterType.GREATER_THAN, sfilter.getFilterType()); assertEquals("test", sfilter.getTagKey()); assertEquals("1", sfilter.getComparedValue()); }
public static TagFilter buildTagFilter(String tagFilter) throws InvalidFilterException { String[] tagSet = tagFilter.split("(&|\\|)"); try { Stack<TagFilter> predicateStack = new Stack<>(); for (int i = 0; i < tagSet.length; i++) { String item = tagSet[i]; if (predicateStack.isEmpty()) { SimpleTagFilter filter = buildSimpleFilter(item); predicateStack.push(filter); } else { TagFilter pop = predicateStack.pop(); char operator = tagFilter.charAt(tagFilter.indexOf(tagSet[i]) - 1); switch (operator) { case '|': predicateStack.push(new ComplexTagFilter(ComplexFilterType.OR, (Arrays.asList(pop, buildSimpleFilter(item))))); break; case '&': predicateStack.push(new ComplexTagFilter(ComplexFilterType.AND, (Arrays.asList(pop, buildSimpleFilter(item))))); break; } } } if (predicateStack.isEmpty()) { return null; } else { return predicateStack.pop(); } } catch (InvalidFilterException e) { throw e; } catch (Exception e) { throw new InvalidFilterException(e.getMessage()); } }
MiscUtils { public static TagFilter buildTagFilter(String tagFilter) throws InvalidFilterException { String[] tagSet = tagFilter.split("(&|\\|)"); try { Stack<TagFilter> predicateStack = new Stack<>(); for (int i = 0; i < tagSet.length; i++) { String item = tagSet[i]; if (predicateStack.isEmpty()) { SimpleTagFilter filter = buildSimpleFilter(item); predicateStack.push(filter); } else { TagFilter pop = predicateStack.pop(); char operator = tagFilter.charAt(tagFilter.indexOf(tagSet[i]) - 1); switch (operator) { case '|': predicateStack.push(new ComplexTagFilter(ComplexFilterType.OR, (Arrays.asList(pop, buildSimpleFilter(item))))); break; case '&': predicateStack.push(new ComplexTagFilter(ComplexFilterType.AND, (Arrays.asList(pop, buildSimpleFilter(item))))); break; } } } if (predicateStack.isEmpty()) { return null; } else { return predicateStack.pop(); } } catch (InvalidFilterException e) { throw e; } catch (Exception e) { throw new InvalidFilterException(e.getMessage()); } } }
MiscUtils { public static TagFilter buildTagFilter(String tagFilter) throws InvalidFilterException { String[] tagSet = tagFilter.split("(&|\\|)"); try { Stack<TagFilter> predicateStack = new Stack<>(); for (int i = 0; i < tagSet.length; i++) { String item = tagSet[i]; if (predicateStack.isEmpty()) { SimpleTagFilter filter = buildSimpleFilter(item); predicateStack.push(filter); } else { TagFilter pop = predicateStack.pop(); char operator = tagFilter.charAt(tagFilter.indexOf(tagSet[i]) - 1); switch (operator) { case '|': predicateStack.push(new ComplexTagFilter(ComplexFilterType.OR, (Arrays.asList(pop, buildSimpleFilter(item))))); break; case '&': predicateStack.push(new ComplexTagFilter(ComplexFilterType.AND, (Arrays.asList(pop, buildSimpleFilter(item))))); break; } } } if (predicateStack.isEmpty()) { return null; } else { return predicateStack.pop(); } } catch (InvalidFilterException e) { throw e; } catch (Exception e) { throw new InvalidFilterException(e.getMessage()); } } private  MiscUtils(); }
MiscUtils { public static TagFilter buildTagFilter(String tagFilter) throws InvalidFilterException { String[] tagSet = tagFilter.split("(&|\\|)"); try { Stack<TagFilter> predicateStack = new Stack<>(); for (int i = 0; i < tagSet.length; i++) { String item = tagSet[i]; if (predicateStack.isEmpty()) { SimpleTagFilter filter = buildSimpleFilter(item); predicateStack.push(filter); } else { TagFilter pop = predicateStack.pop(); char operator = tagFilter.charAt(tagFilter.indexOf(tagSet[i]) - 1); switch (operator) { case '|': predicateStack.push(new ComplexTagFilter(ComplexFilterType.OR, (Arrays.asList(pop, buildSimpleFilter(item))))); break; case '&': predicateStack.push(new ComplexTagFilter(ComplexFilterType.AND, (Arrays.asList(pop, buildSimpleFilter(item))))); break; } } } if (predicateStack.isEmpty()) { return null; } else { return predicateStack.pop(); } } catch (InvalidFilterException e) { throw e; } catch (Exception e) { throw new InvalidFilterException(e.getMessage()); } } 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 TagFilter buildTagFilter(String tagFilter) throws InvalidFilterException { String[] tagSet = tagFilter.split("(&|\\|)"); try { Stack<TagFilter> predicateStack = new Stack<>(); for (int i = 0; i < tagSet.length; i++) { String item = tagSet[i]; if (predicateStack.isEmpty()) { SimpleTagFilter filter = buildSimpleFilter(item); predicateStack.push(filter); } else { TagFilter pop = predicateStack.pop(); char operator = tagFilter.charAt(tagFilter.indexOf(tagSet[i]) - 1); switch (operator) { case '|': predicateStack.push(new ComplexTagFilter(ComplexFilterType.OR, (Arrays.asList(pop, buildSimpleFilter(item))))); break; case '&': predicateStack.push(new ComplexTagFilter(ComplexFilterType.AND, (Arrays.asList(pop, buildSimpleFilter(item))))); break; } } } if (predicateStack.isEmpty()) { return null; } else { return predicateStack.pop(); } } catch (InvalidFilterException e) { throw e; } catch (Exception e) { throw new InvalidFilterException(e.getMessage()); } } 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);  }