You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2014/01/30 07:23:12 UTC

[5/8] git commit: Some helpful utility queries and scripts.

Some helpful utility queries and scripts.


Project: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/commit/3ed22976
Tree: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/tree/3ed22976
Diff: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/diff/3ed22976

Branch: refs/heads/prestonc/benchmarks
Commit: 3ed229760c0de9ae0cc181a3ee444f070e54e23c
Parents: 7e65422
Author: Preston Carman <pr...@apache.org>
Authored: Wed Jan 29 19:52:24 2014 -0800
Committer: Preston Carman <pr...@apache.org>
Committed: Wed Jan 29 19:52:24 2014 -0800

----------------------------------------------------------------------
 .../util/format_query_plan_expression.py        | 86 ++++++++++++++++++++
 .../main/resources/util/vxquery_functions.xq    | 10 +++
 .../main/resources/util/vxquery_operators.xq    | 10 +++
 3 files changed, 106 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/3ed22976/vxquery-benchmark/src/main/resources/util/format_query_plan_expression.py
----------------------------------------------------------------------
diff --git a/vxquery-benchmark/src/main/resources/util/format_query_plan_expression.py b/vxquery-benchmark/src/main/resources/util/format_query_plan_expression.py
new file mode 100644
index 0000000..047b6aa
--- /dev/null
+++ b/vxquery-benchmark/src/main/resources/util/format_query_plan_expression.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import sys, os, getopt, string
+ 
+def main(argv):
+    expression_file = ""
+     
+    # Get the base folder
+    try:
+        opts, args = getopt.getopt(argv, "f:h", ["file="])
+    except getopt.GetoptError:
+        print 'The file options for format_query_plan_expression.py were not correctly specified.'
+        print 'To see a full list of options try:'
+        print '  $ python format_query_plan_expression.py -h'
+        sys.exit(2)
+    for opt, arg in opts:
+        if opt == '-h':
+            print 'Options:'
+            print '    -f        The filename for the expression string.'
+            sys.exit()
+        elif opt in ('-f', "--file"):
+            # check if file exists.
+            if os.path.exists(arg):
+                expression_file = arg
+            else:
+                print 'Error: Argument must be a filename for --file (-f).'
+                sys.exit()
+  
+    # Required fields to run the script.
+    if expression_file == "" or not os.path.exists(expression_file):
+        print 'Error: The filename option must be supplied:  --file (-f).'
+        sys.exit()
+      
+    # Read file string.
+    with open(expression_file, 'r') as f:
+        expression = f.readline();
+
+    skipping = False
+    with open(expression_file, 'a') as f:
+        
+        indent = 0
+        index = 0
+        end = len(expression)
+        while (index < end and index >= 0):
+            char_to_print = expression[index]
+            
+            if skipping:
+                if char_to_print is ")":
+                    skipping = False
+            elif char_to_print is "(":
+                skipping = True
+            elif char_to_print is "]":
+                indent -= 2
+                f.write("\n" + (" " * indent))
+                
+            f.write(char_to_print)
+
+            if skipping:
+                pass
+            elif char_to_print is ",":
+                f.write("\n" + (" " * indent))
+                index += 1
+            elif char_to_print is "[":
+                indent += 2
+                f.write("\n" + (" " * indent))
+                
+            index += 1
+        
+        f.close()
+
+if __name__ == "__main__":
+    main(sys.argv[1:])

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/3ed22976/vxquery-benchmark/src/main/resources/util/vxquery_functions.xq
----------------------------------------------------------------------
diff --git a/vxquery-benchmark/src/main/resources/util/vxquery_functions.xq b/vxquery-benchmark/src/main/resources/util/vxquery_functions.xq
new file mode 100644
index 0000000..4b8cd9a
--- /dev/null
+++ b/vxquery-benchmark/src/main/resources/util/vxquery_functions.xq
@@ -0,0 +1,10 @@
+(: XQuery Function List :)
+(: VXQuery function list in csv with arguments and return types :)
+let $list := "../../../../../vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml"
+let $r :=
+    for $f in fn:doc($list)/functions/function
+        let $pl := 
+            for $p in $f/param
+            return $p/@type
+        return fn:string-join((data($f/@name), fn:string-join($pl, ' '), data($f/return/@type)), ',')
+return fn:string-join($r , '|')
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/3ed22976/vxquery-benchmark/src/main/resources/util/vxquery_operators.xq
----------------------------------------------------------------------
diff --git a/vxquery-benchmark/src/main/resources/util/vxquery_operators.xq b/vxquery-benchmark/src/main/resources/util/vxquery_operators.xq
new file mode 100644
index 0000000..a60fc47
--- /dev/null
+++ b/vxquery-benchmark/src/main/resources/util/vxquery_operators.xq
@@ -0,0 +1,10 @@
+(: XQuery Function List :)
+(: VXQuery function list in csv with arguments and return types :)
+let $list := "../../../../../vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml"
+let $r :=
+    for $f in fn:doc($list)/operators/operator
+        let $pl := 
+            for $p in $f/param
+            return $p/@type
+        return fn:string-join((data($f/@name), fn:string-join($pl, ' '), data($f/return/@type)), ',')
+return fn:string-join($r , '|')
\ No newline at end of file