{"action":"created","comment":{"url":"https://api.github.com/repos/apache/vxquery/pulls/comments/33403885","id":33403885,"diff_hunk":"@@ -0,0 +1,171 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may 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 implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.apache.vxquery.compiler.rewriter.rules;\n+\n+import java.io.DataInputStream;\n+import java.io.DataOutput;\n+import java.io.File;\n+import java.io.IOException;\n+import java.nio.ByteBuffer;\n+import java.util.Arrays;\n+import java.util.List;\n+\n+import org.apache.commons.lang3.mutable.Mutable;\n+import org.apache.vxquery.compiler.algebricks.VXQueryConstantValue;\n+import org.apache.vxquery.compiler.rewriter.rules.util.ExpressionToolbox;\n+import org.apache.vxquery.compiler.rewriter.rules.util.OperatorToolbox;\n+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;\n+import org.apache.vxquery.datamodel.builders.atomic.StringValueBuilder;\n+import org.apache.vxquery.datamodel.values.ValueTag;\n+import org.apache.vxquery.functions.BuiltinFunctions;\n+import org.apache.vxquery.metadata.VXQueryMetadataProvider;\n+import org.apache.vxquery.types.BuiltinTypeRegistry;\n+import org.apache.vxquery.types.Quantifier;\n+import org.apache.vxquery.types.SequenceType;\n+\n+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;\n+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;\n+import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;\n+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;\n+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;\n+import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;\n+\n+/**\n+ * The rule searches for where the function_doc1 function is in the plan in place of XQuery function.\n+ * It replaces the string contained in the function with its absolute file path.\n+ * \n+ * <pre>\n+ * Before\n+ * \n+ *   plan__parent\n+ *   %OPERATOR( $v1 : function_doc1( \\@string ) )\n+ *   plan__child\n+ *   \n+ *   Where xquery_function creates an atomic value.\n+ *   \n+ * After \n+ * \n+ *   plan__parent\n+ *   %OPERATOR( $v1 : function_doc1( \\@absolute_file_path ) ) )\n+ *   plan__child\n+ * </pre>\n+ * \n+ * @author shivanim\n+ */\n+\n+public class ConvertDocExpressionToFile implements IAlgebraicRewriteRule {\n+\n+    final ByteBufferInputStream bbis = new ByteBufferInputStream();\n+    final DataInputStream di = new DataInputStream(bbis);\n+    final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();\n+    final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();\n+    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();\n+    final DataOutput dOut = abvs.getDataOutput();\n+\n+    @Override\n+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {\n+        // TODO Auto-generated method stub\n+        return false;\n+    }\n+\n+    @Override\n+    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)\n+            throws AlgebricksException {\n+        boolean modified = false;\n+        List<Mutable<ILogicalExpression>> expressions = OperatorToolbox.getExpressions(opRef);\n+        for (Mutable<ILogicalExpression> expression : expressions) {\n+            Mutable<ILogicalExpression> docExpression = ExpressionToolbox.findFirstFunctionExpression(expression,\n+                    BuiltinFunctions.FN_DOC_1.getFunctionIdentifier());\n+            if (docExpression != null) {\n+                AbstractFunctionCallExpression absFnCall = (AbstractFunctionCallExpression) docExpression.getValue();\n+                if (docExpression != null && ifDocExpressionFound(opRef, absFnCall.getArguments().get(0), context)) {\n+                    modified = true;\n+                }\n+            }\n+        }\n+        return modified;\n+    }\n+\n+    protected boolean ifDocExpressionFound(Mutable<ILogicalOperator> opRef, Mutable<ILogicalExpression> funcExpression,\n+            IOptimizationContext context) {\n+        VXQueryConstantValue constantValue = null;\n+        ConstantExpression constantExpression = null;\n+        ILogicalExpression logicalExpression = (ILogicalExpression) funcExpression.getValue();\n+\n+        if (logicalExpression.getExpressionTag() == LogicalExpressionTag.CONSTANT) {\n+\n+            constantExpression = (ConstantExpression) logicalExpression;\n+            constantValue = (VXQueryConstantValue) constantExpression.getValue();\n+        } else if (logicalExpression.getExpressionTag() == LogicalExpressionTag.VARIABLE) {\n+\n+            VariableReferenceExpression varLogicalExpression = (VariableReferenceExpression) logicalExpression;\n+            Mutable<ILogicalOperator> lop = OperatorToolbox.findProducerOf(opRef,\n+                    varLogicalExpression.getVariableReference());\n+            ILogicalExpression variableLogicalExpression = (ILogicalExpression) OperatorToolbox.getExpressionOf(lop,\n+                    varLogicalExpression.getVariableReference()).getValue();\n+            if (variableLogicalExpression.getExpressionTag() != LogicalExpressionTag.CONSTANT) {\n+                return false;\n+            }\n+            constantExpression = (ConstantExpression) variableLogicalExpression;\n+            constantValue = (VXQueryConstantValue) constantExpression.getValue();\n+        } else {\n+            return false;\n+        }\n+\n+        if (constantValue.getType() != SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE)) {\n+            return false;\n+        }\n+        tvp.set(constantValue.getValue(), 0, constantValue.getValue().length);\n+        String collectionName = null;\n+        tvp.getValue(stringp);\n+        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {\n+            return false;\n+        }\n+        try {","path":"vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertDocExpressionToFile.java","position":144,"original_position":144,"commit_id":"58ee9244dd175c77c768b8ff72ddcb21c0a5a231","original_commit_id":"58ee9244dd175c77c768b8ff72ddcb21c0a5a231","user":{"login":"shivani1494","id":5581525,"avatar_url":"https://avatars.githubusercontent.com/u/5581525?v=3","gravatar_id":"","url":"https://api.github.com/users/shivani1494","html_url":"https://github.com/shivani1494","followers_url":"https://api.github.com/users/shivani1494/followers","following_url":"https://api.github.com/users/shivani1494/following{/other_user}","gists_url":"https://api.github.com/users/shivani1494/gists{/gist_id}","starred_url":"https://api.github.com/users/shivani1494/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shivani1494/subscriptions","organizations_url":"https://api.github.com/users/shivani1494/orgs","repos_url":"https://api.github.com/users/shivani1494/repos","events_url":"https://api.github.com/users/shivani1494/events{/privacy}","received_events_url":"https://api.github.com/users/shivani1494/received_events","type":"User","site_admin":false},"body":"Did you mean the following?\r\ntvp.set(constantValue.getValue(), 0, constantValue.getValue().length);\r\n        tvp.getValue(stringp);\r\n        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {\r\n            return false;\r\n        }\r\n        stringp.toString(toStr);\r\n        docArg = toStr.toString();\r\n","created_at":"2015-06-26T23:11:22Z","updated_at":"2015-06-26T23:11:22Z","html_url":"https://github.com/apache/vxquery/pull/8#discussion_r33403885","pull_request_url":"https://api.github.com/repos/apache/vxquery/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/apache/vxquery/pulls/comments/33403885"},"html":{"href":"https://github.com/apache/vxquery/pull/8#discussion_r33403885"},"pull_request":{"href":"https://api.github.com/repos/apache/vxquery/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/apache/vxquery/pulls/8","id":38284685,"html_url":"https://github.com/apache/vxquery/pull/8","diff_url":"https://github.com/apache/vxquery/pull/8.diff","patch_url":"https://github.com/apache/vxquery/pull/8.patch","issue_url":"https://api.github.com/repos/apache/vxquery/issues/8","number":8,"state":"open","locked":false,"title":"Rewrite rule and test implemented to run fn:doc","user":{"login":"shivani1494","id":5581525,"avatar_url":"https://avatars.githubusercontent.com/u/5581525?v=3","gravatar_id":"","url":"https://api.github.com/users/shivani1494","html_url":"https://github.com/shivani1494","followers_url":"https://api.github.com/users/shivani1494/followers","following_url":"https://api.github.com/users/shivani1494/following{/other_user}","gists_url":"https://api.github.com/users/shivani1494/gists{/gist_id}","starred_url":"https://api.github.com/users/shivani1494/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shivani1494/subscriptions","organizations_url":"https://api.github.com/users/shivani1494/orgs","repos_url":"https://api.github.com/users/shivani1494/repos","events_url":"https://api.github.com/users/shivani1494/events{/privacy}","received_events_url":"https://api.github.com/users/shivani1494/received_events","type":"User","site_admin":false},"body":"I pushed some files(DocTest.xml, test.xml, test.xq) in my first commit. Please ignore them. Thanks!","created_at":"2015-06-22T22:42:55Z","updated_at":"2015-06-26T23:11:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94241a199420585249003c50840aa9e2a69cc64d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/vxquery/pulls/8/commits","review_comments_url":"https://api.github.com/repos/apache/vxquery/pulls/8/comments","review_comment_url":"https://api.github.com/repos/apache/vxquery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/vxquery/issues/8/comments","statuses_url":"https://api.github.com/repos/apache/vxquery/statuses/58ee9244dd175c77c768b8ff72ddcb21c0a5a231","head":{"label":"shivani1494:shivanim/docrewrite1","ref":"shivanim/docrewrite1","sha":"58ee9244dd175c77c768b8ff72ddcb21c0a5a231","user":{"login":"shivani1494","id":5581525,"avatar_url":"https://avatars.githubusercontent.com/u/5581525?v=3","gravatar_id":"","url":"https://api.github.com/users/shivani1494","html_url":"https://github.com/shivani1494","followers_url":"https://api.github.com/users/shivani1494/followers","following_url":"https://api.github.com/users/shivani1494/following{/other_user}","gists_url":"https://api.github.com/users/shivani1494/gists{/gist_id}","starred_url":"https://api.github.com/users/shivani1494/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shivani1494/subscriptions","organizations_url":"https://api.github.com/users/shivani1494/orgs","repos_url":"https://api.github.com/users/shivani1494/repos","events_url":"https://api.github.com/users/shivani1494/events{/privacy}","received_events_url":"https://api.github.com/users/shivani1494/received_events","type":"User","site_admin":false},"repo":{"id":35782115,"name":"vxquery","full_name":"shivani1494/vxquery","owner":{"login":"shivani1494","id":5581525,"avatar_url":"https://avatars.githubusercontent.com/u/5581525?v=3","gravatar_id":"","url":"https://api.github.com/users/shivani1494","html_url":"https://github.com/shivani1494","followers_url":"https://api.github.com/users/shivani1494/followers","following_url":"https://api.github.com/users/shivani1494/following{/other_user}","gists_url":"https://api.github.com/users/shivani1494/gists{/gist_id}","starred_url":"https://api.github.com/users/shivani1494/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shivani1494/subscriptions","organizations_url":"https://api.github.com/users/shivani1494/orgs","repos_url":"https://api.github.com/users/shivani1494/repos","events_url":"https://api.github.com/users/shivani1494/events{/privacy}","received_events_url":"https://api.github.com/users/shivani1494/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shivani1494/vxquery","description":"Mirror of Apache VXQuery","fork":true,"url":"https://api.github.com/repos/shivani1494/vxquery","forks_url":"https://api.github.com/repos/shivani1494/vxquery/forks","keys_url":"https://api.github.com/repos/shivani1494/vxquery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shivani1494/vxquery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shivani1494/vxquery/teams","hooks_url":"https://api.github.com/repos/shivani1494/vxquery/hooks","issue_events_url":"https://api.github.com/repos/shivani1494/vxquery/issues/events{/number}","events_url":"https://api.github.com/repos/shivani1494/vxquery/events","assignees_url":"https://api.github.com/repos/shivani1494/vxquery/assignees{/user}","branches_url":"https://api.github.com/repos/shivani1494/vxquery/branches{/branch}","tags_url":"https://api.github.com/repos/shivani1494/vxquery/tags","blobs_url":"https://api.github.com/repos/shivani1494/vxquery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shivani1494/vxquery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shivani1494/vxquery/git/refs{/sha}","trees_url":"https://api.github.com/repos/shivani1494/vxquery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shivani1494/vxquery/statuses/{sha}","languages_url":"https://api.github.com/repos/shivani1494/vxquery/languages","stargazers_url":"https://api.github.com/repos/shivani1494/vxquery/stargazers","contributors_url":"https://api.github.com/repos/shivani1494/vxquery/contributors","subscribers_url":"https://api.github.com/repos/shivani1494/vxquery/subscribers","subscription_url":"https://api.github.com/repos/shivani1494/vxquery/subscription","commits_url":"https://api.github.com/repos/shivani1494/vxquery/commits{/sha}","git_commits_url":"https://api.github.com/repos/shivani1494/vxquery/git/commits{/sha}","comments_url":"https://api.github.com/repos/shivani1494/vxquery/comments{/number}","issue_comment_url":"https://api.github.com/repos/shivani1494/vxquery/issues/comments{/number}","contents_url":"https://api.github.com/repos/shivani1494/vxquery/contents/{+path}","compare_url":"https://api.github.com/repos/shivani1494/vxquery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shivani1494/vxquery/merges","archive_url":"https://api.github.com/repos/shivani1494/vxquery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shivani1494/vxquery/downloads","issues_url":"https://api.github.com/repos/shivani1494/vxquery/issues{/number}","pulls_url":"https://api.github.com/repos/shivani1494/vxquery/pulls{/number}","milestones_url":"https://api.github.com/repos/shivani1494/vxquery/milestones{/number}","notifications_url":"https://api.github.com/repos/shivani1494/vxquery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shivani1494/vxquery/labels{/name}","releases_url":"https://api.github.com/repos/shivani1494/vxquery/releases{/id}","created_at":"2015-05-17T20:40:07Z","updated_at":"2015-06-11T15:24:54Z","pushed_at":"2015-06-26T22:01:22Z","git_url":"git://github.com/shivani1494/vxquery.git","ssh_url":"git@github.com:shivani1494/vxquery.git","clone_url":"https://github.com/shivani1494/vxquery.git","svn_url":"https://github.com/shivani1494/vxquery","homepage":null,"size":11848,"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"}},"base":{"label":"apache:master","ref":"master","sha":"169e71a9fd2e14e30f97eb0ecec044d168608a9a","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":32376873,"name":"vxquery","full_name":"apache/vxquery","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/vxquery","description":"Mirror of Apache VXQuery","fork":false,"url":"https://api.github.com/repos/apache/vxquery","forks_url":"https://api.github.com/repos/apache/vxquery/forks","keys_url":"https://api.github.com/repos/apache/vxquery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/vxquery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/vxquery/teams","hooks_url":"https://api.github.com/repos/apache/vxquery/hooks","issue_events_url":"https://api.github.com/repos/apache/vxquery/issues/events{/number}","events_url":"https://api.github.com/repos/apache/vxquery/events","assignees_url":"https://api.github.com/repos/apache/vxquery/assignees{/user}","branches_url":"https://api.github.com/repos/apache/vxquery/branches{/branch}","tags_url":"https://api.github.com/repos/apache/vxquery/tags","blobs_url":"https://api.github.com/repos/apache/vxquery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/vxquery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/vxquery/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/vxquery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/vxquery/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/vxquery/languages","stargazers_url":"https://api.github.com/repos/apache/vxquery/stargazers","contributors_url":"https://api.github.com/repos/apache/vxquery/contributors","subscribers_url":"https://api.github.com/repos/apache/vxquery/subscribers","subscription_url":"https://api.github.com/repos/apache/vxquery/subscription","commits_url":"https://api.github.com/repos/apache/vxquery/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/vxquery/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/vxquery/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/vxquery/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/vxquery/contents/{+path}","compare_url":"https://api.github.com/repos/apache/vxquery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/vxquery/merges","archive_url":"https://api.github.com/repos/apache/vxquery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/vxquery/downloads","issues_url":"https://api.github.com/repos/apache/vxquery/issues{/number}","pulls_url":"https://api.github.com/repos/apache/vxquery/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/vxquery/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/vxquery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/vxquery/labels{/name}","releases_url":"https://api.github.com/repos/apache/vxquery/releases{/id}","created_at":"2015-03-17T07:00:06Z","updated_at":"2015-05-31T06:05:13Z","pushed_at":"2015-06-26T22:01:23Z","git_url":"git://github.com/apache/vxquery.git","ssh_url":"git@github.com:apache/vxquery.git","clone_url":"https://github.com/apache/vxquery.git","svn_url":"https://github.com/apache/vxquery","homepage":null,"size":12071,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":"git://git.apache.org/vxquery.git","open_issues_count":3,"forks":9,"open_issues":3,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/vxquery/pulls/8"},"html":{"href":"https://github.com/apache/vxquery/pull/8"},"issue":{"href":"https://api.github.com/repos/apache/vxquery/issues/8"},"comments":{"href":"https://api.github.com/repos/apache/vxquery/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/vxquery/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/vxquery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/vxquery/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/apache/vxquery/statuses/58ee9244dd175c77c768b8ff72ddcb21c0a5a231"}}}}