{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-java/pulls/comments/52866680","id":52866680,"diff_hunk":"@@ -1657,6 +1657,91 @@ public void distinctAsync_notIndexedLinkedFields() {\n         }\n     }\n \n+    /*\n+     * The idea is to interweave different values in 2's multiplier and 3's multiplier in a way that\n+     * the outcome is different if the order of distinct* operations alternates.\n+     * An example is illustrated below.\n+     *\n+     * Object        : O1| O2| O3| O4| O5| O6\n+     * indexedString : A | A | B | B | A | A\n+     * indexedLong   : 1 | 1 | 1 | 2 | 2 | 2\n+     *\n+     * Suppose we're to execute distinct(\"indexedString\").distinct(\"indexedLong\"), the outcome\n+     * should be O1(A, 1) and total count is 1 since distinct takes the first element when two\n+     * elements are identical.\n+     *\n+     * In case of distinct(\"indexedLong\").distinct(\"indexedString\"), the outcome should be\n+     * O1(A,1) and O2(B,2) so total count is 2.\n+     *\n+     */\n+    private void populateForChainedOperation(Realm realm, long numberOfBlocks) {\n+        realm.beginTransaction();\n+        for (int i = 0; i < numberOfBlocks; i++) {\n+            for (int j = 0; j < 6; j++) {\n+                AnnotationIndexTypes obj = realm.createObject(AnnotationIndexTypes.class);\n+                obj.setIndexString((((j / 2) % 2) == 0) ? \"A\" : \"B\");\n+                obj.setIndexLong((j < 3) ? 1 : 2);\n+            }\n+        }\n+        realm.commitTransaction();\n+    }\n+\n+    @Test\n+    public void distinct_checkChainedOpertionValidity() {\n+        final long numberOfBlocks = 1; // must be greater than 1\n+        populateForChainedOperation(realm, numberOfBlocks);\n+\n+        final RealmResults<AnnotationIndexTypes> distinctStringAndLong = realm.where(AnnotationIndexTypes.class).findAll().distinct(\"indexString\").distinct(\"indexLong\");\n+        final RealmResults<AnnotationIndexTypes> distinctLongAndString = realm.where(AnnotationIndexTypes.class).findAll().distinct(\"indexLong\").distinct(\"indexString\");\n+        assertEquals(\"distinctStringAndLong\", 1, distinctStringAndLong.size());\n+        assertEquals(\"distinctLongAndString\", 2, distinctLongAndString.size());\n+    }\n+\n+    @Test\n+    @RunTestInLooperThread\n+    public void distinctAsync_checkChainedOpertionValidity() throws Throwable {\n+        final AtomicInteger changeListenerCalled = new AtomicInteger(2);\n+        final Realm realm = looperThread.realm;\n+        final long numberOfBlocks = 1; // must be greater than 1\n+        populateForChainedOperation(realm, numberOfBlocks);\n+\n+        final RealmResults<AnnotationIndexTypes> distinctStringAndLong = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(\"indexString\").distinctAsync(\"indexLong\");\n+        final RealmResults<AnnotationIndexTypes> distinctLongAndString = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(\"indexLong\").distinctAsync(\"indexString\");\n+","path":"realm/realm-library/src/androidTest/java/io/realm/RealmResultsTests.java","position":54,"original_position":54,"commit_id":"6a7f7657f007bf102af1226eca656cc6172fee9a","original_commit_id":"6a7f7657f007bf102af1226eca656cc6172fee9a","user":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"body":"In terms of API representation, two two lines work as \r\n`Table.where().findAll()` -> `TableView.where().getTable().getDistinctView()` -> `TableView.where().getTable().getDistinctView()` (The last two `TableView` are different ones).","created_at":"2016-02-15T07:27:32Z","updated_at":"2016-02-15T07:27:32Z","html_url":"https://github.com/realm/realm-java/pull/2260#discussion_r52866680","pull_request_url":"https://api.github.com/repos/realm/realm-java/pulls/2260","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments/52866680"},"html":{"href":"https://github.com/realm/realm-java/pull/2260#discussion_r52866680"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2260"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/2260","id":59040531,"html_url":"https://github.com/realm/realm-java/pull/2260","diff_url":"https://github.com/realm/realm-java/pull/2260.diff","patch_url":"https://github.com/realm/realm-java/pull/2260.patch","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2260","number":2260,"state":"open","locked":false,"title":"Chained distinct/distintAsync calls does not yield expected results","user":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"body":"The idea is to interweave different values in 2's multiplier and 3's multiplier in a way that\r\nthe outcome is different if the order of distinct* operations alternates.\r\n\r\nAn example is illustrated below.\r\n\r\n```\r\nObject        : O1| O2| O3| O4| O5| O6\r\nindexedString : A | A | B | B | A | A\r\nindexedLong   : 1 | 1 | 1 | 2 | 2 | 2\r\n```\r\n\r\nSuppose we are to execute `realm.where(Foo.class).findAll().distinct(\"indexedString\").distinct(\"indexedLong\")`, the outcome might be O1(A, 1) and the total count should be one (1) since distinct takes the first element when two elements are identical.\r\n\r\nIn case of `realm.where(Foo.class).findAll().distinct(\"indexedLong\").distinct(\"indexedString\")`, the outcome would be O1(A,1) and O2(B,2) and the total count should two (2). Similar outcome is expected to chained `distinctAsync()`.\r\n\r\n","created_at":"2016-02-11T14:49:16Z","updated_at":"2016-02-15T07:27:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d45a733cb4456420f88f93dfc3eb7c47f30f5be5","assignee":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-java/pulls/2260/commits","review_comments_url":"https://api.github.com/repos/realm/realm-java/pulls/2260/comments","review_comment_url":"https://api.github.com/repos/realm/realm-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2260/comments","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/6a7f7657f007bf102af1226eca656cc6172fee9a","head":{"label":"realm:stk/distinct_chainedcall","ref":"stk/distinct_chainedcall","sha":"6a7f7657f007bf102af1226eca656cc6172fee9a","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-02-15T04:33:08Z","pushed_at":"2016-02-15T05:39:19Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":46002,"stargazers_count":3608,"watchers_count":3608,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":409,"mirror_url":null,"open_issues_count":217,"forks":409,"open_issues":217,"watchers":3608,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"ef78fd05824a9ea426b6f829c17c2ad9bb48694f","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-02-15T04:33:08Z","pushed_at":"2016-02-15T05:39:19Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":46002,"stargazers_count":3608,"watchers_count":3608,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":409,"mirror_url":null,"open_issues_count":217,"forks":409,"open_issues":217,"watchers":3608,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2260"},"html":{"href":"https://github.com/realm/realm-java/pull/2260"},"issue":{"href":"https://api.github.com/repos/realm/realm-java/issues/2260"},"comments":{"href":"https://api.github.com/repos/realm/realm-java/issues/2260/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2260/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2260/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-java/statuses/6a7f7657f007bf102af1226eca656cc6172fee9a"}}}}