내용으로 건너뛰기

What is the nested function call syntax for IoT Rule Engine's SQL?

0

I want to republish messages from a topic to another.

When there's a message on topic: node/node_id
it should resolve this expression:
user/get(${aws_lambda("arn:aws:lambda:us-east-1:1234567890:function:GetUserIDsForNode", {"data":{"node_id":"topic(2)"}} )}, 0)
To give me something like: user/<user_id>

It has 3 levels of nesting: get contains a aws_lambda call, which in-turn contains a topic call.

The issue is that it currently resolves the aws_lambda function, but not the rest. As they are not wrapped in ${}.
But when I wrap the other functions, like:
user/${get(${aws_lambda("arn:aws:lambda:us-east-1:1234567890:function:GetUserIDsForNode", {"data":{"node_id":"${topic(2)}"}} )}, 0)}

The SQL is apparently problematic. It complains:

SqlParseException
Unexpected character '$' ${aws_lambda("arn:aws:lambda:us-east-1:1234567890:function:GetUserIDsForNode", {"data":{"node_id":"${topic(2)}"}} )}, 0)}/params ----^ at 1:5

When I use:
user/get(${aws_lambda("arn:aws:lambda:us-east-1:1234567890:function:GetUserIDsForNode", {"data":{"node_id":"${topic(2)}"}} )}, 0).
and print the data payload inside the Lambda, I see that the node_id field is not resolved, it says:

{
    "data": {
        "node_id": "${topic(2)}"
    }
}

So this time it does not complain about nesting, but it does not resolve to the actual value either.

What is the syntax for nested SQL function calls?

질문됨 2년 전315회 조회

2개 답변
0

Hello,

there are several things that may go wrong :)

First of all, make sure the sintax is ok.

user/${get(${aws_lambda("arn:aws:lambda:us-east-1:1234567890:function:GetUserIDsForNode", {"data":{"node_id":"${topic(2)}"}})}, 0)}

전문가

답변함 2년 전

  • Hey I tried that. But I get this again: Resource handler returned message: "Unexpected character '$' ${aws_lambda("arn:aws:lambda:us-east- 1:1234567890:function:GetUserIDsForNode", {"data":{"node_id":"${topic(2)}"}})}, 0)} ----^ at 1:5

    I also added select beside the inner function calls, because this expression is technically supposed to be a SELECT clause.
    But that didn't work either.

0

Turns out this is one of those things where I had to get out of my own way.

There's no need to think about how many places I have to add ${}.
The trick was to build a complete SELECT clause first (like a normal SQL statement), which means forgetting the ${} part.

For me that looked like:
SELECT get(aws_lambda("LambdaARN", { "data":{"node_id": topic(2) }}), 0)

THEN removing the SELECT and wrap the ${} only around this:
${get(aws_lambda("LambdaARN", { "data":{"node_id": topic(2) }}), 0)}

Finally I could add any other string literals I wanted around it:
user/${get(aws_lambda("LambdaARN", { "data":{"node_id": topic(2) }}), 0)}

And that worked!

답변함 2년 전

전문가

검토됨 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠