{"action":"created","comment":{"url":"https://api.github.com/repos/guptapuneet/lens/pulls/comments/93925090","pull_request_review_id":14445078,"id":93925090,"diff_hunk":"@@ -205,4 +218,75 @@ public int compare(UnionCandidate o1, UnionCandidate o2) {\n       return Integer.valueOf(o1.getChildren().size() - o2.getChildren().size());\n     }\n   }\n+\n+  private static final String baseQueryFormat = \"SELECT %s FROM %s\";\n+\n+  public static String createHQLQuery(String select, String from, String where, String groupby, String orderby, String having,\n+                                      Integer limit) {\n+\n+    List<String> qstrs = new ArrayList<String>();\n+    qstrs.add(select);\n+    qstrs.add(from);\n+    if (!StringUtils.isBlank(where)) {\n+      qstrs.add(where);\n+    }\n+    if (!StringUtils.isBlank(groupby)) {\n+      qstrs.add(groupby);\n+    }\n+    if (!StringUtils.isBlank(having)) {\n+      qstrs.add(having);\n+    }\n+    if (!StringUtils.isBlank(orderby)) {\n+      qstrs.add(orderby);\n+    }\n+    if (limit != null) {\n+      qstrs.add(String.valueOf(limit));\n+    }\n+\n+    StringBuilder queryFormat = new StringBuilder();\n+    queryFormat.append(baseQueryFormat);\n+    if (!StringUtils.isBlank(where)) {\n+      queryFormat.append(\" WHERE %s\");\n+    }\n+    if (!StringUtils.isBlank(groupby)) {\n+      queryFormat.append(\" GROUP BY %s\");\n+    }\n+    if (!StringUtils.isBlank(having)) {\n+      queryFormat.append(\" HAVING %s\");\n+    }\n+    if (!StringUtils.isBlank(orderby)) {\n+      queryFormat.append(\" ORDER BY %s\");\n+    }\n+    if (limit != null) {\n+      queryFormat.append(\" LIMIT %s\");\n+    }\n+    return String.format(queryFormat.toString(), qstrs.toArray(new String[0]));\n+  }\n+\n+  public static void updateFinalAlias(ASTNode selectAST, CubeQueryContext cubeql) {\n+    for (int i = 0; i < selectAST.getChildCount(); i++) {\n+      ASTNode selectExpr = (ASTNode) selectAST.getChild(i);\n+      ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, Identifier);\n+      String finalAlias = cubeql.getSelectPhrases().get(i).getFinalAlias().replaceAll(\"`\", \"\");\n+      String actualAlias = cubeql.getSelectPhrases().get(i).getActualAlias();\n+      if (actualAlias == null && selectExpr.getChildCount() == 2 ) {\n+        selectExpr.deleteChild(1);","path":"lens-cube/src/main/java/org/apache/lens/cube/parse/CandidateUtil.java","position":122,"original_position":122,"commit_id":"b490e6f14da8b61ddfb1906a4cc3058eb2649ce3","original_commit_id":"b490e6f14da8b61ddfb1906a4cc3058eb2649ce3","user":{"login":"guptapuneet","id":9948264,"avatar_url":"https://avatars.githubusercontent.com/u/9948264?v=3","gravatar_id":"","url":"https://api.github.com/users/guptapuneet","html_url":"https://github.com/guptapuneet","followers_url":"https://api.github.com/users/guptapuneet/followers","following_url":"https://api.github.com/users/guptapuneet/following{/other_user}","gists_url":"https://api.github.com/users/guptapuneet/gists{/gist_id}","starred_url":"https://api.github.com/users/guptapuneet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guptapuneet/subscriptions","organizations_url":"https://api.github.com/users/guptapuneet/orgs","repos_url":"https://api.github.com/users/guptapuneet/repos","events_url":"https://api.github.com/users/guptapuneet/events{/privacy}","received_events_url":"https://api.github.com/users/guptapuneet/received_events","type":"User","site_admin":false},"body":"Can we add comments explaining why this was done ","created_at":"2016-12-27T12:09:48Z","updated_at":"2016-12-27T13:03:44Z","html_url":"https://github.com/guptapuneet/lens/pull/4#discussion_r93925090","pull_request_url":"https://api.github.com/repos/guptapuneet/lens/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/guptapuneet/lens/pulls/comments/93925090"},"html":{"href":"https://github.com/guptapuneet/lens/pull/4#discussion_r93925090"},"pull_request":{"href":"https://api.github.com/repos/guptapuneet/lens/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/guptapuneet/lens/pulls/4","id":98113982,"html_url":"https://github.com/guptapuneet/lens/pull/4","diff_url":"https://github.com/guptapuneet/lens/pull/4.diff","patch_url":"https://github.com/guptapuneet/lens/pull/4.patch","issue_url":"https://api.github.com/repos/guptapuneet/lens/issues/4","number":4,"state":"open","locked":false,"title":"Query rewrite phase 1 - Single StorageCandidate","user":{"login":"sushilmohanty","id":2369386,"avatar_url":"https://avatars.githubusercontent.com/u/2369386?v=3","gravatar_id":"","url":"https://api.github.com/users/sushilmohanty","html_url":"https://github.com/sushilmohanty","followers_url":"https://api.github.com/users/sushilmohanty/followers","following_url":"https://api.github.com/users/sushilmohanty/following{/other_user}","gists_url":"https://api.github.com/users/sushilmohanty/gists{/gist_id}","starred_url":"https://api.github.com/users/sushilmohanty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sushilmohanty/subscriptions","organizations_url":"https://api.github.com/users/sushilmohanty/orgs","repos_url":"https://api.github.com/users/sushilmohanty/repos","events_url":"https://api.github.com/users/sushilmohanty/events{/privacy}","received_events_url":"https://api.github.com/users/sushilmohanty/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-15T09:29:37Z","updated_at":"2016-12-27T13:03:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"736b06c88021db3dae73a9b402afa9997b0bc27b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/guptapuneet/lens/pulls/4/commits","review_comments_url":"https://api.github.com/repos/guptapuneet/lens/pulls/4/comments","review_comment_url":"https://api.github.com/repos/guptapuneet/lens/pulls/comments{/number}","comments_url":"https://api.github.com/repos/guptapuneet/lens/issues/4/comments","statuses_url":"https://api.github.com/repos/guptapuneet/lens/statuses/b490e6f14da8b61ddfb1906a4cc3058eb2649ce3","head":{"label":"sushilmohanty:union-refactor","ref":"union-refactor","sha":"b490e6f14da8b61ddfb1906a4cc3058eb2649ce3","user":{"login":"sushilmohanty","id":2369386,"avatar_url":"https://avatars.githubusercontent.com/u/2369386?v=3","gravatar_id":"","url":"https://api.github.com/users/sushilmohanty","html_url":"https://github.com/sushilmohanty","followers_url":"https://api.github.com/users/sushilmohanty/followers","following_url":"https://api.github.com/users/sushilmohanty/following{/other_user}","gists_url":"https://api.github.com/users/sushilmohanty/gists{/gist_id}","starred_url":"https://api.github.com/users/sushilmohanty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sushilmohanty/subscriptions","organizations_url":"https://api.github.com/users/sushilmohanty/orgs","repos_url":"https://api.github.com/users/sushilmohanty/repos","events_url":"https://api.github.com/users/sushilmohanty/events{/privacy}","received_events_url":"https://api.github.com/users/sushilmohanty/received_events","type":"User","site_admin":false},"repo":{"id":27164137,"name":"incubator-lens","full_name":"sushilmohanty/incubator-lens","owner":{"login":"sushilmohanty","id":2369386,"avatar_url":"https://avatars.githubusercontent.com/u/2369386?v=3","gravatar_id":"","url":"https://api.github.com/users/sushilmohanty","html_url":"https://github.com/sushilmohanty","followers_url":"https://api.github.com/users/sushilmohanty/followers","following_url":"https://api.github.com/users/sushilmohanty/following{/other_user}","gists_url":"https://api.github.com/users/sushilmohanty/gists{/gist_id}","starred_url":"https://api.github.com/users/sushilmohanty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sushilmohanty/subscriptions","organizations_url":"https://api.github.com/users/sushilmohanty/orgs","repos_url":"https://api.github.com/users/sushilmohanty/repos","events_url":"https://api.github.com/users/sushilmohanty/events{/privacy}","received_events_url":"https://api.github.com/users/sushilmohanty/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sushilmohanty/incubator-lens","description":"Mirror of Apache Lens","fork":true,"url":"https://api.github.com/repos/sushilmohanty/incubator-lens","forks_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/forks","keys_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/teams","hooks_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/hooks","issue_events_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/issues/events{/number}","events_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/events","assignees_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/assignees{/user}","branches_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/branches{/branch}","tags_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/tags","blobs_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/git/refs{/sha}","trees_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/statuses/{sha}","languages_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/languages","stargazers_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/stargazers","contributors_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/contributors","subscribers_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/subscribers","subscription_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/subscription","commits_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/commits{/sha}","git_commits_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/git/commits{/sha}","comments_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/comments{/number}","issue_comment_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/issues/comments{/number}","contents_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/contents/{+path}","compare_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/merges","archive_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/downloads","issues_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/issues{/number}","pulls_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/pulls{/number}","milestones_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/milestones{/number}","notifications_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/labels{/name}","releases_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/releases{/id}","deployments_url":"https://api.github.com/repos/sushilmohanty/incubator-lens/deployments","created_at":"2014-11-26T07:07:24Z","updated_at":"2016-02-02T09:01:09Z","pushed_at":"2016-12-27T08:39:16Z","git_url":"git://github.com/sushilmohanty/incubator-lens.git","ssh_url":"git@github.com:sushilmohanty/incubator-lens.git","clone_url":"https://github.com/sushilmohanty/incubator-lens.git","svn_url":"https://github.com/sushilmohanty/incubator-lens","homepage":null,"size":16616,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"guptapuneet:union-refactor","ref":"union-refactor","sha":"c55e8a204dc89793bc2d66566164d8f61a20b1f2","user":{"login":"guptapuneet","id":9948264,"avatar_url":"https://avatars.githubusercontent.com/u/9948264?v=3","gravatar_id":"","url":"https://api.github.com/users/guptapuneet","html_url":"https://github.com/guptapuneet","followers_url":"https://api.github.com/users/guptapuneet/followers","following_url":"https://api.github.com/users/guptapuneet/following{/other_user}","gists_url":"https://api.github.com/users/guptapuneet/gists{/gist_id}","starred_url":"https://api.github.com/users/guptapuneet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guptapuneet/subscriptions","organizations_url":"https://api.github.com/users/guptapuneet/orgs","repos_url":"https://api.github.com/users/guptapuneet/repos","events_url":"https://api.github.com/users/guptapuneet/events{/privacy}","received_events_url":"https://api.github.com/users/guptapuneet/received_events","type":"User","site_admin":false},"repo":{"id":42512048,"name":"lens","full_name":"guptapuneet/lens","owner":{"login":"guptapuneet","id":9948264,"avatar_url":"https://avatars.githubusercontent.com/u/9948264?v=3","gravatar_id":"","url":"https://api.github.com/users/guptapuneet","html_url":"https://github.com/guptapuneet","followers_url":"https://api.github.com/users/guptapuneet/followers","following_url":"https://api.github.com/users/guptapuneet/following{/other_user}","gists_url":"https://api.github.com/users/guptapuneet/gists{/gist_id}","starred_url":"https://api.github.com/users/guptapuneet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guptapuneet/subscriptions","organizations_url":"https://api.github.com/users/guptapuneet/orgs","repos_url":"https://api.github.com/users/guptapuneet/repos","events_url":"https://api.github.com/users/guptapuneet/events{/privacy}","received_events_url":"https://api.github.com/users/guptapuneet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/guptapuneet/lens","description":"Mirror of Apache Lens","fork":true,"url":"https://api.github.com/repos/guptapuneet/lens","forks_url":"https://api.github.com/repos/guptapuneet/lens/forks","keys_url":"https://api.github.com/repos/guptapuneet/lens/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guptapuneet/lens/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guptapuneet/lens/teams","hooks_url":"https://api.github.com/repos/guptapuneet/lens/hooks","issue_events_url":"https://api.github.com/repos/guptapuneet/lens/issues/events{/number}","events_url":"https://api.github.com/repos/guptapuneet/lens/events","assignees_url":"https://api.github.com/repos/guptapuneet/lens/assignees{/user}","branches_url":"https://api.github.com/repos/guptapuneet/lens/branches{/branch}","tags_url":"https://api.github.com/repos/guptapuneet/lens/tags","blobs_url":"https://api.github.com/repos/guptapuneet/lens/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guptapuneet/lens/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guptapuneet/lens/git/refs{/sha}","trees_url":"https://api.github.com/repos/guptapuneet/lens/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guptapuneet/lens/statuses/{sha}","languages_url":"https://api.github.com/repos/guptapuneet/lens/languages","stargazers_url":"https://api.github.com/repos/guptapuneet/lens/stargazers","contributors_url":"https://api.github.com/repos/guptapuneet/lens/contributors","subscribers_url":"https://api.github.com/repos/guptapuneet/lens/subscribers","subscription_url":"https://api.github.com/repos/guptapuneet/lens/subscription","commits_url":"https://api.github.com/repos/guptapuneet/lens/commits{/sha}","git_commits_url":"https://api.github.com/repos/guptapuneet/lens/git/commits{/sha}","comments_url":"https://api.github.com/repos/guptapuneet/lens/comments{/number}","issue_comment_url":"https://api.github.com/repos/guptapuneet/lens/issues/comments{/number}","contents_url":"https://api.github.com/repos/guptapuneet/lens/contents/{+path}","compare_url":"https://api.github.com/repos/guptapuneet/lens/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guptapuneet/lens/merges","archive_url":"https://api.github.com/repos/guptapuneet/lens/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guptapuneet/lens/downloads","issues_url":"https://api.github.com/repos/guptapuneet/lens/issues{/number}","pulls_url":"https://api.github.com/repos/guptapuneet/lens/pulls{/number}","milestones_url":"https://api.github.com/repos/guptapuneet/lens/milestones{/number}","notifications_url":"https://api.github.com/repos/guptapuneet/lens/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guptapuneet/lens/labels{/name}","releases_url":"https://api.github.com/repos/guptapuneet/lens/releases{/id}","deployments_url":"https://api.github.com/repos/guptapuneet/lens/deployments","created_at":"2015-09-15T10:40:34Z","updated_at":"2015-09-15T10:40:37Z","pushed_at":"2016-12-27T08:39:17Z","git_url":"git://github.com/guptapuneet/lens.git","ssh_url":"git@github.com:guptapuneet/lens.git","clone_url":"https://github.com/guptapuneet/lens.git","svn_url":"https://github.com/guptapuneet/lens","homepage":null,"size":16874,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/guptapuneet/lens/pulls/4"},"html":{"href":"https://github.com/guptapuneet/lens/pull/4"},"issue":{"href":"https://api.github.com/repos/guptapuneet/lens/issues/4"},"comments":{"href":"https://api.github.com/repos/guptapuneet/lens/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/guptapuneet/lens/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/guptapuneet/lens/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/guptapuneet/lens/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/guptapuneet/lens/statuses/b490e6f14da8b61ddfb1906a4cc3058eb2649ce3"}}}}
{"actor":{"display_login":"guptapuneet"}}