The NOT doesn't work for regexp in filter

I want to filter nodes whose email address not contain a constent word. For the reason that allofterms is case insensitive, and i want case sensitive, so I try use regex to do it.
I have nodes A, B, C
with address

"testAddress1@gmail.com"
"testAddress2@gmail.com"
"testaddress3@gmail.com"

use

result(func: uid(A,B,C)) @filter(regexp(email, /Address/)){**
  name
}

it return node A and B
while use

result(func: uid(A,B,C)) @filter(NOT regexp(email, /Address/)){**
    name
}

it should return node C, but it doesn’t return any node.
did I do the right thing? or there is any way to reach what I want.
I use dgraph1.1 and on win10
Thanks anyway

You would never have this result using regex. Because all other emails have ‘Address’. Soon they will be excluded as well.

You can try like this:

{
#I'm not saying you have to use hass. Just an example.
  A as q(func: has(email)){ 
    email
  }
  
  RS as result(func: uid(A)) @filter(regexp(email, /Address/)){
  email
 }
  
  result2(func: uid(A)) @filter(NOT uid(RS)){
    email
 }

}

Result

{
  "data": {
    "q": [
      {
        "email": "testaddress3@gmail.com"
      },
      {
        "email": "testAddress1@gmail.com"
      },
      {
        "email": "testAddress2@gmail.com"
      }
    ],
    "result": [
      {
        "email": "testAddress1@gmail.com"
      },
      {
        "email": "testAddress2@gmail.com"
      }
    ],
    "result2": [
      {
        "email": "testaddress3@gmail.com"
      }
    ]
  }
}
1 Like

Thanks for your response. the way you suggested works well.
But I still confuse where I was wrong. The regexp operation is case sensitive, so I think @filter(NOT regexp(email, /Address/) should not exclude all email for that the last email contains “address” not “Address”.

Weird, I thought I was right. But it’s actually working the way you wanted it to. Maybe it was some typo.

See (the result 3):

{
  A as q(func: has(email)){
    email
  }
  
  RS as result(func: uid(A)) @filter(regexp(email, /Address/)){
  email
}
  
  result2(func: uid(A)) @filter(NOT uid(RS)){
    email
}
  result3(func: uid(A)) @filter(NOT regexp(email, /Address/)){
    email
}
}

Result

{
  "data": {
    "q": [
      {
        "email": "testaddress3@gmail.com"
      },
      {
        "email": "testAddress1@gmail.com"
      },
      {
        "email": "testAddress2@gmail.com"
      }
    ],
    "result": [
      {
        "email": "testAddress1@gmail.com"
      },
      {
        "email": "testAddress2@gmail.com"
      }
    ],
    "result2": [
      {
        "email": "testaddress3@gmail.com"
      }
    ],
    "result3": [
      {
        "email": "testaddress3@gmail.com"
      }
    ]
  }
}

Yeah, that’s really wired. I try it again.
This is my schema:
%E5%9B%BE%E7%89%87
This is the data:

{
  set{
    _:cust1 <name> "Alice" .
    _:cust1 <email> "testAddress1@gmail.com" .
    _:cust2 <name> "Beney" .
    _:cust2 <email> "testAddress2@gmail.com" .
    _:cust3 <name> "Charly" .
    _:cust3 <email> "testaddress3@gmail.com" .
    }
}

%E5%9B%BE%E7%89%87
And this is the result I got using the same query as yours:
%E5%9B%BE%E7%89%87
This is the log:
%E5%9B%BE%E7%89%87
Is there any difference between our operation? Did I do anything wrong?

I can’t see the logs, too small

I’ve droped the DB and rerun with your dataset. Same result.

Just like what you did, I did that test on an entirly new DB. This is the log, I hope it will be help.
The log from zero:


The log from alpha

I must do something wrong, but I can’t find it:rofl:

Can you try on Docker?
I’m on Mac, also tested on Docker. Not on Windows.
You can also try to run Dgraph with Microsoft’s WSL.

OK, I will try it and I think it will work on Docker or WSL. But I still want to know why it doesn’t work on win10.
Thanks anyway.

Very hard to tell. But if that’s reproducible (And easy to reproduce) in any Windows env. So it’s a bug and an issue must be filled so we can track it and solve it.

We recently had problems with the windows file system. And to solve it took a while, because nobody on the team uses Windows. Dgraph supports Windows, but for tests and study usage. We do not recommend creating a Windows cluster. Although you can do it. In that case, I would recommend using WSL to avoid problems. We have never tested WSL, but it seems safe.

Cheers.

I retried it on the Docker today, and I got the same error result.
this is my rdf file and schema file:
regexp_test.rdf (233 Bytes)
regexp_test.schema (134 Bytes)

I dropped my DB and started a totally new one. Then I used dgraph live to inport the data.

And the same query as we did the day before yestoday and got the error result

Now I’m really confused…

Okay, I found the reason behind this

I was using a very recent binary based on the Master branch. In recent weeks there have been changes to the Regex code from some issues resolved by Core Devs. So that explains why I couldn’t reproduce your case. You are using a v1.1.0 release and I am using Master. I did the test here to prove it works in Master but not in v1.1.0.

So it is solved. Wait for a new release that this will come fixed.

PS. The repo download the 1.1.0 version. So the issue will happen if you just try it out. If you need to test with master, you need to Build it from master.

Thank you very much. That’s so happy for knowing what happed.:+1::+1::+1::+1: