Filtering list values

Mirror of: Feature request: Filtering list values · Issue #2563 · dgraph-io/dgraph · GitHub

Say I have a predicate timestamps:[datetime] @index(month) @count . and I only want values between a range.
Currently, since the inequality functions require a predicate of some kind you can’t use it to filter values as suggested in #2271, additionally that returns everything as long as there is a value within that range (rather than just the values you want). The current workaround that I have come up with is converting timestamps to a UID from [datetime] and then creating another timestamp type but this has the downside of 2 predicates + N UID’s to deal with elsewhere.

1 Like

I can not see the issue, can you detail it a bit better? With examples. I made an example below, if you can explain better with it already helps.

timestamps:[datetime] @index(month) @count .

Mutation in JSON

{
  "set": [
    {
      "Nodes": [
        {
          "Node_Name": "Node_01",
          "timestamps": [
            "2018-01-01",
            "2018-02-01",
            "2018-03-01",
            "2018-04-01"
          ]
        },
        {
          "Node_Name": "Node_02",
          "timestamps": [
            "2019-01-01",
            "2019-02-01",
            "2019-03-01",
            "2019-04-01"
          ]
        },
         {
          "Node_Name": "Node_03",
          "timestamps": [
            "2018-05-01"
          ]
        },
        {
          "Node_Name": "Node_04",
          "timestamps": [
            "2019-06-01"
          ]
        },
        {
          "Node_Name": "Node_05",
          "timestamps": [
            "2017-06-01"
          ]
        }
      ]
    }
  ]
}

Query


{
  query(func: has(Nodes)){
    uid
    Nodes @filter(ge(timestamps, "2018-03-01") AND le (timestamps, "2019-01-01")){ expand(_all_)}
  }
  query2(func: has(Nodes)){
    uid
    Nodes @filter(ge(timestamps, "2017-03-01") AND le (timestamps, "2018-01-01")){ expand(_all_)}
  }
}

Response

{
  "data": {
    "query": [
      {
        "uid": "0x2713",
        "Nodes": [
          {
            "Node_Name": "Node_02",
            "timestamps": [
              "2019-02-01T00:00:00Z",
              "2019-01-01T00:00:00Z",
              "2019-04-01T00:00:00Z",
              "2019-03-01T00:00:00Z"
            ]
          },
          {
            "Node_Name": "Node_01",
            "timestamps": [
              "2018-02-01T00:00:00Z",
              "2018-01-01T00:00:00Z",
              "2018-03-01T00:00:00Z",
              "2018-04-01T00:00:00Z"
            ]
          },
          {
            "Node_Name": "Node_03",
            "timestamps": [
              "2018-05-01T00:00:00Z"
            ]
          }
        ]
      }
    ],
    "query2": [
      {
        "uid": "0x2713",
        "Nodes": [
          {
            "Node_Name": "Node_01",
            "timestamps": [
              "2018-02-01T00:00:00Z",
              "2018-01-01T00:00:00Z",
              "2018-03-01T00:00:00Z",
              "2018-04-01T00:00:00Z"
            ]
          },
          {
            "Node_Name": "Node_05",
            "timestamps": [
              "2017-06-01T00:00:00Z"
            ]
          }
        ]
      }
    ]
  }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.