{"action":"created","comment":{"url":"https://api.github.com/repos/prestodb/presto/pulls/comments/79066214","id":79066214,"diff_hunk":"@@ -528,6 +529,24 @@ public void dropTable(Session session, TableHandle tableHandle)\n     }\n \n     @Override\n+    public void beginQuery(Session session, Collection<TableHandle> tableHandles)\n+    {\n+        Set<String> distrinctConnectors = retrieveConnectorIds(tableHandles);\n+\n+        for (String connectorId : distrinctConnectors) {\n+            ConnectorEntry entry = connectorsById.get(connectorId);\n+            ConnectorSession connectorSession = session.toConnectorSession(entry.getCatalog());\n+            ConnectorMetadata metadata = entry.getMetadata(session);\n+            metadata.beginQuery(connectorSession);\n+        }\n+    }\n+\n+    private static Set<String> retrieveConnectorIds(Collection<TableHandle> tableHandles)","path":"presto-main/src/main/java/com/facebook/presto/metadata/MetadataManager.java","position":null,"original_position":24,"commit_id":"db749d1eff91a6317ca937f2f8ba3b4ec9651223","original_commit_id":"46fefccf6edf927b0898b5fc0c8733cfc5b8e556","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":"Inline since this is only used in one place","created_at":"2016-09-15T21:29:26Z","updated_at":"2016-09-15T21:29:26Z","html_url":"https://github.com/prestodb/presto/pull/6114#discussion_r79066214","pull_request_url":"https://api.github.com/repos/prestodb/presto/pulls/6114","_links":{"self":{"href":"https://api.github.com/repos/prestodb/presto/pulls/comments/79066214"},"html":{"href":"https://github.com/prestodb/presto/pull/6114#discussion_r79066214"},"pull_request":{"href":"https://api.github.com/repos/prestodb/presto/pulls/6114"}}},"pull_request":{"url":"https://api.github.com/repos/prestodb/presto/pulls/6114","id":85267612,"html_url":"https://github.com/prestodb/presto/pull/6114","diff_url":"https://github.com/prestodb/presto/pull/6114.diff","patch_url":"https://github.com/prestodb/presto/pull/6114.patch","issue_url":"https://api.github.com/repos/prestodb/presto/issues/6114","number":6114,"state":"open","locked":false,"title":"Add beginQuery and endQuery SPI notifications","user":{"login":"maciejgrzybek","id":366501,"avatar_url":"https://avatars.githubusercontent.com/u/366501?v=3","gravatar_id":"","url":"https://api.github.com/users/maciejgrzybek","html_url":"https://github.com/maciejgrzybek","followers_url":"https://api.github.com/users/maciejgrzybek/followers","following_url":"https://api.github.com/users/maciejgrzybek/following{/other_user}","gists_url":"https://api.github.com/users/maciejgrzybek/gists{/gist_id}","starred_url":"https://api.github.com/users/maciejgrzybek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maciejgrzybek/subscriptions","organizations_url":"https://api.github.com/users/maciejgrzybek/orgs","repos_url":"https://api.github.com/users/maciejgrzybek/repos","events_url":"https://api.github.com/users/maciejgrzybek/events{/privacy}","received_events_url":"https://api.github.com/users/maciejgrzybek/received_events","type":"User","site_admin":false},"body":"`beginQuery(Session)` is called when any type of query (SELECT, INSERT, UPDATE, DELETE or DDL) is starting its execution.\r\n`endQuery(Session)` is called in the very end of query execution after any other notification.\r\nIf multiple connectors are involved in execution of a query (e.g. JOIN between connectors) each of them is notified once. If multiple sources (tables) from the same connector are participating in one query, it's notified only once.\r\nE.g.:\r\n```sql\r\nSELECT n.name, l.tax, nh.comment\r\n  FROM tpch.tiny.nation n\r\n     JOIN tpch.sf1.lineitem l    ON (n.nationkey = l.orderkey)\r\n     JOIN hive.default.nation nh ON (n.nationkey = nh.nationkey);\r\n```\r\nwill trigger two notifications:\r\none for TPCH catalog and another for Hive catalog.\r\nBut if below was queried instead (mind the _tpch*2*_ is different than _tpch_ catalog, using the same connector though):\r\n```sql\r\nSELECT n.name, l.tax, nh.comment\r\n  FROM tpch.tiny.nation n\r\n    JOIN tpch2.sf1.lineitem l   ON (n.nationkey = l.orderkey)\r\n    JOIN hive.default.nation nh ON (n.nationkey = nh.nationkey);\r\n```\r\nit would trigger three notifications for those catalogs:\r\n- `tpch`\r\n- `tpch2`\r\n- `hive`\r\n\r\nThe purpose of this patch is to let connector know about each query it's participating in.\r\nThat's to let catalog follow (e.g. allocate necessary resources [and deallocate them in `endQuery` notification]) execution of queries in more generic way than using `beginX` and `endX` pairs of notifications (e.g. `beginInsert` and `finishInsert`).\r\n\r\nPlease keep in mind that `beginQuery` does not mean the query will be executed correctly.\r\nEspecially for DDLs, e.g.:\r\n`create table x` will trigger `beginQuery` while it may fail right after with `table already exists` error. Though, `endQuery` will be triggered when it's failed.\r\n\r\n---\r\nThis is a continuation of work started at https://github.com/prestodb/presto/pull/5122.\r\nThe work will be split into two PRs: first (this one) will contain `beginQuery` and `endQuery`. Next will be covering adding column list (projection) to `ConnectorSplitManager`.\r\n\r\nTD internal review: https://github.com/Teradata/presto/pull/346 and its superseding https://github.com/Teradata/presto/pull/348.","created_at":"2016-09-14T17:07:36Z","updated_at":"2016-09-15T21:29:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fa99acb18536d35f29cd0ae6c71c531ef8363a73","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},"assignees":[{"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/prestodb/presto/pulls/6114/commits","review_comments_url":"https://api.github.com/repos/prestodb/presto/pulls/6114/comments","review_comment_url":"https://api.github.com/repos/prestodb/presto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prestodb/presto/issues/6114/comments","statuses_url":"https://api.github.com/repos/prestodb/presto/statuses/db749d1eff91a6317ca937f2f8ba3b4ec9651223","head":{"label":"Teradata:begin_end_query/2","ref":"begin_end_query/2","sha":"db749d1eff91a6317ca937f2f8ba3b4ec9651223","user":{"login":"Teradata","id":1615979,"avatar_url":"https://avatars.githubusercontent.com/u/1615979?v=3","gravatar_id":"","url":"https://api.github.com/users/Teradata","html_url":"https://github.com/Teradata","followers_url":"https://api.github.com/users/Teradata/followers","following_url":"https://api.github.com/users/Teradata/following{/other_user}","gists_url":"https://api.github.com/users/Teradata/gists{/gist_id}","starred_url":"https://api.github.com/users/Teradata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teradata/subscriptions","organizations_url":"https://api.github.com/users/Teradata/orgs","repos_url":"https://api.github.com/users/Teradata/repos","events_url":"https://api.github.com/users/Teradata/events{/privacy}","received_events_url":"https://api.github.com/users/Teradata/received_events","type":"Organization","site_admin":false},"repo":{"id":36903368,"name":"presto","full_name":"Teradata/presto","owner":{"login":"Teradata","id":1615979,"avatar_url":"https://avatars.githubusercontent.com/u/1615979?v=3","gravatar_id":"","url":"https://api.github.com/users/Teradata","html_url":"https://github.com/Teradata","followers_url":"https://api.github.com/users/Teradata/followers","following_url":"https://api.github.com/users/Teradata/following{/other_user}","gists_url":"https://api.github.com/users/Teradata/gists{/gist_id}","starred_url":"https://api.github.com/users/Teradata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teradata/subscriptions","organizations_url":"https://api.github.com/users/Teradata/orgs","repos_url":"https://api.github.com/users/Teradata/repos","events_url":"https://api.github.com/users/Teradata/events{/privacy}","received_events_url":"https://api.github.com/users/Teradata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Teradata/presto","description":"Teradata Distribution of Presto -- A Distributed SQL Query Engine for Big Data","fork":true,"url":"https://api.github.com/repos/Teradata/presto","forks_url":"https://api.github.com/repos/Teradata/presto/forks","keys_url":"https://api.github.com/repos/Teradata/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Teradata/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Teradata/presto/teams","hooks_url":"https://api.github.com/repos/Teradata/presto/hooks","issue_events_url":"https://api.github.com/repos/Teradata/presto/issues/events{/number}","events_url":"https://api.github.com/repos/Teradata/presto/events","assignees_url":"https://api.github.com/repos/Teradata/presto/assignees{/user}","branches_url":"https://api.github.com/repos/Teradata/presto/branches{/branch}","tags_url":"https://api.github.com/repos/Teradata/presto/tags","blobs_url":"https://api.github.com/repos/Teradata/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Teradata/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Teradata/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/Teradata/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Teradata/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/Teradata/presto/languages","stargazers_url":"https://api.github.com/repos/Teradata/presto/stargazers","contributors_url":"https://api.github.com/repos/Teradata/presto/contributors","subscribers_url":"https://api.github.com/repos/Teradata/presto/subscribers","subscription_url":"https://api.github.com/repos/Teradata/presto/subscription","commits_url":"https://api.github.com/repos/Teradata/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/Teradata/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/Teradata/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/Teradata/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/Teradata/presto/contents/{+path}","compare_url":"https://api.github.com/repos/Teradata/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Teradata/presto/merges","archive_url":"https://api.github.com/repos/Teradata/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Teradata/presto/downloads","issues_url":"https://api.github.com/repos/Teradata/presto/issues{/number}","pulls_url":"https://api.github.com/repos/Teradata/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/Teradata/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/Teradata/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Teradata/presto/labels{/name}","releases_url":"https://api.github.com/repos/Teradata/presto/releases{/id}","deployments_url":"https://api.github.com/repos/Teradata/presto/deployments","created_at":"2015-06-05T00:38:37Z","updated_at":"2016-08-29T16:52:50Z","pushed_at":"2016-09-15T20:29:28Z","git_url":"git://github.com/Teradata/presto.git","ssh_url":"git@github.com:Teradata/presto.git","clone_url":"https://github.com/Teradata/presto.git","svn_url":"https://github.com/Teradata/presto","homepage":"http://www.teradata.com/presto","size":159239,"stargazers_count":56,"watchers_count":56,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":18,"forks":11,"open_issues":18,"watchers":56,"default_branch":"master"}},"base":{"label":"prestodb:master","ref":"master","sha":"c2be0a854fc5e2ef25738aec8ae8e7c37d821b4e","user":{"login":"prestodb","id":6882181,"avatar_url":"https://avatars.githubusercontent.com/u/6882181?v=3","gravatar_id":"","url":"https://api.github.com/users/prestodb","html_url":"https://github.com/prestodb","followers_url":"https://api.github.com/users/prestodb/followers","following_url":"https://api.github.com/users/prestodb/following{/other_user}","gists_url":"https://api.github.com/users/prestodb/gists{/gist_id}","starred_url":"https://api.github.com/users/prestodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prestodb/subscriptions","organizations_url":"https://api.github.com/users/prestodb/orgs","repos_url":"https://api.github.com/users/prestodb/repos","events_url":"https://api.github.com/users/prestodb/events{/privacy}","received_events_url":"https://api.github.com/users/prestodb/received_events","type":"Organization","site_admin":false},"repo":{"id":5349565,"name":"presto","full_name":"prestodb/presto","owner":{"login":"prestodb","id":6882181,"avatar_url":"https://avatars.githubusercontent.com/u/6882181?v=3","gravatar_id":"","url":"https://api.github.com/users/prestodb","html_url":"https://github.com/prestodb","followers_url":"https://api.github.com/users/prestodb/followers","following_url":"https://api.github.com/users/prestodb/following{/other_user}","gists_url":"https://api.github.com/users/prestodb/gists{/gist_id}","starred_url":"https://api.github.com/users/prestodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prestodb/subscriptions","organizations_url":"https://api.github.com/users/prestodb/orgs","repos_url":"https://api.github.com/users/prestodb/repos","events_url":"https://api.github.com/users/prestodb/events{/privacy}","received_events_url":"https://api.github.com/users/prestodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prestodb/presto","description":"Distributed SQL query engine for big data","fork":false,"url":"https://api.github.com/repos/prestodb/presto","forks_url":"https://api.github.com/repos/prestodb/presto/forks","keys_url":"https://api.github.com/repos/prestodb/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prestodb/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prestodb/presto/teams","hooks_url":"https://api.github.com/repos/prestodb/presto/hooks","issue_events_url":"https://api.github.com/repos/prestodb/presto/issues/events{/number}","events_url":"https://api.github.com/repos/prestodb/presto/events","assignees_url":"https://api.github.com/repos/prestodb/presto/assignees{/user}","branches_url":"https://api.github.com/repos/prestodb/presto/branches{/branch}","tags_url":"https://api.github.com/repos/prestodb/presto/tags","blobs_url":"https://api.github.com/repos/prestodb/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prestodb/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prestodb/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/prestodb/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prestodb/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/prestodb/presto/languages","stargazers_url":"https://api.github.com/repos/prestodb/presto/stargazers","contributors_url":"https://api.github.com/repos/prestodb/presto/contributors","subscribers_url":"https://api.github.com/repos/prestodb/presto/subscribers","subscription_url":"https://api.github.com/repos/prestodb/presto/subscription","commits_url":"https://api.github.com/repos/prestodb/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/prestodb/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/prestodb/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/prestodb/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/prestodb/presto/contents/{+path}","compare_url":"https://api.github.com/repos/prestodb/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prestodb/presto/merges","archive_url":"https://api.github.com/repos/prestodb/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prestodb/presto/downloads","issues_url":"https://api.github.com/repos/prestodb/presto/issues{/number}","pulls_url":"https://api.github.com/repos/prestodb/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/prestodb/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/prestodb/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prestodb/presto/labels{/name}","releases_url":"https://api.github.com/repos/prestodb/presto/releases{/id}","deployments_url":"https://api.github.com/repos/prestodb/presto/deployments","created_at":"2012-08-09T01:03:37Z","updated_at":"2016-09-15T16:47:34Z","pushed_at":"2016-09-15T21:24:37Z","git_url":"git://github.com/prestodb/presto.git","ssh_url":"git@github.com:prestodb/presto.git","clone_url":"https://github.com/prestodb/presto.git","svn_url":"https://github.com/prestodb/presto","homepage":"https://prestodb.io","size":162920,"stargazers_count":5112,"watchers_count":5112,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1571,"mirror_url":null,"open_issues_count":656,"forks":1571,"open_issues":656,"watchers":5112,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prestodb/presto/pulls/6114"},"html":{"href":"https://github.com/prestodb/presto/pull/6114"},"issue":{"href":"https://api.github.com/repos/prestodb/presto/issues/6114"},"comments":{"href":"https://api.github.com/repos/prestodb/presto/issues/6114/comments"},"review_comments":{"href":"https://api.github.com/repos/prestodb/presto/pulls/6114/comments"},"review_comment":{"href":"https://api.github.com/repos/prestodb/presto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prestodb/presto/pulls/6114/commits"},"statuses":{"href":"https://api.github.com/repos/prestodb/presto/statuses/db749d1eff91a6317ca937f2f8ba3b4ec9651223"}}}}
{"actor":{"display_login":"electrum"}}