The NOT doesn't work for regexp in filter


(Lee Hui) #1

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


(Michel Conrado) #2

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"
      }
    ]
  }
}

(Lee Hui) #3

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”.


(Michel Conrado) #4

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"
      }
    ]
  }
}

(Lee Hui) #5

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?


(Michel Conrado) #6

I can’t see the logs, too small

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


(Lee Hui) #7

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:


(Michel Conrado) #8

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.


(Lee Hui) #9

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.


(Michel Conrado) #10

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.