OAL supports multiple values when as numeric (#6233)
This commit is contained in:
parent
a8e66244cd
commit
762e347cba
|
|
@ -71,6 +71,7 @@ Release Notes.
|
|||
* Support Alarm to feishu
|
||||
* Add the implementation of ConfigurationDiscovery on the OAP side.
|
||||
* Fix bug in `parseInternalErrorCode` where some error codes are never reached.
|
||||
* OAL supports multiple values when as numeric
|
||||
|
||||
#### UI
|
||||
* Fix un-removed tags in trace query.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public class ConditionExpression {
|
|||
private List<String> attributes = new ArrayList<>();
|
||||
private String value;
|
||||
private List<String> values;
|
||||
private boolean number;
|
||||
|
||||
public ConditionExpression(final String expressionType, final String attributes, final String value) {
|
||||
this.expressionType = expressionType;
|
||||
|
|
@ -50,11 +51,17 @@ public class ConditionExpression {
|
|||
}
|
||||
}
|
||||
|
||||
public void isNumber() {
|
||||
number = true;
|
||||
}
|
||||
|
||||
public void enterMultiConditionValue() {
|
||||
values = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void exitMultiConditionValue() {
|
||||
value = "new Object[]{" + String.join(",", values) + "}";
|
||||
value = number ?
|
||||
"new long[]{" + String.join(",", values) + "}" :
|
||||
"new Object[]{" + String.join(",", values) + "}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ public class OALListener extends OALParserBaseListener {
|
|||
|
||||
@Override
|
||||
public void enterNumberConditionValue(OALParser.NumberConditionValueContext ctx) {
|
||||
conditionExpression.isNumber();
|
||||
enterConditionValue(ctx.getText());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -227,11 +227,31 @@ public class ScriptParserTest {
|
|||
"org.apache.skywalking.oap.server.core.analysis.metrics.expression.InMatch",
|
||||
expression.getExpressionObject()
|
||||
);
|
||||
Assert.assertEquals("new Object[]{1,2,3}", expression.getRight());
|
||||
Assert.assertEquals("new long[]{1,2,3}", expression.getRight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse8() throws IOException {
|
||||
ScriptParser parser = ScriptParser.createFromScriptText(
|
||||
"service_response_s4_summary = from(Service.latency).filter(latency != 1).filter(latency in [\"1\",\"2\", \"3\"]).sum();",
|
||||
TEST_SOURCE_PACKAGE
|
||||
);
|
||||
List<AnalysisResult> results = parser.parse().getMetricsStmts();
|
||||
Assert.assertEquals(1, results.size());
|
||||
AnalysisResult result = results.get(0);
|
||||
List<Expression> expressions = result.getFilterExpressions();
|
||||
Assert.assertEquals(2, expressions.size());
|
||||
Expression expression = expressions.get(1);
|
||||
Assert.assertEquals("source.getLatency()", expression.getLeft());
|
||||
Assert.assertEquals(
|
||||
"org.apache.skywalking.oap.server.core.analysis.metrics.expression.InMatch",
|
||||
expression.getExpressionObject()
|
||||
);
|
||||
Assert.assertEquals("new Object[]{\"1\",\"2\",\"3\"}", expression.getRight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse9() throws IOException {
|
||||
ScriptParser parser = ScriptParser.createFromScriptText(
|
||||
"ServicePercent = from(Service.sidecar.internalError).filter(sidecar.internalError == \"abc\").percent(sidecar.internalError != \"\");", TEST_SOURCE_PACKAGE);
|
||||
List<AnalysisResult> results = parser.parse().getMetricsStmts();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,25 @@ import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterM
|
|||
|
||||
@FilterMatcher
|
||||
public class InMatch {
|
||||
|
||||
public boolean match(int left, long[] rights) {
|
||||
for (long right : rights) {
|
||||
if (left == right) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean match(long left, long[] rights) {
|
||||
for (long right : rights) {
|
||||
if (left == right) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean match(Object left, Object[] rights) {
|
||||
for (Object right : rights) {
|
||||
if (right instanceof String) {
|
||||
|
|
|
|||
|
|
@ -48,26 +48,26 @@ public class InMatchTest {
|
|||
}
|
||||
));
|
||||
|
||||
Assert.assertTrue(new InMatch().match(1, new Object[] {
|
||||
Assert.assertTrue(new InMatch().match(1, new long[] {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
}));
|
||||
Assert.assertFalse(new InMatch().match(4, new Object[] {
|
||||
Assert.assertFalse(new InMatch().match(4, new long[] {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
}));
|
||||
|
||||
Assert.assertTrue(new InMatch().match(1.0D, new Object[] {
|
||||
1.0D,
|
||||
2.0D,
|
||||
3.0D
|
||||
Assert.assertTrue(new InMatch().match(1L, new long[] {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
}));
|
||||
Assert.assertFalse(new InMatch().match(4.0D, new Object[] {
|
||||
1.0D,
|
||||
2.0D,
|
||||
3.0D
|
||||
Assert.assertFalse(new InMatch().match(4L, new long[] {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue