forked from OpenTSDB/opentsdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some really ugly makefile code to compile the expression parser
source files and add the source and classes to the TSDB jar. TODO - clean this up! It's not pretty but it seems to function and it doesn't cleanup after itself yet. Signed-off-by: Chris Larsen <[email protected]>
- Loading branch information
Showing
6 changed files
with
113 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,4 @@ guava-rpm-maker/\.project | |
src-main | ||
src-test | ||
plugin_test.jar | ||
/bin/ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
PARSER_BEGIN(SyntaxChecker) | ||
package net.opentsdb.query.expression.parser; | ||
|
||
import net.opentsdb.query.expression.ExpressionTree; | ||
import net.opentsdb.core.TSQuery; | ||
|
||
import java.util.List; | ||
import com.google.common.base.Joiner; | ||
import com.google.common.collect.Lists; | ||
|
||
/** | ||
* A simple class for validating the expressions | ||
* @since 2.3 | ||
*/ | ||
public class SyntaxChecker { | ||
|
||
private TSQuery data_query; | ||
private List<String> metricQueries; | ||
|
||
public void setTSQuery(TSQuery data_query) { | ||
this.data_query = data_query; | ||
} | ||
|
||
public void setMetricQueries(List<String> metricQueries) { | ||
this.metricQueries = metricQueries; | ||
} | ||
|
||
public static void main(String[] args) { | ||
try { | ||
new SyntaxChecker(new java.io.StringReader(args[0])).EXPRESSION(); | ||
System.out.println("Syntax is okay"); | ||
} catch (Throwable e) { | ||
// Catching Throwable is ugly but JavaCC throws Error objects! | ||
System.out.println("Syntax check failed: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
PARSER_END(SyntaxChecker) | ||
|
||
SKIP: { " " | "\t" | "\n" | "\r" } | ||
TOKEN: { <NAME: ("*" | (["a" - "z"] | ["A" - "Z"]| ["0"-"9"] | "-" | "_" | "#" | "/" | "$" | "@" | "|" | "." | "'" | "]" | "[")+ )> } | ||
TOKEN: { <PARAM: ("&&")> } | ||
|
||
ExpressionTree EXPRESSION(): {Token name; int paramIndex=0;} { | ||
name=<NAME> { ExpressionTree tree=new ExpressionTree(name.image,data_query); } | ||
"(" PARAMETER(tree, paramIndex++) ("," PARAMETER(tree, paramIndex++))* ")" | ||
{return tree;} | ||
} | ||
|
||
void PARAMETER(ExpressionTree tree, int paramIndex): {String metric; Token param; ExpressionTree subTree;} { | ||
subTree=EXPRESSION() {tree.addSubExpression(subTree, paramIndex);} | | ||
metric=METRIC() {metricQueries.add(metric); tree.addSubMetricQuery(metric, metricQueries.size()-1, paramIndex);} | | ||
param=<NAME> {tree.addFunctionParameter(param.image);} | ||
} | ||
|
||
// metric is agg:[interval-agg:][rate:]metric[{tag=value,...}] | ||
String METRIC() : {Token agg,itvl,rate,metric,tagk,tagv; StringBuilder builder = new StringBuilder(); | ||
Joiner JOINER = Joiner.on(",").skipNulls(); | ||
List<String> tagPairs = Lists.newArrayList(); | ||
} { | ||
agg = <NAME> ":" { builder.append(agg.image).append(":"); } | ||
(itvl=<NAME> ":" { builder.append(itvl.image).append(":"); })? | ||
(rate=<NAME> ":" { builder.append(rate.image).append(":"); })? | ||
metric=<NAME> { builder.append(metric.image); } | ||
("{" tagk=<NAME> "=" tagv=<NAME> {tagPairs.add(tagk+"="+tagv);} | ||
("," tagk=<NAME> "=" tagv=<NAME> {tagPairs.add(tagk+"="+tagv);})* "}")? | ||
{if (tagPairs.size() > 0) builder.append("{").append(JOINER.join(tagPairs)).append("}"); return builder.toString();} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (C) 2015 The OpenTSDB Authors. | ||
# | ||
# This library is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 2.1 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
JAVACC_VERSION := 6.1.2 | ||
JAVACC := third_party/javacc/javacc-$(JAVACC_VERSION).jar | ||
JAVACC_BASE_URL := http://central.maven.org/maven2/net/java/dev/javacc/javacc/$(JAVACC_VERSION) | ||
|
||
$(JAVACC): $(JAVACC).md5 | ||
set dummy "$(JAVACC_BASE_URL)" "$(JAVACC)"; shift; $(FETCH_DEPENDENCY) | ||
|
||
THIRD_PARTY += $(JAVACC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c74b2df75b4c46209d6da22bf4dad976 |