Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Query): Add random keyword in DQL #7693

Merged
merged 3 commits into from
Apr 25, 2021

Conversation

Samyak2
Copy link

@Samyak2 Samyak2 commented Apr 7, 2021

Fixes: https://discuss.dgraph.io/t/pick-random-node/10815

Changes

  • random nodes can be selected from the graph using random: <number of nodes>
  • random selection by replacement is used to select nodes

Issues/future work

  • Since selection is by replacement, you can get duplicates
  • No error handling yet in the applyRandom function
  • Making of new slice in lines 2430-2432 looks a little inefficient, there might a better way to do this.

This is my first PR here (and I'm new to Go), there will be a lot more issues I'm not aware of.

Example

I have only tested this on a basic example from Ratel. This will need a lot more testing.

Mutation
{
  set {
   _:luke <name> "Luke Skywalker" .
   _:luke <dgraph.type> "Person" .
   _:leia <name> "Princess Leia" .
   _:leia <dgraph.type> "Person" .
   _:han <name> "Han Solo" .
   _:han <dgraph.type> "Person" .
   _:lucas <name> "George Lucas" .
   _:lucas <dgraph.type> "Person" .
   _:irvin <name> "Irvin Kernshner" .
   _:irvin <dgraph.type> "Person" .
   _:richard <name> "Richard Marquand" .
   _:richard <dgraph.type> "Person" .

   _:sw1 <name> "Star Wars: Episode IV - A New Hope" .
   _:sw1 <release_date> "1977-05-25" .
   _:sw1 <revenue> "775000000" .
   _:sw1 <running_time> "121" .
   _:sw1 <starring> _:luke .
   _:sw1 <starring> _:leia .
   _:sw1 <starring> _:han .
   _:sw1 <director> _:lucas .
   _:sw1 <dgraph.type> "Film" .

   _:sw2 <name> "Star Wars: Episode V - The Empire Strikes Back" .
   _:sw2 <release_date> "1980-05-21" .
   _:sw2 <revenue> "534000000" .
   _:sw2 <running_time> "124" .
   _:sw2 <starring> _:luke .
   _:sw2 <starring> _:leia .
   _:sw2 <starring> _:han .
   _:sw2 <director> _:irvin .
   _:sw2 <dgraph.type> "Film" .

   _:sw3 <name> "Star Wars: Episode VI - Return of the Jedi" .
   _:sw3 <release_date> "1983-05-25" .
   _:sw3 <revenue> "572000000" .
   _:sw3 <running_time> "131" .
   _:sw3 <starring> _:luke .
   _:sw3 <starring> _:leia .
   _:sw3 <starring> _:han .
   _:sw3 <director> _:richard .
   _:sw3 <dgraph.type> "Film" .

   _:st1 <name> "Star Trek: The Motion Picture" .
   _:st1 <release_date> "1979-12-07" .
   _:st1 <revenue> "139000000" .
   _:st1 <running_time> "132" .
   _:st1 <dgraph.type> "Film" .
  }
}

Query

{
  q(func: type(Person), random: 5) {
    name
    uid
  }
}

Result

  "data": {
    "q": [
      {
        "name": "Luke Skywalker",
        "uid": "0x7538"
      },
      {
        "name": "Luke Skywalker",
        "uid": "0x7538"
      },
      {
        "name": "George Lucas",
        "uid": "0x7539"
      },
      {
        "name": "Princess Leia",
        "uid": "0x753c"
      },
      {
        "name": "Richard Marquand",
        "uid": "0x7535"
      }
    ]
  }

This change is Reviewable

@CLAassistant
Copy link

CLAassistant commented Apr 7, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahsanbarkati -- can you work on the comment I have.

Thanks @Samyak2 for the PR. This is a good and clean PR, nicely written. @ahsanbarkati would help fix up the filter case I'm talking about.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @Samyak2)


query/query.go, line 2422 at r1 (raw file):

// TODO: error handling here
func (sg *SubGraph) applyRandom(ctx context.Context) error {
	sg.updateUidMatrix()

This should be done in the same way as we do first: N. So, if we have a filter, then we need to apply the filter first, and then choose N random nodes.

Copy link
Contributor

@ahsanbarkati ahsanbarkati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @Samyak2. I have a few comments. Also, can we please add some tests? Do let me know if you need some help.

query/query.go Outdated
@@ -2395,6 +2414,34 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) {
rch <- childErr
}

// applies "random" to lists inside uidMatrix
// Params.Random number of nodes are selected
// duplicates are not removed i.e., random selection by replacement is done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not have duplicate results. I'd suggest having some map to keep track of what all we have already picked to randomly pick n unique results.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll do this, along with the filters application.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to do anything for filters. You are already doing the random selection after filter application and pagination.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay. That explains why I couldn't figure out how to do it by looking at pagination xD.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed a commit fixing these.

To remove duplicates, I had to:

  • introduce a new struct UidKey to store the index of a UID in the matrix
  • calculate total number of nodes and check if required number of nodes is less than that. If it's not, return all the nodes.

Because of the condition if sg.Params.Random >= totalNodes at line 2440, when the required number of nodes (sg.Params.Random) is equal to the total number of nodes, all of the nodes are returned without any processing. I did this thinking of it as an optimization (because there will be many overlaps in random numbers when only a few nodes are left to be selected). But I just realized that this will make it so that the order is not randomized when sg.Params.Random == totalNodes. Should I fix this to do the random selection even when all the nodes have to be selected?

query/query.go Outdated Show resolved Hide resolved
…e random_

To remove duplicates, I had to:
 - introduce a new struct `UidKey` to store the index of a UID in the
   matrix
 - calculate total number of nodes and check if required number of nodes
   is less than that. If it's not, return all the nodes.
 - one caveat is that the order is not randomized when the requested
   number is equal to total number of nodes.
Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @ahsanbarkati and @Samyak2)


query/query.go, line 2432 at r2 (raw file):

	// calculate total number of nodes
	totalNodes := 0

Had an initial look and I have some comments.

  1. I don't think we have to worry about duplicates here because a uid list within a uid matrix doesn't have any duplicates. Yes there could be duplicate uid within two different uids lists but we dont have to worry about that.
  2. @ahsanbarkati we should add some tests for this feature and how it works at root and at a child level.
  3. I reckon we can simplify this to just truncate all the uid lists with random elements in place instead of creating a new list.

Copy link
Contributor

@ahsanbarkati ahsanbarkati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @ahsanbarkati, @pawanrawal, and @Samyak2)


query/query.go, line 2432 at r2 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Had an initial look and I have some comments.

  1. I don't think we have to worry about duplicates here because a uid list within a uid matrix doesn't have any duplicates. Yes there could be duplicate uid within two different uids lists but we dont have to worry about that.
  2. @ahsanbarkati we should add some tests for this feature and how it works at root and at a child level.
  3. I reckon we can simplify this to just truncate all the uid lists with random elements in place instead of creating a new list.

@pawanrawal In the current approach, the way random nodes are selected is by repeatedly choosing a random index. So, even if there is just one uid list in the uidMatrix and it has all unique values, we'll end up with duplicates. Is that something acceptable?

Copy link
Contributor

@ahsanbarkati ahsanbarkati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is one issue with your approach. Suppose the query is for k random nodes, then you are selecting k nodes out of the whole UidMatrix. This is not the right thing to do.

You need to pick k random uids for each UidList in the UidMatrix. To make it clear, let me give you an example:

Suppose you run this query:

{
 q2(func: has(name), random:5) {
  		name
  		uid
  		friend(random: 2) { 
                           name
                }
    }
}

In the first go, we fetch all the Uids having the name predicate. In this case the UidMatrix will contain only one UidList. In the next iteration, when we'll fetch stuff for the children, for each uid in the UidList of uids containing name predicate, we'll get another uidList (list of Uids containing friends for the given UID).

So, you'll need to apply this random selection on each list rather than on complete UIdMatrix.

Secondly, as suggested by @pawanrawal, within a UidList, in order to select k random Uids. We can select a window of length k with random start index. We know that this will reduce the randomness but since we are doing this selection on Uids, it should be fine.

We'd love to merge your changes once this issue is addressed.

Also, we'd need some tests. It'd be great if you add some tests otherwise I'll all tests after merging your PR.

Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @ahsanbarkati, @pawanrawal, and @Samyak2)

@ahsanbarkati ahsanbarkati marked this pull request as ready for review April 21, 2021 20:27
@ahsanbarkati
Copy link
Contributor

Are you still working on this PR @Samyak2? If not, then I can merge your changes and then I can do the fixes in next PR.

@Samyak2
Copy link
Author

Samyak2 commented Apr 22, 2021

Yes, I'm still working on it. Sorry, I couldn't do it in the last week because of the end sem workload from college 😄.
I will implement your suggestions by tonight (IST).

@ahsanbarkati
Copy link
Contributor

Awesome! Thanks @Samyak2.

the random uids are now selected from each uid list instead of
the uid matrix. This simplifies the process.
@Samyak2
Copy link
Author

Samyak2 commented Apr 22, 2021

@ahsanbarkati thank you for the explanation, it makes a lot more sense now.

I have implemented your suggestions in the latest commit:

  • k random uids are now selected from each uid list instead of the whole matrix
  • for in-place selection, I have first shuffled the list (in-place) using rand.Shuffle and then selected the first k elements. Would it be better to just select a random window here instead of the shuffling the list? Are uids guaranteed to be ordered randomly in the list?

I will look at adding tests for these now.

@Samyak2
Copy link
Author

Samyak2 commented Apr 25, 2021

I had a few issues while running the tests:

  • The contributing guidelines instruct to run test.sh whereas the script is apparently deprecated and t/t.go is to be used instead. Should this be updated in the guidelines?
  • I get an error while running the tests with ./t or ./t -s -p "query"
Output of `./t`
testutil: "" localhost:9080 localhost:5080
Proc ID is 992
Installing dgraph ...
make[1]: Entering directory '/home/samyak/PESU/Sem6/HP/Project/dgraph/dgraph'
Commit SHA256: a44abf8587f4c26714952c45a05aedff1373ab13
Old SHA256: 561df6fcce9beff32df455feed232cf4b9d1a726fed7a4ca93abf44613ab7260
New SHA256: 561df6fcce9beff32df455feed232cf4b9d1a726fed7a4ca93abf44613ab7260
make[1]: Leaving directory '/home/samyak/PESU/Sem6/HP/Project/dgraph/dgraph'
compiling plugin: src="./custom_plugins/anagram/main.go" so="./custom_plugins/0.so"
compiling plugin: src="./custom_plugins/cidr/main.go" so="./custom_plugins/1.so"
compiling plugin: src="./custom_plugins/factor/main.go" so="./custom_plugins/2.so"
compiling plugin: src="./custom_plugins/rune/main.go" so="./custom_plugins/3.so"
plugin build completed. Files are: /home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/0.so,/home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/1.so,/home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/2.so,/home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/3.so
Skipping package github.com/dgraph-io/dgraph/systest/1million as its not valid for the selected suite unit 
Skipping package github.com/dgraph-io/dgraph/systest/21million/bulk as its not valid for the selected suite unit 
Skipping package github.com/dgraph-io/dgraph/systest/21million/live as its not valid for the selected suite unit 
Skipping package github.com/dgraph-io/dgraph/systest/bgindex as its not valid for the selected suite unit 
Skipping package github.com/dgraph-io/dgraph/systest/bulk_live/bulk as its not valid for the selected suite unit 
Skipping package github.com/dgraph-io/dgraph/systest/bulk_live/live as its not valid for the selected suite unit 
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/alpha isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/alpha/mutations_mode isCommon:false
Found valid task: github.com/dgraph-io/dgraph/ee/acl isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/admin_auth/poorman_auth isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/admin_auth/poorman_auth_with_acl isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/auth isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/auth/debug_off isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/auth_closed_by_default isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/common isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/custom_logic isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/custom_logic/cmd isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/directives isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/multi_tenancy isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/normal isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/schema isCommon:false
Found valid task: github.com/dgraph-io/dgraph/graphql/e2e/subscription isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest isCommon:true
Found valid task: github.com/dgraph-io/dgraph/systest/21million/common isCommon:true
Found valid task: github.com/dgraph-io/dgraph/systest/audit isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/backup/common isCommon:true
Found valid task: github.com/dgraph-io/dgraph/systest/backup/encryption isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/backup/filesystem isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/backup/minio isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/backup/minio-large isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/backup/multi-tenancy isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/bulk_live/common isCommon:true
Found valid task: github.com/dgraph-io/dgraph/systest/cdc isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/export isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/group-delete isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/license isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/loader isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/multi-tenancy isCommon:true
Found valid task: github.com/dgraph-io/dgraph/systest/online-restore isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/plugin isCommon:false
Found valid task: github.com/dgraph-io/dgraph/systest/posting-list-benchmark isCommon:true
Found valid task: github.com/dgraph-io/dgraph/worker isCommon:false
Found valid task: github.com/dgraph-io/dgraph/ee/audit isCommon:true
Found valid task: github.com/dgraph-io/dgraph/ee/backup isCommon:true
Found valid task: github.com/dgraph-io/dgraph/ee/enc isCommon:true
Found valid task: github.com/dgraph-io/dgraph/filestore isCommon:true
Found valid task: github.com/dgraph-io/dgraph/gql isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/admin isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/api isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/authorization isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/bench isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/dgraph isCommon:true
Found valid task: github.com/dgraph-io/dgraph/compose isCommon:true
Found valid task: github.com/dgraph-io/dgraph/conn isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/embargo isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/integration/acctupsert isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/integration/bank isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/integration/bigdata isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/integration/mutates isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/integration/swap isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/integration/testtxn isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/jepsen isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/jepsen/browser isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/neo4j-converter isCommon:true
Found valid task: github.com/dgraph-io/dgraph/contrib/teamcity isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/resolve isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/schema isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/subscription isCommon:true
Found valid task: github.com/dgraph-io/dgraph/graphql/test isCommon:true
Found valid task: github.com/dgraph-io/dgraph/lex isCommon:true
Found valid task: github.com/dgraph-io/dgraph/posting isCommon:true
Found valid task: github.com/dgraph-io/dgraph/protos isCommon:true
Found valid task: github.com/dgraph-io/dgraph/protos/pb isCommon:true
Found valid task: github.com/dgraph-io/dgraph/query isCommon:true
Found valid task: github.com/dgraph-io/dgraph/raftwal isCommon:true
Found valid task: github.com/dgraph-io/dgraph/schema isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph isCommon:false
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd isCommon:true
Found valid task: github.com/dgraph-io/dgraph/algo isCommon:true
Found valid task: github.com/dgraph-io/dgraph/chunker isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/bulk isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/cert isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/conv isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/debug isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/debuginfo isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/decrypt isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/increment isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/live isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/live/load-json isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/live/load-uids isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/migrate isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/version isCommon:true
Found valid task: github.com/dgraph-io/dgraph/dgraph/cmd/zero isCommon:true
Found valid task: github.com/dgraph-io/dgraph/edgraph isCommon:true
Found valid task: github.com/dgraph-io/dgraph/ee isCommon:true
Found valid task: github.com/dgraph-io/dgraph/t isCommon:true
Found valid task: github.com/dgraph-io/dgraph/task isCommon:true
Found valid task: github.com/dgraph-io/dgraph/telemetry isCommon:true
Found valid task: github.com/dgraph-io/dgraph/testutil isCommon:true
Found valid task: github.com/dgraph-io/dgraph/testutil/custom_plugins/anagram isCommon:true
Found valid task: github.com/dgraph-io/dgraph/testutil/custom_plugins/cidr isCommon:true
Found valid task: github.com/dgraph-io/dgraph/testutil/custom_plugins/factor isCommon:true
Found valid task: github.com/dgraph-io/dgraph/testutil/custom_plugins/rune isCommon:true
Found valid task: github.com/dgraph-io/dgraph/tlstest/acl isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/certrequest isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/certrequireandverify isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/certverifyifgiven isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/mtls_internal/ha_6_node isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/mtls_internal/multi_group isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/mtls_internal/single_node isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/zero_https/all_routes_tls isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tlstest/zero_https/no_tls isCommon:false
Found valid task: github.com/dgraph-io/dgraph/tok isCommon:true
Found valid task: github.com/dgraph-io/dgraph/types isCommon:true
Found valid task: github.com/dgraph-io/dgraph/types/facets isCommon:true
Found valid task: github.com/dgraph-io/dgraph/upgrade isCommon:true
Found valid task: github.com/dgraph-io/dgraph/codec isCommon:true
Found valid task: github.com/dgraph-io/dgraph/x isCommon:true
Found valid task: github.com/dgraph-io/dgraph/xidmap isCommon:true
Running tests for 114 packages.
Sent 1/114 packages for processing.
Sent 2/114 packages for processing.
Sent 3/114 packages for processing.
Bringing up cluster for package: github.com/dgraph-io/dgraph/dgraph/cmd/alpha/mutations_mode
Bringing up cluster test-992-3 for package: ../dgraph/docker-compose.yml ...
Bringing up cluster test-992-4 for package: ../dgraph/cmd/alpha/mutations_mode/docker-compose.yml ...
Bringing up cluster test-992-1 for package: ../dgraph/docker-compose.yml ...
While running command: "docker-compose -f ../dgraph/cmd/alpha/mutations_mode/docker-compose.yml -p test-992-4 up --force-recreate --build --remove-orphans --detach" Error: exit status 1
While running command: "docker-compose -f ../dgraph/docker-compose.yml -p test-992-3 up --force-recreate --build --remove-orphans --detach" Error: exit status 1
Running: /usr/bin/go test -failfast -v -timeout 30m github.com/dgraph-io/dgraph/ee/acl with test-992-3
While running command: "docker-compose -f ../dgraph/docker-compose.yml -p test-992-1 up --force-recreate --build --remove-orphans --detach" Error: exit status 1
Running: /usr/bin/go test -failfast -v -timeout 30m github.com/dgraph-io/dgraph/dgraph/cmd/alpha with test-992-1
CLUSTER DOWN: test-992-2
Docker logs for 920caef178652bd66a2bf1fb5d7eb1ccbe264fa6e621d52fb60938da2a1adeea is  with error <nil> Docker logs for 20b6a230eb352e3f96da8ff3deb80a65775c6b958d220859955efdee18a8e2bc is  with error <nil> Docker logs for e4db5f70782008a84da392ff6f52cf6078cffb26c2dcb2657342086e96b9c839 is  with error <nil> Docker logs for ba22ea8565f359669552332bcb8b2dcd35744ef44b9002abdbd3ce78c15fb4c2 is  with error <nil> CLUSTER DOWN: test-992-1
CLUSTER DOWN: test-992-3
TIMELINE starting at 10:57:02 PM
[    3s][0] COMPILE took: 3s
[   15s]   [1] DONE took: 10s
[   17s]      [2] DONE took: 13s
[   17s]         [3] DONE took: 13s
Got error: exit status 1.
Tests FAILED.

Output of `./t -s -p "query"`
testutil: "" localhost:9080 localhost:5080
Proc ID is 674
Installing dgraph ...
make[1]: Entering directory '/home/samyak/PESU/Sem6/HP/Project/dgraph/dgraph'
Commit SHA256: a44abf8587f4c26714952c45a05aedff1373ab13
Old SHA256: 561df6fcce9beff32df455feed232cf4b9d1a726fed7a4ca93abf44613ab7260
New SHA256: 561df6fcce9beff32df455feed232cf4b9d1a726fed7a4ca93abf44613ab7260
make[1]: Leaving directory '/home/samyak/PESU/Sem6/HP/Project/dgraph/dgraph'
compiling plugin: src="./custom_plugins/anagram/main.go" so="./custom_plugins/0.so"
compiling plugin: src="./custom_plugins/cidr/main.go" so="./custom_plugins/1.so"
compiling plugin: src="./custom_plugins/factor/main.go" so="./custom_plugins/2.so"
compiling plugin: src="./custom_plugins/rune/main.go" so="./custom_plugins/3.so"
plugin build completed. Files are: /home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/0.so,/home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/1.so,/home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/2.so,/home/samyak/PESU/Sem6/HP/Project/dgraph/t/custom_plugins/3.so
Found valid task: github.com/dgraph-io/dgraph/query isCommon:true
Running tests for 1 packages.
Sent 1/1 packages for processing.
Bringing up cluster test-674-1 for package: ../dgraph/docker-compose.yml ...
While running command: "docker-compose -f ../dgraph/docker-compose.yml -p test-674-1 up --force-recreate --build --remove-orphans --detach" Error: exit status 1
Running: /usr/bin/go test -failfast -v -timeout 30m github.com/dgraph-io/dgraph/query with test-674-1
Docker logs for 40d1a1d2875351cd217fabb25f8ecdd97217ac88d469bb2f12a702e2a50b138d is  with error <nil> Docker logs for 4c6d3d33ac7be1e98813fe6decf32e5c6f3ebc0b45e385dc8cf02acd6bf8d09b is  with error <nil> CLUSTER DOWN: test-674-1
TIMELINE starting at 10:58:11 PM
[    2s][0] COMPILE took: 2s
[   10s]   [1] DONE took: 7s
Got error: While running command: [go test -failfast -v -timeout 30m github.com/dgraph-io/dgraph/query] Error: context canceled.
Tests FAILED.

I tried rebasing on master, the error persists.

@ahsanbarkati
Copy link
Contributor

ahsanbarkati commented Apr 25, 2021

Awesome @Samyak2. Thanks for the nice work. Your changes looks good to me. I am just concerned if there will be performance issues by using rand.Shuffle(). But that is a part of the next step. This change is good to go into master.

Regarding the test, it seems like your docker is unable to spin up the containers. Can you try running docker-compose up in the dgraph directory.

Other thing to look at is by running ./t -p query -k this will keep your containers and then you can look into the logs if there is some issue.

By the way, I see that the CI has run fine.

@ahsanbarkati
Copy link
Contributor

I am merging this PR, so that we can do further development/testing of the feature. Feel free to raise another PR with the tests. :)

@ahsanbarkati ahsanbarkati merged commit 0b01441 into dgraph-io:master Apr 25, 2021
@Samyak2
Copy link
Author

Samyak2 commented Apr 25, 2021

Regarding the test, it seems like your docker is unable to spin up the containers. Can you try running docker-compose up in the dgraph directory.
Other thing to look at is by running ./t -p query -k this will keep your containers and then you can look into the logs if there is some issue.

Okay, I will try debugging this.

I am merging this PR, so that we can do further development/testing of the feature. Feel free to raise another PR with the tests. :)

Thank you! 😄
I will send another PR if I can figure out the tests issue.

@Samyak2
Copy link
Author

Samyak2 commented Jun 25, 2021

@ahsanbarkati I see you have added the tests in #7758! Are there any other tests to add here? If not, I could try fixing the performance issues by not using rand.Shuffle().

Also, is there a timeline on when this feature will be released?

@MichelDiz MichelDiz added cherry-pick v22.0.0 Issues related to v22.0.0 community Issue or PR created by the community. labels Oct 24, 2022
mangalaman93 added a commit that referenced this pull request Aug 25, 2023
This change implements the `random` function argument.
If an argument `random: k` is provided to a dql function then
random k results will be returned.

For example:
`func(has(name), random:5)` will choose 5 random nodes having
the name predicate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick community Issue or PR created by the community. v22.0.0 Issues related to v22.0.0
Development

Successfully merging this pull request may close these issues.

6 participants