{"action":"created","comment":{"url":"https://api.github.com/repos/VoltDB/voltdb/pulls/comments/36581028","id":36581028,"diff_hunk":"@@ -0,0 +1,151 @@\n+/* This file is part of VoltDB.\n+ * Copyright (C) 2008-2015 VoltDB Inc.\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Affero General Public License as\n+ * published by the Free Software Foundation, either version 3 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU Affero General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Affero General Public License\n+ * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.\n+ */\n+\n+package org.voltdb.compiler;\n+\n+import java.util.List;\n+import java.util.ArrayList;\n+import org.hsqldb_voltpatches.VoltXMLElement;\n+\n+/**\n+ * Helper functions for assembling VoltXMLElement.\n+ * ENG-8641\n+ */\n+public class VoltXMLElementHelper {\n+\n+    // Find the current maximum element id (recursively).\n+    public static int findMaxElementId(VoltXMLElement root) {\n+        int retval = 0;\n+        if (root != null) {\n+            String strId = root.attributes.get(\"id\");\n+            if (strId != null) {\n+                retval = Integer.parseInt(strId);\n+            }\n+            for (VoltXMLElement child : root.children) {\n+                int childMaxId = findMaxElementId(child);\n+                if (retval < childMaxId) {\n+                    retval = childMaxId;\n+                }\n+            }\n+        }\n+        return retval;\n+    }\n+\n+    public static VoltXMLElement getFirstChild(VoltXMLElement root, String name, boolean createIfNotExist) {\n+        if (root == null || name == null) { return null; }\n+\n+        List<VoltXMLElement> elementList = root.findChildren(name);\n+        if (elementList.size() < 1) {\n+            if (createIfNotExist) {\n+                VoltXMLElement retval = new VoltXMLElement(name);\n+                root.children.add(retval);\n+                return retval;\n+            }\n+            else {\n+                return null;\n+            }\n+        }\n+        else {\n+            return elementList.get(0);\n+        }\n+    }\n+\n+    public static VoltXMLElement getFirstChild(VoltXMLElement root, String name) {\n+        return getFirstChild( root, name, false );\n+    }\n+\n+    // Merge two XML elements with a parent element of operation.\n+    // e.g. and, or, equal, greaterthan\n+    // If one of the elements is null, return the other one diectly.\n+    public static VoltXMLElement mergeTwoElementsUsingOperator(String opName,\n+                                                               String opElementId,\n+                                                               VoltXMLElement first,\n+                                                               VoltXMLElement second) {\n+        if (first == null || second == null) {\n+            return first == null ? second : first;\n+        }\n+        if (opName == null || opElementId == null) { return null; }\n+\n+        VoltXMLElement retval = new VoltXMLElement(\"operation\");\n+        retval.attributes.put( \"id\", opElementId );\n+        retval.attributes.put( \"optype\", opName );\n+        retval.children.add( first );\n+        retval.children.add( second );\n+        return retval;\n+    }\n+\n+    public static VoltXMLElement buildValueElement(String elementId, boolean isParam, String value, String valueType) {\n+        if (elementId == null) { return null; }\n+\n+        VoltXMLElement retval = new VoltXMLElement(\"value\");\n+        retval.attributes.put(\"id\", elementId);\n+        if (isParam) {\n+            retval.attributes.put(\"isparam\", \"true\");\n+            return retval;\n+        }\n+\n+        if (value == null || valueType == null) { return null; }\n+        retval.attributes.put(\"value\", value);\n+        retval.attributes.put(\"valuetype\", valueType);\n+        return retval;\n+    }\n+\n+    public static VoltXMLElement buildValueElement(String elementId) {\n+        return buildValueElement(elementId, true, null, null);\n+    }\n+\n+    // Build VoltXMLElement for expression like \"LIMIT 1\".\n+    public static List<VoltXMLElement> buildLimitElements(int limit, String limitValueElementId) {\n+        if (limitValueElementId == null) { return null; }\n+\n+        List<VoltXMLElement> retval = new ArrayList<VoltXMLElement>();\n+        retval.add( new VoltXMLElement(\"offset\") );\n+\n+        VoltXMLElement limitElement = new VoltXMLElement(\"limit\");\n+        String strLimit = String.valueOf( limit );\n+        limitElement.attributes.put( \"limit\", strLimit );\n+        limitElement.children.add( buildValueElement( limitValueElementId, false, strLimit, \"BIGINT\" ) );\n+        retval.add( limitElement );\n+        return retval;\n+    }\n+\n+    // Build VoltXMLElement for expression like \"column=?\".\n+    public static VoltXMLElement buildColumnParamJoincondElement(String opName, VoltXMLElement leftElement, String valueParamElementId, String opElementId) {\n+        VoltXMLElement valueParamElement = buildValueElement(valueParamElementId);\n+        return mergeTwoElementsUsingOperator(opName, opElementId, leftElement, valueParamElement);\n+    }\n+\n+    // Build an element to be inserted under the \"parameters\" tree.\n+    public static VoltXMLElement buildParamElement(String elementId, String index, String valueType) {\n+        VoltXMLElement retval = new VoltXMLElement(\"parameter\");\n+        retval.attributes.put(\"id\", elementId);\n+        retval.attributes.put(\"index\", index);\n+        retval.attributes.put(\"valuetype\", valueType);\n+        return retval;\n+    }\n+\n+    public static VoltXMLElement buildOrderColumnsElement(VoltXMLElement orderbyColumn, boolean desc, String elementId) {","path":"src/frontend/org/voltdb/compiler/VoltXMLElementHelper.java","position":141,"original_position":141,"commit_id":"13a756d9167f90338a32a503da590db8af765804","original_commit_id":"13a756d9167f90338a32a503da590db8af765804","user":{"login":"yzhang1991","id":6643318,"avatar_url":"https://avatars.githubusercontent.com/u/6643318?v=3","gravatar_id":"","url":"https://api.github.com/users/yzhang1991","html_url":"https://github.com/yzhang1991","followers_url":"https://api.github.com/users/yzhang1991/followers","following_url":"https://api.github.com/users/yzhang1991/following{/other_user}","gists_url":"https://api.github.com/users/yzhang1991/gists{/gist_id}","starred_url":"https://api.github.com/users/yzhang1991/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yzhang1991/subscriptions","organizations_url":"https://api.github.com/users/yzhang1991/orgs","repos_url":"https://api.github.com/users/yzhang1991/repos","events_url":"https://api.github.com/users/yzhang1991/events{/privacy}","received_events_url":"https://api.github.com/users/yzhang1991/received_events","type":"User","site_admin":false},"body":"Same as buildLimitElements(), built for other plans.","created_at":"2015-08-08T19:30:57Z","updated_at":"2015-08-08T19:30:57Z","html_url":"https://github.com/VoltDB/voltdb/pull/2670#discussion_r36581028","pull_request_url":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670","_links":{"self":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/comments/36581028"},"html":{"href":"https://github.com/VoltDB/voltdb/pull/2670#discussion_r36581028"},"pull_request":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670"}}},"pull_request":{"url":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670","id":41825332,"html_url":"https://github.com/VoltDB/voltdb/pull/2670","diff_url":"https://github.com/VoltDB/voltdb/pull/2670.diff","patch_url":"https://github.com/VoltDB/voltdb/pull/2670.patch","issue_url":"https://api.github.com/repos/VoltDB/voltdb/issues/2670","number":2670,"state":"open","locked":false,"title":"Eng 8641 plan based mview minmax","user":{"login":"yzhang1991","id":6643318,"avatar_url":"https://avatars.githubusercontent.com/u/6643318?v=3","gravatar_id":"","url":"https://api.github.com/users/yzhang1991","html_url":"https://github.com/yzhang1991","followers_url":"https://api.github.com/users/yzhang1991/followers","following_url":"https://api.github.com/users/yzhang1991/following{/other_user}","gists_url":"https://api.github.com/users/yzhang1991/gists{/gist_id}","starred_url":"https://api.github.com/users/yzhang1991/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yzhang1991/subscriptions","organizations_url":"https://api.github.com/users/yzhang1991/orgs","repos_url":"https://api.github.com/users/yzhang1991/repos","events_url":"https://api.github.com/users/yzhang1991/events{/privacy}","received_events_url":"https://api.github.com/users/yzhang1991/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-06T19:29:27Z","updated_at":"2015-08-08T19:30:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8232ecfae871bebd4317a2bcaa2beba12c79d89b","assignee":{"login":"paulmartel","id":1512099,"avatar_url":"https://avatars.githubusercontent.com/u/1512099?v=3","gravatar_id":"","url":"https://api.github.com/users/paulmartel","html_url":"https://github.com/paulmartel","followers_url":"https://api.github.com/users/paulmartel/followers","following_url":"https://api.github.com/users/paulmartel/following{/other_user}","gists_url":"https://api.github.com/users/paulmartel/gists{/gist_id}","starred_url":"https://api.github.com/users/paulmartel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulmartel/subscriptions","organizations_url":"https://api.github.com/users/paulmartel/orgs","repos_url":"https://api.github.com/users/paulmartel/repos","events_url":"https://api.github.com/users/paulmartel/events{/privacy}","received_events_url":"https://api.github.com/users/paulmartel/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670/commits","review_comments_url":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670/comments","review_comment_url":"https://api.github.com/repos/VoltDB/voltdb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/VoltDB/voltdb/issues/2670/comments","statuses_url":"https://api.github.com/repos/VoltDB/voltdb/statuses/13a756d9167f90338a32a503da590db8af765804","head":{"label":"VoltDB:ENG-8641-plan-based-mview-minmax","ref":"ENG-8641-plan-based-mview-minmax","sha":"13a756d9167f90338a32a503da590db8af765804","user":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"repo":{"id":2445970,"name":"voltdb","full_name":"VoltDB/voltdb","owner":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/VoltDB/voltdb","description":"VoltDB","fork":false,"url":"https://api.github.com/repos/VoltDB/voltdb","forks_url":"https://api.github.com/repos/VoltDB/voltdb/forks","keys_url":"https://api.github.com/repos/VoltDB/voltdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/VoltDB/voltdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/VoltDB/voltdb/teams","hooks_url":"https://api.github.com/repos/VoltDB/voltdb/hooks","issue_events_url":"https://api.github.com/repos/VoltDB/voltdb/issues/events{/number}","events_url":"https://api.github.com/repos/VoltDB/voltdb/events","assignees_url":"https://api.github.com/repos/VoltDB/voltdb/assignees{/user}","branches_url":"https://api.github.com/repos/VoltDB/voltdb/branches{/branch}","tags_url":"https://api.github.com/repos/VoltDB/voltdb/tags","blobs_url":"https://api.github.com/repos/VoltDB/voltdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/VoltDB/voltdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/VoltDB/voltdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/VoltDB/voltdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/VoltDB/voltdb/statuses/{sha}","languages_url":"https://api.github.com/repos/VoltDB/voltdb/languages","stargazers_url":"https://api.github.com/repos/VoltDB/voltdb/stargazers","contributors_url":"https://api.github.com/repos/VoltDB/voltdb/contributors","subscribers_url":"https://api.github.com/repos/VoltDB/voltdb/subscribers","subscription_url":"https://api.github.com/repos/VoltDB/voltdb/subscription","commits_url":"https://api.github.com/repos/VoltDB/voltdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/VoltDB/voltdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/VoltDB/voltdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/VoltDB/voltdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/VoltDB/voltdb/contents/{+path}","compare_url":"https://api.github.com/repos/VoltDB/voltdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/VoltDB/voltdb/merges","archive_url":"https://api.github.com/repos/VoltDB/voltdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/VoltDB/voltdb/downloads","issues_url":"https://api.github.com/repos/VoltDB/voltdb/issues{/number}","pulls_url":"https://api.github.com/repos/VoltDB/voltdb/pulls{/number}","milestones_url":"https://api.github.com/repos/VoltDB/voltdb/milestones{/number}","notifications_url":"https://api.github.com/repos/VoltDB/voltdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/VoltDB/voltdb/labels{/name}","releases_url":"https://api.github.com/repos/VoltDB/voltdb/releases{/id}","created_at":"2011-09-23T18:46:12Z","updated_at":"2015-08-07T09:08:47Z","pushed_at":"2015-08-08T18:34:15Z","git_url":"git://github.com/VoltDB/voltdb.git","ssh_url":"git@github.com:VoltDB/voltdb.git","clone_url":"https://github.com/VoltDB/voltdb.git","svn_url":"https://github.com/VoltDB/voltdb","homepage":"http://community.voltdb.com/","size":877083,"stargazers_count":608,"watchers_count":608,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":180,"mirror_url":null,"open_issues_count":30,"forks":180,"open_issues":30,"watchers":608,"default_branch":"master"}},"base":{"label":"VoltDB:master","ref":"master","sha":"c6b0bb7e67dce622cf13883466c0c8a96c350470","user":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"repo":{"id":2445970,"name":"voltdb","full_name":"VoltDB/voltdb","owner":{"login":"VoltDB","id":703910,"avatar_url":"https://avatars.githubusercontent.com/u/703910?v=3","gravatar_id":"","url":"https://api.github.com/users/VoltDB","html_url":"https://github.com/VoltDB","followers_url":"https://api.github.com/users/VoltDB/followers","following_url":"https://api.github.com/users/VoltDB/following{/other_user}","gists_url":"https://api.github.com/users/VoltDB/gists{/gist_id}","starred_url":"https://api.github.com/users/VoltDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VoltDB/subscriptions","organizations_url":"https://api.github.com/users/VoltDB/orgs","repos_url":"https://api.github.com/users/VoltDB/repos","events_url":"https://api.github.com/users/VoltDB/events{/privacy}","received_events_url":"https://api.github.com/users/VoltDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/VoltDB/voltdb","description":"VoltDB","fork":false,"url":"https://api.github.com/repos/VoltDB/voltdb","forks_url":"https://api.github.com/repos/VoltDB/voltdb/forks","keys_url":"https://api.github.com/repos/VoltDB/voltdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/VoltDB/voltdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/VoltDB/voltdb/teams","hooks_url":"https://api.github.com/repos/VoltDB/voltdb/hooks","issue_events_url":"https://api.github.com/repos/VoltDB/voltdb/issues/events{/number}","events_url":"https://api.github.com/repos/VoltDB/voltdb/events","assignees_url":"https://api.github.com/repos/VoltDB/voltdb/assignees{/user}","branches_url":"https://api.github.com/repos/VoltDB/voltdb/branches{/branch}","tags_url":"https://api.github.com/repos/VoltDB/voltdb/tags","blobs_url":"https://api.github.com/repos/VoltDB/voltdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/VoltDB/voltdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/VoltDB/voltdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/VoltDB/voltdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/VoltDB/voltdb/statuses/{sha}","languages_url":"https://api.github.com/repos/VoltDB/voltdb/languages","stargazers_url":"https://api.github.com/repos/VoltDB/voltdb/stargazers","contributors_url":"https://api.github.com/repos/VoltDB/voltdb/contributors","subscribers_url":"https://api.github.com/repos/VoltDB/voltdb/subscribers","subscription_url":"https://api.github.com/repos/VoltDB/voltdb/subscription","commits_url":"https://api.github.com/repos/VoltDB/voltdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/VoltDB/voltdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/VoltDB/voltdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/VoltDB/voltdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/VoltDB/voltdb/contents/{+path}","compare_url":"https://api.github.com/repos/VoltDB/voltdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/VoltDB/voltdb/merges","archive_url":"https://api.github.com/repos/VoltDB/voltdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/VoltDB/voltdb/downloads","issues_url":"https://api.github.com/repos/VoltDB/voltdb/issues{/number}","pulls_url":"https://api.github.com/repos/VoltDB/voltdb/pulls{/number}","milestones_url":"https://api.github.com/repos/VoltDB/voltdb/milestones{/number}","notifications_url":"https://api.github.com/repos/VoltDB/voltdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/VoltDB/voltdb/labels{/name}","releases_url":"https://api.github.com/repos/VoltDB/voltdb/releases{/id}","created_at":"2011-09-23T18:46:12Z","updated_at":"2015-08-07T09:08:47Z","pushed_at":"2015-08-08T18:34:15Z","git_url":"git://github.com/VoltDB/voltdb.git","ssh_url":"git@github.com:VoltDB/voltdb.git","clone_url":"https://github.com/VoltDB/voltdb.git","svn_url":"https://github.com/VoltDB/voltdb","homepage":"http://community.voltdb.com/","size":877083,"stargazers_count":608,"watchers_count":608,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":180,"mirror_url":null,"open_issues_count":30,"forks":180,"open_issues":30,"watchers":608,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670"},"html":{"href":"https://github.com/VoltDB/voltdb/pull/2670"},"issue":{"href":"https://api.github.com/repos/VoltDB/voltdb/issues/2670"},"comments":{"href":"https://api.github.com/repos/VoltDB/voltdb/issues/2670/comments"},"review_comments":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670/comments"},"review_comment":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/2670/commits"},"statuses":{"href":"https://api.github.com/repos/VoltDB/voltdb/statuses/13a756d9167f90338a32a503da590db8af765804"}}}}