Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid json error given for a nested Json message #1723

Merged
merged 2 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class TemplateBuilder {

private static final Pattern DYNAMIC_PATTERN = Pattern.compile("(\\{\\{[^{}]*\\}\\})|[{}]");
private static final String SPLIT_PATTERN = "(\\{\\{|\\}\\})";
private static final String SPLIT_PATTERN = "(\\{.\\{|\\}.\\})";
private int[] positionArray;
private String[] splitTemplateArray;
private boolean isObjectMessage = false;
Expand Down Expand Up @@ -113,7 +113,7 @@ private String parseTextMessage(StreamDefinition streamDefinition, String templa
if (m.group(1) != null) {
int attrIndex = attributes.indexOf(m.group(1).replaceAll("\\p{Ps}", "").replaceAll("\\p{Pe}", ""));
if (attrIndex >= 0) {
m.appendReplacement(result, String.format("{{%s}}", attrIndex));
m.appendReplacement(result, String.format("{.{%s}.}", attrIndex));
} else {
throw new NoSuchAttributeException(String.format("Attribute : %s does not exist in %s.",
m.group(1), streamDefinition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,40 @@ public void receive(Event[] events) {

}

@Test(dependsOnMethods = "testQuery7")
public void testQuery8() throws InterruptedException {
//see https://github.com/siddhi-io/siddhi/issues/1542
log.info("test case for https://github.com/siddhi-io/siddhi/issues/1542");

SiddhiManager siddhiManager = new SiddhiManager();

String plan = "" +
"define trigger AlertTypeReadTrigger at 'start';" +
"@sink(type='log')\n" +
"define stream logStream (foo string);\n" +
"\n" +
"from AlertTypeReadTrigger\n" +
"select \"hello\" as foo\n" +
"insert into logStream;";

SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan);

siddhiAppRuntime.addCallback("logStream", new StreamCallback() {

@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count += events.length;
eventArrived = true;
}
});

siddhiAppRuntime.start();

Thread.sleep(1000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(1, count);
AssertJUnit.assertEquals(true, eventArrived);
}

}