{"action":"created","comment":{"url":"https://api.github.com/repos/crate/crate/pulls/comments/71080259","id":71080259,"diff_hunk":"@@ -0,0 +1,183 @@\n+/*\n+ * Licensed to Crate under one or more contributor license agreements.\n+ * See the NOTICE file distributed with this work for additional\n+ * information regarding copyright ownership.  Crate licenses this file\n+ * to you under the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.  You may\n+ * 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\n+ * implied.  See the License for the specific language governing\n+ * permissions and limitations under the License.\n+ *\n+ * However, if you have executed another commercial license agreement\n+ * with Crate these terms will supersede the license and you may use the\n+ * software solely pursuant to the terms of the relevant commercial\n+ * agreement.\n+ */\n+\n+package io.crate.protocols.postgres;\n+\n+import io.crate.action.sql.ResultReceiver;\n+import io.crate.action.sql.RowReceiverToResultReceiver;\n+import io.crate.analyze.Analysis;\n+import io.crate.analyze.AnalyzedStatement;\n+import io.crate.analyze.ParameterContext;\n+import io.crate.analyze.symbol.Field;\n+import io.crate.analyze.symbol.Symbols;\n+import io.crate.concurrent.CompletionListener;\n+import io.crate.concurrent.CompletionMultiListener;\n+import io.crate.concurrent.CompletionState;\n+import io.crate.exceptions.BatchModeWriteOnlyException;\n+import io.crate.exceptions.ReadOnlyException;\n+import io.crate.operation.collect.StatsTables;\n+import io.crate.operation.projectors.RowReceiver;\n+import io.crate.planner.Plan;\n+import io.crate.planner.Planner;\n+import io.crate.sql.tree.Statement;\n+import io.crate.types.DataType;\n+import org.elasticsearch.common.logging.ESLogger;\n+import org.elasticsearch.common.logging.Loggers;\n+\n+import javax.annotation.Nullable;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.UUID;\n+import java.util.concurrent.atomic.AtomicInteger;\n+\n+import static io.crate.action.sql.SQLBulkRequest.EMPTY_BULK_ARGS;\n+\n+class BatchPortal extends AbstractPortal {\n+\n+    private final static ESLogger LOGGER = Loggers.getLogger(BatchPortal.class);\n+\n+    private List<List<Object>> batchParams = new ArrayList<>();\n+    private List<String> queries = new ArrayList<>();\n+    private List<Analysis> analysis= new ArrayList<>();\n+    private List<FormatCodes.FormatCode[]> resultFormatCodes = new ArrayList<>();\n+    private List<List<? extends DataType>> outputTypes = new ArrayList<>();\n+    private List<ResultReceiver> resultReceivers = new ArrayList<>();\n+\n+    BatchPortal(String name,\n+                String query,\n+                Analysis analysis,\n+                List<? extends DataType> outputTypes,\n+                ResultReceiver resultReceiver,\n+                List<Object> params,\n+                SessionData sessionData) {\n+        super(name, sessionData);\n+        queries.add(query);\n+        this.analysis.add(analysis);\n+        this.outputTypes.add(outputTypes);\n+        resultReceivers.add(resultReceiver);\n+        batchParams.add(params);\n+    }\n+\n+    @Override\n+    @Nullable\n+    public FormatCodes.FormatCode[] getLastResultFormatCodes() {\n+        if (resultFormatCodes.isEmpty()) {\n+            return null;\n+        } else {\n+            return resultFormatCodes.get(resultFormatCodes.size() - 1);\n+        }\n+    }\n+\n+    @Override\n+    public List<? extends DataType> getLastOutputTypes() {\n+        return outputTypes.get(outputTypes.size() - 1);\n+    }\n+\n+    @Override\n+    public String getLastQuery() {\n+        return queries.get(queries.size() - 1);\n+    }\n+\n+    @Override\n+    public Portal bind(String statementName, String query, Statement statement,\n+                       List<Object> params, @Nullable FormatCodes.FormatCode[] resultFormatCodes) {\n+        queries.add(query);\n+        batchParams.add(params);\n+        this.resultFormatCodes.add(resultFormatCodes);\n+        analysis.add(sessionData.getAnalyzer().analyze(statement,\n+            new ParameterContext(getArgs(),\n+                EMPTY_BULK_ARGS,\n+                sessionData.getDefaultSchema())));\n+        return this;\n+    }\n+\n+    @Override\n+    public List<Field> describe() {\n+        Analysis lastAnalysis = analysis.get(analysis.size() - 1);\n+        if (lastAnalysis.rootRelation() == null) {\n+            return null;\n+        }\n+        List<Field> fields = lastAnalysis.rootRelation().fields();\n+        outputTypes.add(Symbols.extractTypes(fields));\n+        return fields;\n+    }\n+\n+    @Override\n+    public void execute(ResultReceiver resultReceiver, int maxRows) {\n+        validate(analysis.get(analysis.size() - 1));\n+        resultReceivers.add(resultReceiver);\n+    }\n+\n+    @Override\n+    public void sync(Planner planner, StatsTables statsTables, CompletionListener listener) {\n+        BatchCompletionListener batchCompletionListener = new BatchCompletionListener(analysis.size(), listener,\n+            new StatsTablesUpdateListener(sessionData.getJobId(), statsTables));\n+        for (int i = 0; i < analysis.size(); i++) {\n+            Plan plan = planner.plan(analysis.get(i), UUID.randomUUID(), 0, 0);","path":"sql/src/main/java/io/crate/protocols/postgres/BatchPortal.java","position":135,"original_position":135,"commit_id":"121768f89f88655328db130b88d580cd95d132ae","original_commit_id":"121768f89f88655328db130b88d580cd95d132ae","user":{"login":"matriv","id":5058131,"avatar_url":"https://avatars.githubusercontent.com/u/5058131?v=3","gravatar_id":"","url":"https://api.github.com/users/matriv","html_url":"https://github.com/matriv","followers_url":"https://api.github.com/users/matriv/followers","following_url":"https://api.github.com/users/matriv/following{/other_user}","gists_url":"https://api.github.com/users/matriv/gists{/gist_id}","starred_url":"https://api.github.com/users/matriv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matriv/subscriptions","organizations_url":"https://api.github.com/users/matriv/orgs","repos_url":"https://api.github.com/users/matriv/repos","events_url":"https://api.github.com/users/matriv/events{/privacy}","received_events_url":"https://api.github.com/users/matriv/received_events","type":"User","site_admin":false},"body":"@mfussenegger I'm using a new jobId for each operation. Is this correct? any alternatives?","created_at":"2016-07-17T10:35:14Z","updated_at":"2016-07-17T10:35:14Z","html_url":"https://github.com/crate/crate/pull/3827#discussion_r71080259","pull_request_url":"https://api.github.com/repos/crate/crate/pulls/3827","_links":{"self":{"href":"https://api.github.com/repos/crate/crate/pulls/comments/71080259"},"html":{"href":"https://github.com/crate/crate/pull/3827#discussion_r71080259"},"pull_request":{"href":"https://api.github.com/repos/crate/crate/pulls/3827"}}},"pull_request":{"url":"https://api.github.com/repos/crate/crate/pulls/3827","id":77732133,"html_url":"https://github.com/crate/crate/pull/3827","diff_url":"https://github.com/crate/crate/pull/3827.diff","patch_url":"https://github.com/crate/crate/pull/3827.patch","issue_url":"https://api.github.com/repos/crate/crate/issues/3827","number":3827,"state":"open","locked":false,"title":"Implemented batch operations with different statements","user":{"login":"matriv","id":5058131,"avatar_url":"https://avatars.githubusercontent.com/u/5058131?v=3","gravatar_id":"","url":"https://api.github.com/users/matriv","html_url":"https://github.com/matriv","followers_url":"https://api.github.com/users/matriv/followers","following_url":"https://api.github.com/users/matriv/following{/other_user}","gists_url":"https://api.github.com/users/matriv/gists{/gist_id}","starred_url":"https://api.github.com/users/matriv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matriv/subscriptions","organizations_url":"https://api.github.com/users/matriv/orgs","repos_url":"https://api.github.com/users/matriv/repos","events_url":"https://api.github.com/users/matriv/events{/privacy}","received_events_url":"https://api.github.com/users/matriv/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-17T10:30:31Z","updated_at":"2016-07-17T10:35:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"786703cf63a32bacdbfad28cc4ab851d7036e48a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/crate/crate/pulls/3827/commits","review_comments_url":"https://api.github.com/repos/crate/crate/pulls/3827/comments","review_comment_url":"https://api.github.com/repos/crate/crate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crate/crate/issues/3827/comments","statuses_url":"https://api.github.com/repos/crate/crate/statuses/121768f89f88655328db130b88d580cd95d132ae","head":{"label":"crate:mt/implement-batchoperations","ref":"mt/implement-batchoperations","sha":"121768f89f88655328db130b88d580cd95d132ae","user":{"login":"crate","id":4048232,"avatar_url":"https://avatars.githubusercontent.com/u/4048232?v=3","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"repo":{"id":9342529,"name":"crate","full_name":"crate/crate","owner":{"login":"crate","id":4048232,"avatar_url":"https://avatars.githubusercontent.com/u/4048232?v=3","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crate/crate","description":"Crate.IO: The fast, scalable, easy to use SQL database with native full text search","fork":false,"url":"https://api.github.com/repos/crate/crate","forks_url":"https://api.github.com/repos/crate/crate/forks","keys_url":"https://api.github.com/repos/crate/crate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crate/crate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crate/crate/teams","hooks_url":"https://api.github.com/repos/crate/crate/hooks","issue_events_url":"https://api.github.com/repos/crate/crate/issues/events{/number}","events_url":"https://api.github.com/repos/crate/crate/events","assignees_url":"https://api.github.com/repos/crate/crate/assignees{/user}","branches_url":"https://api.github.com/repos/crate/crate/branches{/branch}","tags_url":"https://api.github.com/repos/crate/crate/tags","blobs_url":"https://api.github.com/repos/crate/crate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crate/crate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crate/crate/git/refs{/sha}","trees_url":"https://api.github.com/repos/crate/crate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crate/crate/statuses/{sha}","languages_url":"https://api.github.com/repos/crate/crate/languages","stargazers_url":"https://api.github.com/repos/crate/crate/stargazers","contributors_url":"https://api.github.com/repos/crate/crate/contributors","subscribers_url":"https://api.github.com/repos/crate/crate/subscribers","subscription_url":"https://api.github.com/repos/crate/crate/subscription","commits_url":"https://api.github.com/repos/crate/crate/commits{/sha}","git_commits_url":"https://api.github.com/repos/crate/crate/git/commits{/sha}","comments_url":"https://api.github.com/repos/crate/crate/comments{/number}","issue_comment_url":"https://api.github.com/repos/crate/crate/issues/comments{/number}","contents_url":"https://api.github.com/repos/crate/crate/contents/{+path}","compare_url":"https://api.github.com/repos/crate/crate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crate/crate/merges","archive_url":"https://api.github.com/repos/crate/crate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crate/crate/downloads","issues_url":"https://api.github.com/repos/crate/crate/issues{/number}","pulls_url":"https://api.github.com/repos/crate/crate/pulls{/number}","milestones_url":"https://api.github.com/repos/crate/crate/milestones{/number}","notifications_url":"https://api.github.com/repos/crate/crate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crate/crate/labels{/name}","releases_url":"https://api.github.com/repos/crate/crate/releases{/id}","deployments_url":"https://api.github.com/repos/crate/crate/deployments","created_at":"2013-04-10T09:17:16Z","updated_at":"2016-07-17T06:04:59Z","pushed_at":"2016-07-17T10:32:10Z","git_url":"git://github.com/crate/crate.git","ssh_url":"git@github.com:crate/crate.git","clone_url":"https://github.com/crate/crate.git","svn_url":"https://github.com/crate/crate","homepage":"https://crate.io","size":71589,"stargazers_count":1317,"watchers_count":1317,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":146,"mirror_url":null,"open_issues_count":46,"forks":146,"open_issues":46,"watchers":1317,"default_branch":"master"}},"base":{"label":"crate:master","ref":"master","sha":"a1283d91c6575c71ec5e12947135b71682720186","user":{"login":"crate","id":4048232,"avatar_url":"https://avatars.githubusercontent.com/u/4048232?v=3","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"repo":{"id":9342529,"name":"crate","full_name":"crate/crate","owner":{"login":"crate","id":4048232,"avatar_url":"https://avatars.githubusercontent.com/u/4048232?v=3","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crate/crate","description":"Crate.IO: The fast, scalable, easy to use SQL database with native full text search","fork":false,"url":"https://api.github.com/repos/crate/crate","forks_url":"https://api.github.com/repos/crate/crate/forks","keys_url":"https://api.github.com/repos/crate/crate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crate/crate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crate/crate/teams","hooks_url":"https://api.github.com/repos/crate/crate/hooks","issue_events_url":"https://api.github.com/repos/crate/crate/issues/events{/number}","events_url":"https://api.github.com/repos/crate/crate/events","assignees_url":"https://api.github.com/repos/crate/crate/assignees{/user}","branches_url":"https://api.github.com/repos/crate/crate/branches{/branch}","tags_url":"https://api.github.com/repos/crate/crate/tags","blobs_url":"https://api.github.com/repos/crate/crate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crate/crate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crate/crate/git/refs{/sha}","trees_url":"https://api.github.com/repos/crate/crate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crate/crate/statuses/{sha}","languages_url":"https://api.github.com/repos/crate/crate/languages","stargazers_url":"https://api.github.com/repos/crate/crate/stargazers","contributors_url":"https://api.github.com/repos/crate/crate/contributors","subscribers_url":"https://api.github.com/repos/crate/crate/subscribers","subscription_url":"https://api.github.com/repos/crate/crate/subscription","commits_url":"https://api.github.com/repos/crate/crate/commits{/sha}","git_commits_url":"https://api.github.com/repos/crate/crate/git/commits{/sha}","comments_url":"https://api.github.com/repos/crate/crate/comments{/number}","issue_comment_url":"https://api.github.com/repos/crate/crate/issues/comments{/number}","contents_url":"https://api.github.com/repos/crate/crate/contents/{+path}","compare_url":"https://api.github.com/repos/crate/crate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crate/crate/merges","archive_url":"https://api.github.com/repos/crate/crate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crate/crate/downloads","issues_url":"https://api.github.com/repos/crate/crate/issues{/number}","pulls_url":"https://api.github.com/repos/crate/crate/pulls{/number}","milestones_url":"https://api.github.com/repos/crate/crate/milestones{/number}","notifications_url":"https://api.github.com/repos/crate/crate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crate/crate/labels{/name}","releases_url":"https://api.github.com/repos/crate/crate/releases{/id}","deployments_url":"https://api.github.com/repos/crate/crate/deployments","created_at":"2013-04-10T09:17:16Z","updated_at":"2016-07-17T06:04:59Z","pushed_at":"2016-07-17T10:32:10Z","git_url":"git://github.com/crate/crate.git","ssh_url":"git@github.com:crate/crate.git","clone_url":"https://github.com/crate/crate.git","svn_url":"https://github.com/crate/crate","homepage":"https://crate.io","size":71589,"stargazers_count":1317,"watchers_count":1317,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":146,"mirror_url":null,"open_issues_count":46,"forks":146,"open_issues":46,"watchers":1317,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crate/crate/pulls/3827"},"html":{"href":"https://github.com/crate/crate/pull/3827"},"issue":{"href":"https://api.github.com/repos/crate/crate/issues/3827"},"comments":{"href":"https://api.github.com/repos/crate/crate/issues/3827/comments"},"review_comments":{"href":"https://api.github.com/repos/crate/crate/pulls/3827/comments"},"review_comment":{"href":"https://api.github.com/repos/crate/crate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crate/crate/pulls/3827/commits"},"statuses":{"href":"https://api.github.com/repos/crate/crate/statuses/121768f89f88655328db130b88d580cd95d132ae"}}}}
{"actor":{"display_login":"matriv"}}