IoT Core Rule SQL - OR operator inconsistency between IoT SQL versions

0

Hello, I am trying to create an IoT Rule that selects only the fields I need from a specified MQTT topic and republishes the message to another MQTT topic. The SQL query I am using is the following:

SELECT state.debug AS state.debug, state.command AS state.command, version 
FROM '$aws/things/my-thing/shadow/update/delta' 
WHERE state.debug <> '' OR state.command <> '' 

When the selected SQL version is the latest (2016-03-23), the right operand of the WHERE clause is completely ignored and the rule is triggered only if the state.debug property has a value. When I change the SQL version to 2015-10-08, however, the rule works just fine.

It seems that there is no breaking change on the way the two SQL versions handle logical operators, according to the AWS documentation. Therefore, is it possible that there is a bug with 2016-03-23 IoT SQL version or am I missing something else here?

질문됨 2년 전335회 조회
1개 답변
0

Hi. I tried to replicate your issue with the WHERE clause, but didn't find a problem with SQL version 2016-03-23. Are you still stuck on this problem?

profile pictureAWS
전문가
Greg_B
답변함 2년 전
  • Hello Greg, thanks for your reply! Yes, unfortunately I am still stuck on this. Could you please provide the SQL query you tried as well as the message you used it on?

    The messages published to the topic I am querying are structured this way: { "state": { "debug": { "remoteLogging": false }, "command": "ls", ... }, "version": ... , "timestamp": ... , "metadata": ... } Should I maybe check in a different way than state.debug <> '' OR state.command <> '' whether either of these 2 properties is not empty? Thanks again!

  • I realize I misread your SQL statement. Now I can indeed see the behaviour. Regardless, it will be more semantic (and it will work) to use the IsUndefined() function: WHERE IsUndefined(state.debug) = False OR IsUndefined(state.command) = False. I hope this unblocks you.

  • Hey Greg, thanks for you response. Indeed, isUndefined() seems to be exactly what I need! Out of curiosity, have you managed to identify why the OR operator behaves this way in my initial query?

  • Hi again. No I didn't. It's odd. I raised a ticket for it internally. Nonetheless, undefined is not necessarily an empty string, so the IsUndefined function is a better choice.

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

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

질문 답변하기에 대한 가이드라인