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

Searching for devices using jsonFilter does not seem to work for string values #3643

Open
StFS opened this issue Jun 8, 2024 · 3 comments
Open

Comments

@StFS
Copy link
Contributor

StFS commented Jun 8, 2024

According to the documentation, searching for devices can be done using a predicate specified by the filterJson request parameter. The example in the documentation for example is {"field": "/ext/brand","value": "eclipse*"} indicating that searching in nested fields should be supported.

However, it seems that it is not as demonstrated by the following example run against the Hono sandbox setup.

First we'll get a list of the devices that are registered on the DEFAULT_TENANT:

➜ curl -X GET https://hono.eclipseprojects.io:28443/v1/devices/DEFAULT_TENANT |jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   469  100   469    0     0   1167      0 --:--:-- --:--:-- --:--:--  1169
{
  "total": 5,
  "result": [
    {
      "status": {
        "created": "2024-06-07T10:27:16Z"
      },
      "id": "1111"
    },
    {
      "ext": {
        "ep": "IMEI4711"
      },
      "status": {
        "created": "2024-06-07T10:27:06Z"
      },
      "id": "1234"
    },
    {
      "enabled": true,
      "defaults": {
        "content-type": "application/vnd.bumlux",
        "importance": "high"
      },
      "status": {
        "created": "2024-06-06T16:30:30Z"
      },
      "id": "4711"
    },
    {
      "enabled": true,
      "via": [
        "gw-1"
      ],
      "status": {
        "created": "2024-06-06T16:30:31Z"
      },
      "id": "4712"
    },
    {
      "enabled": true,
      "status": {
        "created": "2024-06-06T16:30:31Z"
      },
      "id": "gw-1"
    }
  ]
}

Here we see that there is a device registered that we can try searching for by filtering on the value of /ext/ep:

    {
      "ext": {
        "ep": "IMEI4711"
      },
      "status": {
        "created": "2024-06-07T10:27:06Z"
      },
      "id": "1234"
    },

If we perform a GET request using {"field": "/ext/ep","value": "IMEI4711"} as the jsonFilter value, we see that no device is returned:

➜ curl -X GET https://hono.eclipseprojects.io:28443/v1/devices/DEFAULT_TENANT\?filterJson\=%7B%22field%22%3A%20%22%2Fext%2Fep%22%2C%22value%22%3A%20%22IMEI4711%22%7D
{"error":"no devices matching searching criteria"}

When trying to search by the /id field using the jsonFilter value of {"field": "/id","value": "1234"}, that does not work either:

➜ curl -X GET https://hono.eclipseprojects.io:28443/v1/devices/DEFAULT_TENANT\?filterJson\=%7B%22field%22%3A%20%22%2Fid%22%2C%22value%22%3A%20%221234%22%7D
{"error":"no devices matching searching criteria"}

However, if we search for devices that have the enabled field set to a true value, that seems to work as we only get the subset of devices that actually have that set:

➜ curl -X GET https://hono.eclipseprojects.io:28443/v1/devices/DEFAULT_TENANT\?filterJson\=%7B%22field%22%3A%20%22%2Fenabled%22%2C%22value%22%3A%20true%7D | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   329  100   329    0     0    795      0 --:--:-- --:--:-- --:--:--   794
{
  "total": 3,
  "result": [
    {
      "enabled": true,
      "defaults": {
        "content-type": "application/vnd.bumlux",
        "importance": "high"
      },
      "status": {
        "created": "2024-06-06T16:30:30Z"
      },
      "id": "4711"
    },
    {
      "enabled": true,
      "via": [
        "gw-1"
      ],
      "status": {
        "created": "2024-06-06T16:30:31Z"
      },
      "id": "4712"
    },
    {
      "enabled": true,
      "status": {
        "created": "2024-06-06T16:30:31Z"
      },
      "id": "gw-1"
    }
  ]
}

Note that we're only getting 3 devices with this query while we got 5 devices with our original query (using no jsonFilter).

So my gut feeling is that this must be a bug.

@sophokles73
Copy link
Contributor

Can you reproduce this with a local installation using the JDBC registry with PostgreSQL? The integration tests of Hono include a test case that verifies searching by (nested) string-typed fields, but the embedded H2 based JDBC registry that is used on the Sandbox seems to have problems with this and sorting ...

@StFS
Copy link
Contributor Author

StFS commented Jul 15, 2024

I have reproduced this issue running on a fresh installation to my docker-desktop embedded k8s cluster. That setup has a PSQL DB underneath the JDBC based device registry. I'm seeing this behavior there as well.

@sophokles73
Copy link
Contributor

Can you create a verifier (test case) for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants