First with Value Variable doesnt work

Report a Dgraph Bug

What version of Dgraph are you using?

Dgraph Version
$ dgraph version
 
v20.11.0

Have you tried reproducing the issue with the latest release?

What is the hardware spec (RAM, OS)?

Steps to reproduce the issue (command/config used to run Dgraph).

Run an Query with a Value Variable and this constellation!

length as SOMEPREDICATE

and use it in for example first

(first: val(length))

I get this exception!

{
  "name": "t",
  "url": "http://localhost:8080/query?timeout=20s",
  "errors": [
    {
      "message": ": while converting to subgraph: strconv.ParseInt: parsing \"ct\": invalid syntax",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

I tried several things, defining predicate as string, integer, used count, max, min

Everytime u get this error!

Expected behaviour and actual result.

It should take the value and use it to limit the elements

Found similar Topic where the last statment is on fixed bug

Hi,

I didn’t quite understand the steps to reproduce it. Do you mean something like this:

{
  var (func: allofterms(name@en, "Steven Spielberg")) @filter(has(director.film)){
  	length as count(director.film)
  }
  me(func: allofterms(name@en, "Steven Spielberg")) @filter(has(director.film)){
    director.film(first: val(length)) {
      name@en
    }
  }
}


If this is the case, then you’re right - it doesn’t work.

I’m doubtful of the previous claim that this was in the changelist for 20.07. @hardik can you please check this out?

EDIT: I found the Pull Request:

It is specific to uid(), not val()

So I’m accepting this as a feature request

Good morning!

Yes thats exactly what I mean!

I saw the linked post and didn’t know if its already implemented!

But it seems too

Atleast what I understand from error I have got

while converting to subgraph: strconv.ParseInt: parsing \"ct\": invalid syntax

The error didn’t say that it can’t convert val(), it can’t convert the value of variable

Am I right in this theorie?

Greetings

So the steps in handling a query is something along the lines of this (things in bold are data structures, things not in bold are functions):

Query –parseGraphQueryconvert to SubGraphSubGraphprocess request → Results
… … … ↑↑↑ … … … …
The error happens in the parse phase (where the arrows point to).

That is, our language spec doesn’t allow for identifiers at that position. The spec needs to be updated to allow that.

1 Like

Ah okay.

Is there any estimation when this get’s implemented?

I would need it for a project

Thanks!

Unfortunately I won’t be able to give you an estimate. @hardik might, since he’s managing the queue and features.

We are analyzing whether this should be part of Dgraph or not. We will keep you posted.

1 Like

Hey @Florian, Currently variables are not supported in first and offset parameters. However, can you elaborate on your use case with some sample queries so that we can look into it?

@Florian would you help Minhaj with his query?? ^^

Hello,
I am sorry for my late answer, the last weeks I was on hurry!

Example:

query {
	array(func: uid(0x2723)){
		l as Length
    Array(first: val(l))
    {
			name
    }
  }
}
{
  "set":
	{
    "uid": "_:root",
    "Length": 10,
    "Array":[
        {
            "name": "1"
        },
        {
            "name": "2"
        },
        {
            "name": "3"
        },
        {
            "name": "4"
        },
        {
            "name": "5"
        },
        {
            "name": "6"
        },
        {
            "name": "7"
        }
    ]
	}
}

Greetings
Florian