Skip to content

Commit

Permalink
Merge pull request #1259 from FIWARE/bug/issue1258
Browse files Browse the repository at this point in the history
Fixed issue #1258
  • Loading branch information
kzangeli authored Oct 27, 2022
2 parents f7630fb + 4d7a04d commit d3de001
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
* Issue #280 Added a URL parameter for GET /subscriptions/{subId}: ?options=fromDb to get the subscription from DB and not subscription cache
* Issue #280 Implemented retrieval of a subscription from the database instead of from the subscription cache: GET /subscriptions/{subId}?options=fromDb
* Issue #280 Implemented query of subscriptions from the database instead of from the subscription cache: GET /subscriptionss?options=fromDb
* Issue #1258 Fixed bug in Q-Parser: negative floating point values was not handled ...
14 changes: 10 additions & 4 deletions src/lib/orionld/q/qLex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ static QNode* qTermPush(QNode* prev, char* term, bool* lastTermIsTimestampP, cha
{
if (hyphens > 0)
{
dateTime = true; // MIGHT be a DateTime
type = QNodeIntegerValue;
dateTime = true; // MIGHT be a DateTime

if (dots == 0)
type = QNodeIntegerValue; // hyphens found but no dots - its an Integer (or a DateTime)
else if (dots == 1)
type = QNodeFloatValue; // hyphen found and one dot - its a Float
else
type = QNodeVariable;
}
else if (dots == 0)
type = QNodeIntegerValue;
type = QNodeIntegerValue; // no dots - its an Integer
else if (dots == 1)
type = QNodeFloatValue;
type = QNodeFloatValue; // one dot - its a Floating point
else
type = QNodeVariable;
}
Expand Down
151 changes: 151 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_issue_1258.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Copyright 2022 FIWARE Foundation e.V.
#
# This file is part of Orion-LD Context Broker.
#
# Orion-LD Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion-LD Context Broker 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 Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# orionld at fiware dot org

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
Q-Filter and negative floating point

--SHELL-INIT--
export BROKER=orionld
dbInit CB
brokerStart CB 0

--SHELL--

#
# 01. Create an entity E1 with an attribute xy==-1.03
# 02. Retrieve the entity
# 03. Query using q=xy==-1.03 - see E1
# 04. Query using q=xy==-1.04 - see nothing
# 05. Query using q=xy==1.03 - see nothing
#

echo "01. Create an entity E1 with an attribute xy==-1.03"
echo "==================================================="
payload='{
"id": "urn:ngsi-ld:entities:T:E1",
"type": "T",
"xy": -1.03
}'
orionCurl --url /ngsi-ld/v1/entities -X POST --payload "$payload"
echo
echo


echo "02. Retrieve the entity"
echo "======================="
orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entities:T:E1
echo
echo


echo "03. Query using q=xy==-1.03 - see E1"
echo "===================================="
orionCurl --url /ngsi-ld/v1/entities?q=xy==-1.03
echo
echo


echo "04. Query using q=xy==-1.04 - see nothing"
echo "========================================="
orionCurl --url /ngsi-ld/v1/entities?q=xy==-1.04
echo
echo


echo "05. Query using q=xy==1.03 - see nothing"
echo "========================================"
orionCurl --url /ngsi-ld/v1/entities?q=xy==1.03
echo
echo


--REGEXPECT--
01. Create an entity E1 with an attribute xy==-1.03
===================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:ngsi-ld:entities:T:E1



02. Retrieve the entity
=======================
HTTP/1.1 200 OK
Content-Length: 84
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{
"id": "urn:ngsi-ld:entities:T:E1",
"type": "T",
"xy": {
"type": "Property",
"value": -1.03
}
}


03. Query using q=xy==-1.03 - see E1
====================================
HTTP/1.1 200 OK
Content-Length: 86
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

[
{
"id": "urn:ngsi-ld:entities:T:E1",
"type": "T",
"xy": {
"type": "Property",
"value": -1.03
}
}
]


04. Query using q=xy==-1.04 - see nothing
=========================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Date: REGEX(.*)

[]


05. Query using q=xy==1.03 - see nothing
========================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Date: REGEX(.*)

[]


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit d3de001

Please sign in to comment.