Value manipulation in a query

Hello,

Is there a way to concatenate string values from a query to use in a filter of a subsequent query?

Here’s an example:

{
  people(func: eq(type, “PERSON}”)) @cascade @normalize {
    personId : _id
    _contains @filter(eq(type, “ADDRESS”)) {
      address_city : city
      address_state : state
    }
  }
}

Then, from the application, I execute this per person returned:

{
  pages(func: eq(type, “PAGE”)) @cascade @normalize {
    pageId : _id
    pageTitle : _title
    _owns @filter(eq(path, “address_city.address_state“))
  }
}

This almost always overwhelms my server. What I would like to do is:

{
  people(func: eq(type, “PERSON}”)) @cascade @normalize {
    personId : _id
    _contains @filter(eq(type, “ADDRESS”)) {
      C as city
      S as state
    }
  }

  pages(func: eq(type, “PAGE”)) @cascade @normalize {
    pageId : _id
    pageTitle : _title
    _owns @filter(eq(path, @concat(val(C),".",val(S))))
  }
}

Is there a way to do something along those lines?

Something similar to https://neo4j.com/docs/developer-manual/current/cypher/syntax/operators/#query-operators-string maybe?

Hi, Shelbayeh

For now, there is no way to do this as far as I know. because Query Variables are UID type.

UPDATE

Before I had written about uid_in, slight mistake. It has to filter with uid itself.

Yes, you must transform the address and state as a Nodes structure. And then use @filter by uid.

Let me explain. Each street, city and state would have unique Nodes. That is, they would have UID of their own. So I would recommend that you create a hierarchical structure for this. So it will be easy even for you to get localized bigdata.

That way your filter would look like this:

  var_address_city as city
  var_address_state as state

 _owns @filter(uid( var_address_city, var_address_state))

#if you are using @reverse
 _owns @filter(uid( var_address_city, var_address_state))

More about uid with filter Get started with Dgraph
e.g: predicate @filter(uid(<uid1>, ..., <uidn>))

So, to finish. In that case, a query would look something like this.

{
  people(func: eq(type, “PERSON}”)) @cascade @normalize {
    personId : _id
    _contains @filter(eq(type, “ADDRESS”)) {
      var_address_city as city
      var_address_state as state
    }
  }

    pages_from(func: uid(var_address_state))@cascade @normalize {
       city @filter(uid( var_address_city)) {
        pages {
          pageId : _id
          pageTitle : _title
        }
          }
    }
}

Approximately. This is not a real query.

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