{"action":"created","issue":{"url":"https://api.github.com/repos/Teradata/presto/issues/346","repository_url":"https://api.github.com/repos/Teradata/presto","labels_url":"https://api.github.com/repos/Teradata/presto/issues/346/labels{/name}","comments_url":"https://api.github.com/repos/Teradata/presto/issues/346/comments","events_url":"https://api.github.com/repos/Teradata/presto/issues/346/events","html_url":"https://github.com/Teradata/presto/pull/346","id":176461486,"number":346,"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},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-12T19:23:07Z","updated_at":"2016-09-12T19:23:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Teradata/presto/pulls/346","html_url":"https://github.com/Teradata/presto/pull/346","diff_url":"https://github.com/Teradata/presto/pull/346.diff","patch_url":"https://github.com/Teradata/presto/pull/346.patch"},"body":"`beginQuery(Session)` is called when any type of query (SELECT, INSERT, UPDATE, DELETE or DDLs) is starting it's 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."},"comment":{"url":"https://api.github.com/repos/Teradata/presto/issues/comments/246461557","html_url":"https://github.com/Teradata/presto/pull/346#issuecomment-246461557","issue_url":"https://api.github.com/repos/Teradata/presto/issues/346","id":246461557,"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},"created_at":"2016-09-12T19:23:22Z","updated_at":"2016-09-12T19:23:22Z","body":"@cawallin can you review, please?"}}
{"actor":{"display_login":"maciejgrzybek"}}