{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/presto/pulls/comments/51773403","id":51773403,"diff_hunk":"@@ -0,0 +1,172 @@\n+/*\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.facebook.presto.jdbc;\n+\n+import com.facebook.presto.client.ClientTypeSignature;\n+import com.facebook.presto.client.Column;\n+import com.facebook.presto.client.QueryResults;\n+import com.facebook.presto.client.StatementStats;\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+import com.google.common.base.Throwables;\n+import com.google.common.collect.ImmutableList;\n+import com.google.common.collect.ImmutableListMultimap;\n+import io.airlift.http.client.HttpStatus;\n+import io.airlift.http.client.Request;\n+import io.airlift.http.client.Response;\n+import io.airlift.http.client.testing.TestingHttpClient;\n+import io.airlift.http.client.testing.TestingResponse;\n+import org.testng.annotations.Test;\n+\n+import java.io.StringWriter;\n+import java.net.URI;\n+import java.sql.Connection;\n+import java.sql.ResultSet;\n+import java.sql.ResultSetMetaData;\n+import java.sql.Statement;\n+import java.util.List;\n+import java.util.function.Consumer;\n+\n+import static com.google.common.base.Preconditions.checkState;\n+import static io.airlift.testing.Assertions.assertGreaterThanOrEqual;\n+import static java.lang.String.format;\n+import static org.testng.Assert.assertEquals;\n+import static org.testng.Assert.assertFalse;\n+import static org.testng.Assert.assertTrue;\n+\n+@Test(singleThreaded = true)\n+public class TestProgressMonitor\n+{\n+    private static final String SERVER_ADDRESS = \"127.0.0.1:8080\";\n+\n+    private static final String QUERY_ID = \"20160128_214710_00012_rk68b\";\n+    private static final String INFO_URI = \"http://\" + SERVER_ADDRESS + \"/v1/query/\" + QUERY_ID;\n+    private static final String PARTIAL_CANCEL_URI = \"http://\" + SERVER_ADDRESS + \"/v1/stage/\" + QUERY_ID + \".%d\";\n+    private static final String NEXT_URI = \"http://\" + SERVER_ADDRESS + \"/v1/statement/\" + QUERY_ID + \"/%d\";\n+    private static final List<Column> RESPONSE_COLUMNS = ImmutableList.of(new Column(\"_col0\", \"bigint\", new ClientTypeSignature(\"bigint\", ImmutableList.of())));\n+    private static final List<String> RESPONSES = ImmutableList.of(\n+            newQueryResults(null, 1, null, null, \"QUEUED\"),\n+            newQueryResults(1, 2, RESPONSE_COLUMNS, null, \"RUNNING\"),\n+            newQueryResults(1, 3, RESPONSE_COLUMNS, null, \"RUNNING\"),\n+            newQueryResults(0, 4, RESPONSE_COLUMNS, ImmutableList.of(ImmutableList.of(253161)), \"RUNNING\"),\n+            newQueryResults(null, null, RESPONSE_COLUMNS, null, \"FINISHED\"));\n+\n+    private static String newQueryResults(Integer partialCancelId, Integer nextUriId, List<Column> responseColumns, List<List<Object>> data, String state)\n+    {\n+        try {\n+            QueryResults queryResults = new QueryResults(\n+                    QUERY_ID,\n+                    new URI(INFO_URI),\n+                    partialCancelId == null ? null : new URI(String.format(PARTIAL_CANCEL_URI, partialCancelId)),\n+                    nextUriId == null ? null : new URI(String.format(NEXT_URI, nextUriId)),\n+                    responseColumns,\n+                    data,\n+                    new StatementStats(state, true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null),\n+                    null,\n+                    null,\n+                    null);\n+\n+            ObjectMapper mapper = new ObjectMapper();","path":"presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestProgressMonitor.java","position":79,"original_position":79,"commit_id":"250e242d3bdf38daeb6ba5eddd81e301ad216b95","original_commit_id":"250e242d3bdf38daeb6ba5eddd81e301ad216b95","user":{"login":"electrum","id":9230,"avatar_url":"https://avatars.githubusercontent.com/u/9230?v=3","gravatar_id":"","url":"https://api.github.com/users/electrum","html_url":"https://github.com/electrum","followers_url":"https://api.github.com/users/electrum/followers","following_url":"https://api.github.com/users/electrum/following{/other_user}","gists_url":"https://api.github.com/users/electrum/gists{/gist_id}","starred_url":"https://api.github.com/users/electrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrum/subscriptions","organizations_url":"https://api.github.com/users/electrum/orgs","repos_url":"https://api.github.com/users/electrum/repos","events_url":"https://api.github.com/users/electrum/events{/privacy}","received_events_url":"https://api.github.com/users/electrum/received_events","type":"User","site_admin":false},"body":"Make this a constant","created_at":"2016-02-03T19:29:31Z","updated_at":"2016-02-03T19:29:31Z","html_url":"https://github.com/facebook/presto/pull/4445#discussion_r51773403","pull_request_url":"https://api.github.com/repos/facebook/presto/pulls/4445","_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments/51773403"},"html":{"href":"https://github.com/facebook/presto/pull/4445#discussion_r51773403"},"pull_request":{"href":"https://api.github.com/repos/facebook/presto/pulls/4445"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/presto/pulls/4445","id":57586036,"html_url":"https://github.com/facebook/presto/pull/4445","diff_url":"https://github.com/facebook/presto/pull/4445.diff","patch_url":"https://github.com/facebook/presto/pull/4445.patch","issue_url":"https://api.github.com/repos/facebook/presto/issues/4445","number":4445,"state":"open","locked":false,"title":"Add query progress monitor to Presto JDBC client","user":{"login":"haozhun","id":2020503,"avatar_url":"https://avatars.githubusercontent.com/u/2020503?v=3","gravatar_id":"","url":"https://api.github.com/users/haozhun","html_url":"https://github.com/haozhun","followers_url":"https://api.github.com/users/haozhun/followers","following_url":"https://api.github.com/users/haozhun/following{/other_user}","gists_url":"https://api.github.com/users/haozhun/gists{/gist_id}","starred_url":"https://api.github.com/users/haozhun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haozhun/subscriptions","organizations_url":"https://api.github.com/users/haozhun/orgs","repos_url":"https://api.github.com/users/haozhun/repos","events_url":"https://api.github.com/users/haozhun/events{/privacy}","received_events_url":"https://api.github.com/users/haozhun/received_events","type":"User","site_admin":false},"body":"Originally, only progress of SELECT queries can be monitored. Additionally,\r\nprogress monitor is only possible after the list of output columns become\r\nknown.\r\n\r\nA callback mechanism is implemented in this commit so that users who want\r\naccess to query progress can register a listener before issuing the query.\r\nThe listener will periodically receive stats as the query makes progress.\r\nThis works for any query.","created_at":"2016-01-28T23:53:17Z","updated_at":"2016-02-03T19:29:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e17282af1183ea221410fedd3481c88b5e2c9b59","assignee":{"login":"electrum","id":9230,"avatar_url":"https://avatars.githubusercontent.com/u/9230?v=3","gravatar_id":"","url":"https://api.github.com/users/electrum","html_url":"https://github.com/electrum","followers_url":"https://api.github.com/users/electrum/followers","following_url":"https://api.github.com/users/electrum/following{/other_user}","gists_url":"https://api.github.com/users/electrum/gists{/gist_id}","starred_url":"https://api.github.com/users/electrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrum/subscriptions","organizations_url":"https://api.github.com/users/electrum/orgs","repos_url":"https://api.github.com/users/electrum/repos","events_url":"https://api.github.com/users/electrum/events{/privacy}","received_events_url":"https://api.github.com/users/electrum/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/facebook/presto/pulls/4445/commits","review_comments_url":"https://api.github.com/repos/facebook/presto/pulls/4445/comments","review_comment_url":"https://api.github.com/repos/facebook/presto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/presto/issues/4445/comments","statuses_url":"https://api.github.com/repos/facebook/presto/statuses/250e242d3bdf38daeb6ba5eddd81e301ad216b95","head":{"label":"haozhun:jdbc","ref":"jdbc","sha":"250e242d3bdf38daeb6ba5eddd81e301ad216b95","user":{"login":"haozhun","id":2020503,"avatar_url":"https://avatars.githubusercontent.com/u/2020503?v=3","gravatar_id":"","url":"https://api.github.com/users/haozhun","html_url":"https://github.com/haozhun","followers_url":"https://api.github.com/users/haozhun/followers","following_url":"https://api.github.com/users/haozhun/following{/other_user}","gists_url":"https://api.github.com/users/haozhun/gists{/gist_id}","starred_url":"https://api.github.com/users/haozhun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haozhun/subscriptions","organizations_url":"https://api.github.com/users/haozhun/orgs","repos_url":"https://api.github.com/users/haozhun/repos","events_url":"https://api.github.com/users/haozhun/events{/privacy}","received_events_url":"https://api.github.com/users/haozhun/received_events","type":"User","site_admin":false},"repo":{"id":31032158,"name":"presto","full_name":"haozhun/presto","owner":{"login":"haozhun","id":2020503,"avatar_url":"https://avatars.githubusercontent.com/u/2020503?v=3","gravatar_id":"","url":"https://api.github.com/users/haozhun","html_url":"https://github.com/haozhun","followers_url":"https://api.github.com/users/haozhun/followers","following_url":"https://api.github.com/users/haozhun/following{/other_user}","gists_url":"https://api.github.com/users/haozhun/gists{/gist_id}","starred_url":"https://api.github.com/users/haozhun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haozhun/subscriptions","organizations_url":"https://api.github.com/users/haozhun/orgs","repos_url":"https://api.github.com/users/haozhun/repos","events_url":"https://api.github.com/users/haozhun/events{/privacy}","received_events_url":"https://api.github.com/users/haozhun/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/haozhun/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":true,"url":"https://api.github.com/repos/haozhun/presto","forks_url":"https://api.github.com/repos/haozhun/presto/forks","keys_url":"https://api.github.com/repos/haozhun/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/haozhun/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/haozhun/presto/teams","hooks_url":"https://api.github.com/repos/haozhun/presto/hooks","issue_events_url":"https://api.github.com/repos/haozhun/presto/issues/events{/number}","events_url":"https://api.github.com/repos/haozhun/presto/events","assignees_url":"https://api.github.com/repos/haozhun/presto/assignees{/user}","branches_url":"https://api.github.com/repos/haozhun/presto/branches{/branch}","tags_url":"https://api.github.com/repos/haozhun/presto/tags","blobs_url":"https://api.github.com/repos/haozhun/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/haozhun/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/haozhun/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/haozhun/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/haozhun/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/haozhun/presto/languages","stargazers_url":"https://api.github.com/repos/haozhun/presto/stargazers","contributors_url":"https://api.github.com/repos/haozhun/presto/contributors","subscribers_url":"https://api.github.com/repos/haozhun/presto/subscribers","subscription_url":"https://api.github.com/repos/haozhun/presto/subscription","commits_url":"https://api.github.com/repos/haozhun/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/haozhun/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/haozhun/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/haozhun/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/haozhun/presto/contents/{+path}","compare_url":"https://api.github.com/repos/haozhun/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/haozhun/presto/merges","archive_url":"https://api.github.com/repos/haozhun/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/haozhun/presto/downloads","issues_url":"https://api.github.com/repos/haozhun/presto/issues{/number}","pulls_url":"https://api.github.com/repos/haozhun/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/haozhun/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/haozhun/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/haozhun/presto/labels{/name}","releases_url":"https://api.github.com/repos/haozhun/presto/releases{/id}","deployments_url":"https://api.github.com/repos/haozhun/presto/deployments","created_at":"2015-02-19T19:19:31Z","updated_at":"2015-04-04T00:15:06Z","pushed_at":"2016-02-03T19:10:11Z","git_url":"git://github.com/haozhun/presto.git","ssh_url":"git@github.com:haozhun/presto.git","clone_url":"https://github.com/haozhun/presto.git","svn_url":"https://github.com/haozhun/presto","homepage":"https://prestodb.io","size":52972,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"0f4b85a26e26ce5ead38cc904be77189fb86d9d8","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":5349565,"name":"presto","full_name":"facebook/presto","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":false,"url":"https://api.github.com/repos/facebook/presto","forks_url":"https://api.github.com/repos/facebook/presto/forks","keys_url":"https://api.github.com/repos/facebook/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/presto/teams","hooks_url":"https://api.github.com/repos/facebook/presto/hooks","issue_events_url":"https://api.github.com/repos/facebook/presto/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/presto/events","assignees_url":"https://api.github.com/repos/facebook/presto/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/presto/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/presto/tags","blobs_url":"https://api.github.com/repos/facebook/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/presto/languages","stargazers_url":"https://api.github.com/repos/facebook/presto/stargazers","contributors_url":"https://api.github.com/repos/facebook/presto/contributors","subscribers_url":"https://api.github.com/repos/facebook/presto/subscribers","subscription_url":"https://api.github.com/repos/facebook/presto/subscription","commits_url":"https://api.github.com/repos/facebook/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/presto/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/presto/merges","archive_url":"https://api.github.com/repos/facebook/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/presto/downloads","issues_url":"https://api.github.com/repos/facebook/presto/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/presto/labels{/name}","releases_url":"https://api.github.com/repos/facebook/presto/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/presto/deployments","created_at":"2012-08-09T01:03:37Z","updated_at":"2016-02-03T18:30:58Z","pushed_at":"2016-02-03T19:13:59Z","git_url":"git://github.com/facebook/presto.git","ssh_url":"git@github.com:facebook/presto.git","clone_url":"https://github.com/facebook/presto.git","svn_url":"https://github.com/facebook/presto","homepage":"https://prestodb.io","size":109271,"stargazers_count":4435,"watchers_count":4435,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1227,"mirror_url":null,"open_issues_count":452,"forks":1227,"open_issues":452,"watchers":4435,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/4445"},"html":{"href":"https://github.com/facebook/presto/pull/4445"},"issue":{"href":"https://api.github.com/repos/facebook/presto/issues/4445"},"comments":{"href":"https://api.github.com/repos/facebook/presto/issues/4445/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/presto/pulls/4445/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/presto/pulls/4445/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/presto/statuses/250e242d3bdf38daeb6ba5eddd81e301ad216b95"}}}}