{"action":"created","comment":{"url":"https://api.github.com/repos/crate/crate/pulls/comments/40291041","id":40291041,"diff_hunk":"@@ -0,0 +1,125 @@\n+/*\n+ * Licensed to CRATE Technology GmbH (\"Crate\") under one or more contributor\n+ * license agreements.  See the NOTICE file distributed with this work for\n+ * additional information regarding copyright ownership.  Crate licenses\n+ * this file to you under the Apache License, Version 2.0 (the \"License\");\n+ * you may 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, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the\n+ * License for the specific language governing permissions and limitations\n+ * 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 agreement.\n+ */\n+\n+package io.crate.operation.scalar;\n+\n+import io.crate.metadata.*;\n+import io.crate.operation.Input;\n+import io.crate.planner.symbol.Function;\n+import io.crate.planner.symbol.Literal;\n+import io.crate.planner.symbol.Symbol;\n+import io.crate.types.DataType;\n+import io.crate.types.ArrayType;\n+import io.crate.types.DataTypes;\n+import io.crate.types.UndefinedType;\n+import org.elasticsearch.common.Preconditions;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Locale;\n+\n+public class ArrayCatFunction extends Scalar<Object[], Object> {\n+\n+    public static final String NAME = \"array_cat\";\n+    private FunctionInfo functionInfo;\n+\n+    private static FunctionInfo createInfo(List<DataType> types) {\n+        ArrayType arrayType = (ArrayType) types.get(0);\n+        return new FunctionInfo(new FunctionIdent(NAME, types), arrayType);\n+    }\n+\n+    public static void register(ScalarFunctionModule module) {\n+        module.register(NAME, new Resolver());\n+    }\n+\n+    protected ArrayCatFunction(FunctionInfo functionInfo) {\n+        this.functionInfo = functionInfo;\n+    }\n+\n+    @Override\n+    public FunctionInfo info() {\n+        return functionInfo;\n+    }\n+\n+    @Override\n+    public Symbol normalizeSymbol(Function symbol) {\n+        if (anyNonLiterals(symbol.arguments())) {\n+            return symbol;\n+        }\n+\n+        Input[] argList = new Input[symbol.arguments().size()];\n+        int counter = 0;\n+        for(Symbol argSymbol : symbol.arguments()){\n+            Input input  = (Input) argSymbol;\n+            argList[counter++] = input;\n+        }\n+\n+        return Literal.newLiteral(evaluate(argList), this.info().returnType());\n+    }\n+\n+    @Override\n+    public Object[] evaluate(Input[] args) {\n+        int counter = 0;\n+        for(Input array : args){\n+            Object[] arg = (Object[]) array.value();","path":"sql/src/main/java/io/crate/operation/scalar/ArrayCatFunction.java","position":82,"original_position":82,"commit_id":"beee6dcb051a6a88ac2aafe4b4d381744fffd86e","original_commit_id":"beee6dcb051a6a88ac2aafe4b4d381744fffd86e","user":{"login":"mfelsche","id":1152667,"avatar_url":"https://avatars.githubusercontent.com/u/1152667?v=3","gravatar_id":"","url":"https://api.github.com/users/mfelsche","html_url":"https://github.com/mfelsche","followers_url":"https://api.github.com/users/mfelsche/followers","following_url":"https://api.github.com/users/mfelsche/following{/other_user}","gists_url":"https://api.github.com/users/mfelsche/gists{/gist_id}","starred_url":"https://api.github.com/users/mfelsche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfelsche/subscriptions","organizations_url":"https://api.github.com/users/mfelsche/orgs","repos_url":"https://api.github.com/users/mfelsche/repos","events_url":"https://api.github.com/users/mfelsche/events{/privacy}","received_events_url":"https://api.github.com/users/mfelsche/received_events","type":"User","site_admin":false},"body":"``arg`` can be null.\r\ni think you should keep any values (including ``null``) in the arrays you concatenate.\r\nwhat you really want to do is either ignore ``null`` arguments or return ``null`` if you encounter ``null`` (not as array element but as argument to your function)","created_at":"2015-09-24T07:17:47Z","updated_at":"2015-09-24T07:17:47Z","html_url":"https://github.com/crate/crate/pull/2619#discussion_r40291041","pull_request_url":"https://api.github.com/repos/crate/crate/pulls/2619","_links":{"self":{"href":"https://api.github.com/repos/crate/crate/pulls/comments/40291041"},"html":{"href":"https://github.com/crate/crate/pull/2619#discussion_r40291041"},"pull_request":{"href":"https://api.github.com/repos/crate/crate/pulls/2619"}}},"pull_request":{"url":"https://api.github.com/repos/crate/crate/pulls/2619","id":45588258,"html_url":"https://github.com/crate/crate/pull/2619","diff_url":"https://github.com/crate/crate/pull/2619.diff","patch_url":"https://github.com/crate/crate/pull/2619.patch","issue_url":"https://api.github.com/repos/crate/crate/issues/2619","number":2619,"state":"open","locked":false,"title":"Array functions module","user":{"login":"gmrodrigues","id":3968052,"avatar_url":"https://avatars.githubusercontent.com/u/3968052?v=3","gravatar_id":"","url":"https://api.github.com/users/gmrodrigues","html_url":"https://github.com/gmrodrigues","followers_url":"https://api.github.com/users/gmrodrigues/followers","following_url":"https://api.github.com/users/gmrodrigues/following{/other_user}","gists_url":"https://api.github.com/users/gmrodrigues/gists{/gist_id}","starred_url":"https://api.github.com/users/gmrodrigues/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmrodrigues/subscriptions","organizations_url":"https://api.github.com/users/gmrodrigues/orgs","repos_url":"https://api.github.com/users/gmrodrigues/repos","events_url":"https://api.github.com/users/gmrodrigues/events{/privacy}","received_events_url":"https://api.github.com/users/gmrodrigues/received_events","type":"User","site_admin":false},"body":"Related to issue: support append to array on update (set array_field += new_element) #2566\r\n\r\n```\r\nArray Functions\r\n=================\r\n\r\narray_merge(first_array, second_array, [ third_array , ... ]) returns array\r\n-------------------------------------------------------------------\r\n\r\nThe ``array_merge`` function merges one or more arrays into one array\r\n\r\n::\r\n\r\n    cr> select array_merge([1,2,3],[3,4,5,6],[7,9,10]) from sys.cluster;\r\n    +-------------------------------------------+\r\n    | array_merge([1,2,3], [3,4,5,6], [7,9,10]) |\r\n    +-------------------------------------------+\r\n    | [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]           |\r\n    +-------------------------------------------+\r\n    SELECT 1 row in set (0.004 sec)\r\n\r\n\r\nIt can be used to append elements to array fields\r\n\r\n    cr> create table array_merge_example (list array(integer));\r\n    CREATE OK (0.384 sec)\r\n    cr> insert into array_merge_example (list) values ([1,2,3]);\r\n    INSERT OK, 1 row affected (0.303 sec)\r\n    cr> update array_merge_example set list = array_merge(list,[4,5,6]);\r\n    UPDATE OK, 1 row affected (0.372 sec)\r\n    cr> select * from array_merge_example;\r\n    +--------------------+\r\n    | list               |\r\n    +--------------------+\r\n    | [1, 2, 3, 4, 5, 6] |\r\n    +--------------------+\r\n    SELECT 1 row in set (0.037 sec)\r\n\r\narray_unique(first_array, [ second_array , ... ]) returns array\r\n-------------------------------------------------------------------\r\n\r\nThe ``array_unique`` function merges one or more arrays into one array with unique elements\r\n\r\n::\r\n\r\n    cr> select array_unique([1,2,3],[3,4,5,6],[7,9,10]) from sys.cluster;\r\n    +--------------------------------------------+\r\n    | array_unique([1,2,3], [3,4,5,6], [7,9,10]) |\r\n    +--------------------------------------------+\r\n    | [1, 2, 3, 4, 5, 6, 7, 9, 10]               |\r\n    +--------------------------------------------+\r\n    SELECT 1 row in set (0.007 sec)\r\n\r\n\r\nIt can be used with one argument\r\n\r\n    cr> select array_unique([1,2,3,3,4,5,6,7,5,6,9,10]) from sys.cluster;\r\n    +------------------------------------------+\r\n    | array_unique([1,2,3,3,4,5,6,7,5,6,9,10]) |\r\n    +------------------------------------------+\r\n    | [1, 2, 3, 4, 5, 6, 7, 9, 10]             |\r\n    +------------------------------------------+\r\n    SELECT 1 row in set (0.009 sec)\r\n\r\narray_subtract(first_array, second_array, [ third_array , ... ]) returns array\r\n-------------------------------------------------------------------\r\n\r\nThe ``array_subtract`` function subtracts elements from the first array\r\n\r\n::\r\n\r\n    cr> select array_subtract([1,2,3,4,5,6,7,8,9,10],[2,3],[6,9],[15]) from sys.cluster;\r\n    +------------------------------------------------------------+\r\n    | array_subtract([1,2,3,4,5,6,7,8,9,10], [2,3], [6,9], [15]) |\r\n    +------------------------------------------------------------+\r\n    | [1, 4, 5, 7, 8, 10]                                        |\r\n    +------------------------------------------------------------+\r\n    SELECT 1 row in set (0.009 sec)\r\n\r\n\r\nIt can be used to remove elements from array fields\r\n\r\n    cr> insert into array_subtract_example (list) values ([1,2,3,4,5,6,7,8,9,10]);\r\n    INSERT OK, 1 row affected (0.015 sec)\r\n    cr> update array_subtract_example set list = array_subtract(list,[6]);\r\n    UPDATE OK, 1 row affected (0.017 sec)\r\n    cr> select * from array_subtract_example;\r\n    +------------------------------+\r\n    | list                         |\r\n    +------------------------------+\r\n    | [1, 2, 3, 4, 5, 7, 8, 9, 10] |\r\n    +------------------------------+\r\n    SELECT 1 row in set (0.009 sec)\r\n```","created_at":"2015-09-21T19:21:03Z","updated_at":"2015-09-24T07:17:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2ef01f81ad899df61df125acade7fbcb6237ea1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/crate/crate/pulls/2619/commits","review_comments_url":"https://api.github.com/repos/crate/crate/pulls/2619/comments","review_comment_url":"https://api.github.com/repos/crate/crate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crate/crate/issues/2619/comments","statuses_url":"https://api.github.com/repos/crate/crate/statuses/beee6dcb051a6a88ac2aafe4b4d381744fffd86e","head":{"label":"gmrodrigues:array_functions_module","ref":"array_functions_module","sha":"beee6dcb051a6a88ac2aafe4b4d381744fffd86e","user":{"login":"gmrodrigues","id":3968052,"avatar_url":"https://avatars.githubusercontent.com/u/3968052?v=3","gravatar_id":"","url":"https://api.github.com/users/gmrodrigues","html_url":"https://github.com/gmrodrigues","followers_url":"https://api.github.com/users/gmrodrigues/followers","following_url":"https://api.github.com/users/gmrodrigues/following{/other_user}","gists_url":"https://api.github.com/users/gmrodrigues/gists{/gist_id}","starred_url":"https://api.github.com/users/gmrodrigues/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmrodrigues/subscriptions","organizations_url":"https://api.github.com/users/gmrodrigues/orgs","repos_url":"https://api.github.com/users/gmrodrigues/repos","events_url":"https://api.github.com/users/gmrodrigues/events{/privacy}","received_events_url":"https://api.github.com/users/gmrodrigues/received_events","type":"User","site_admin":false},"repo":{"id":42742823,"name":"crate","full_name":"gmrodrigues/crate","owner":{"login":"gmrodrigues","id":3968052,"avatar_url":"https://avatars.githubusercontent.com/u/3968052?v=3","gravatar_id":"","url":"https://api.github.com/users/gmrodrigues","html_url":"https://github.com/gmrodrigues","followers_url":"https://api.github.com/users/gmrodrigues/followers","following_url":"https://api.github.com/users/gmrodrigues/following{/other_user}","gists_url":"https://api.github.com/users/gmrodrigues/gists{/gist_id}","starred_url":"https://api.github.com/users/gmrodrigues/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmrodrigues/subscriptions","organizations_url":"https://api.github.com/users/gmrodrigues/orgs","repos_url":"https://api.github.com/users/gmrodrigues/repos","events_url":"https://api.github.com/users/gmrodrigues/events{/privacy}","received_events_url":"https://api.github.com/users/gmrodrigues/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gmrodrigues/crate","description":"CRATE: Your Elastic Data Store","fork":true,"url":"https://api.github.com/repos/gmrodrigues/crate","forks_url":"https://api.github.com/repos/gmrodrigues/crate/forks","keys_url":"https://api.github.com/repos/gmrodrigues/crate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gmrodrigues/crate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gmrodrigues/crate/teams","hooks_url":"https://api.github.com/repos/gmrodrigues/crate/hooks","issue_events_url":"https://api.github.com/repos/gmrodrigues/crate/issues/events{/number}","events_url":"https://api.github.com/repos/gmrodrigues/crate/events","assignees_url":"https://api.github.com/repos/gmrodrigues/crate/assignees{/user}","branches_url":"https://api.github.com/repos/gmrodrigues/crate/branches{/branch}","tags_url":"https://api.github.com/repos/gmrodrigues/crate/tags","blobs_url":"https://api.github.com/repos/gmrodrigues/crate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gmrodrigues/crate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gmrodrigues/crate/git/refs{/sha}","trees_url":"https://api.github.com/repos/gmrodrigues/crate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gmrodrigues/crate/statuses/{sha}","languages_url":"https://api.github.com/repos/gmrodrigues/crate/languages","stargazers_url":"https://api.github.com/repos/gmrodrigues/crate/stargazers","contributors_url":"https://api.github.com/repos/gmrodrigues/crate/contributors","subscribers_url":"https://api.github.com/repos/gmrodrigues/crate/subscribers","subscription_url":"https://api.github.com/repos/gmrodrigues/crate/subscription","commits_url":"https://api.github.com/repos/gmrodrigues/crate/commits{/sha}","git_commits_url":"https://api.github.com/repos/gmrodrigues/crate/git/commits{/sha}","comments_url":"https://api.github.com/repos/gmrodrigues/crate/comments{/number}","issue_comment_url":"https://api.github.com/repos/gmrodrigues/crate/issues/comments{/number}","contents_url":"https://api.github.com/repos/gmrodrigues/crate/contents/{+path}","compare_url":"https://api.github.com/repos/gmrodrigues/crate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gmrodrigues/crate/merges","archive_url":"https://api.github.com/repos/gmrodrigues/crate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gmrodrigues/crate/downloads","issues_url":"https://api.github.com/repos/gmrodrigues/crate/issues{/number}","pulls_url":"https://api.github.com/repos/gmrodrigues/crate/pulls{/number}","milestones_url":"https://api.github.com/repos/gmrodrigues/crate/milestones{/number}","notifications_url":"https://api.github.com/repos/gmrodrigues/crate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gmrodrigues/crate/labels{/name}","releases_url":"https://api.github.com/repos/gmrodrigues/crate/releases{/id}","created_at":"2015-09-18T19:23:37Z","updated_at":"2015-09-18T19:23:43Z","pushed_at":"2015-09-23T23:36:31Z","git_url":"git://github.com/gmrodrigues/crate.git","ssh_url":"git@github.com:gmrodrigues/crate.git","clone_url":"https://github.com/gmrodrigues/crate.git","svn_url":"https://github.com/gmrodrigues/crate","homepage":"https://crate.io","size":46208,"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":"crate:master","ref":"master","sha":"a9a77408282fdb8ed3221c0ecc47a44e7b164920","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: Your Elastic Data Store","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}","created_at":"2013-04-10T09:17:16Z","updated_at":"2015-09-23T12:49:05Z","pushed_at":"2015-09-23T23:36:31Z","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":109994,"stargazers_count":1021,"watchers_count":1021,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":110,"mirror_url":null,"open_issues_count":56,"forks":110,"open_issues":56,"watchers":1021,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crate/crate/pulls/2619"},"html":{"href":"https://github.com/crate/crate/pull/2619"},"issue":{"href":"https://api.github.com/repos/crate/crate/issues/2619"},"comments":{"href":"https://api.github.com/repos/crate/crate/issues/2619/comments"},"review_comments":{"href":"https://api.github.com/repos/crate/crate/pulls/2619/comments"},"review_comment":{"href":"https://api.github.com/repos/crate/crate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crate/crate/pulls/2619/commits"},"statuses":{"href":"https://api.github.com/repos/crate/crate/statuses/beee6dcb051a6a88ac2aafe4b4d381744fffd86e"}}}}