vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject git commit: improved printing of constants and types in plans
Date Mon, 17 Mar 2014 18:00:28 GMT
Repository: incubator-vxquery
Updated Branches:
  refs/heads/westmann/prettyprint 04ac20d12 -> 04c11094c


improved printing of constants and types in plans


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

Branch: refs/heads/westmann/prettyprint
Commit: 04c11094ccf8930de8d273709abb076c159ac4e5
Parents: 04ac20d
Author: Till Westmann <westmann@gmail.com>
Authored: Mon Mar 17 10:59:33 2014 -0700
Committer: Till Westmann <westmann@gmail.com>
Committed: Mon Mar 17 10:59:33 2014 -0700

----------------------------------------------------------------------
 .../algebricks/VXQueryConstantValue.java        |  2 +-
 ...ueryLogicalExpressionPrettyPrintVisitor.java | 26 +++++++++++++++++++-
 .../vxquery/serializer/XMLSerializer.java       |  2 +-
 .../org/apache/vxquery/types/AnyItemType.java   |  7 +++++-
 .../vxquery/types/BuiltinTypeRegistry.java      |  2 ++
 .../org/apache/vxquery/types/Quantifier.java    | 13 +++++++++-
 .../org/apache/vxquery/types/SequenceType.java  |  4 +--
 7 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/VXQueryConstantValue.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/VXQueryConstantValue.java
b/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/VXQueryConstantValue.java
index a0090b0..1cbe74e 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/VXQueryConstantValue.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/VXQueryConstantValue.java
@@ -57,7 +57,7 @@ public class VXQueryConstantValue implements IAlgebricksConstantValue {
     @Override
     public String toString() {
         StringBuilder buffer = new StringBuilder();
-        buffer.append(type).append("(bytes[").append(value.length).append("] = [").append(Hex.encodeHexString(value))
+        buffer.append(type).append(" (bytes[").append(value.length).append("] = [").append(Hex.encodeHexString(value))
                 .append("])");
         return buffer.toString();
     }

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/prettyprint/VXQueryLogicalExpressionPrettyPrintVisitor.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/prettyprint/VXQueryLogicalExpressionPrettyPrintVisitor.java
b/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/prettyprint/VXQueryLogicalExpressionPrettyPrintVisitor.java
index 48e923b..65ace85 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/prettyprint/VXQueryLogicalExpressionPrettyPrintVisitor.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/algebricks/prettyprint/VXQueryLogicalExpressionPrettyPrintVisitor.java
@@ -14,6 +14,9 @@
  */
 package org.apache.vxquery.compiler.algebricks.prettyprint;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
 import java.util.List;
 
 import org.apache.commons.lang3.mutable.Mutable;
@@ -22,6 +25,7 @@ import org.apache.vxquery.context.StaticContext;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.functions.BuiltinOperators;
+import org.apache.vxquery.serializer.XMLSerializer;
 import org.apache.vxquery.types.SequenceType;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -30,6 +34,7 @@ import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.StatefulFunctionCallExpression;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression;
@@ -43,16 +48,35 @@ public class VXQueryLogicalExpressionPrettyPrintVisitor implements ILogicalExpre
     StaticContext ctx;
     IntegerPointable ip;
     TaggedValuePointable tvp;
+    XMLSerializer serializer;
 
     public VXQueryLogicalExpressionPrettyPrintVisitor(StaticContext ctx) {
         this.ctx = ctx;
         this.ip = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
         this.tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+        this.serializer = new XMLSerializer();
     }
 
     @Override
     public String visitConstantExpression(ConstantExpression expr, Integer indent) throws
AlgebricksException {
-        return expr.toString();
+        IAlgebricksConstantValue value = expr.getValue();
+        if (value instanceof VXQueryConstantValue) {
+            VXQueryConstantValue vxqValue = (VXQueryConstantValue) value;
+            tvp.set(vxqValue.getValue(), 0, vxqValue.getValue().length);
+
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            PrintStream ps = new PrintStream(os);
+
+            serializer.printTaggedValuePointable(ps, tvp);
+
+            try {
+                return vxqValue.getType() + ": " + os.toString("UTF8");
+            } catch (UnsupportedEncodingException e) {
+                // print stack trace and return the default
+                e.printStackTrace();
+            }
+        }
+        return value.toString();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java b/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
index f2999bb..51670e8 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
@@ -79,7 +79,7 @@ public class XMLSerializer implements IPrinter {
         }
     }
 
-    private void printTaggedValuePointable(PrintStream ps, TaggedValuePointable tvp) {
+    public void printTaggedValuePointable(PrintStream ps, TaggedValuePointable tvp) {
         byte tag = tvp.getTag();
         switch ((int) tag) {
             case ValueTag.XS_ANY_URI_TAG:

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/types/AnyItemType.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/AnyItemType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/AnyItemType.java
index ce7de21..32cd3b0 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/AnyItemType.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/AnyItemType.java
@@ -36,4 +36,9 @@ public final class AnyItemType implements ItemType {
     public boolean equals(Object other) {
         return other instanceof AnyItemType;
     }
-}
\ No newline at end of file
+
+    @Override
+    public String toString() {
+        return String.valueOf(BuiltinTypeRegistry.INSTANCE.getTypeName(BuiltinTypeConstants.XS_ANY_TYPE_ID));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
b/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
index ec4472e..a5da4d7 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
@@ -218,7 +218,9 @@ public final class BuiltinTypeRegistry {
         types[BuiltinTypeConstants.XS_NOTATION_TYPE_ID] = XS_NOTATION;
 
         typeNames = new QName[BuiltinTypeConstants.BUILTIN_TYPE_COUNT];
+        typeNames[BuiltinTypeConstants.XS_ANY_TYPE_ID] = BuiltinTypeQNames.XS_ANY_TYPE_QNAME;
         typeNames[BuiltinTypeConstants.XS_ANY_SIMPLE_TYPE_ID] = BuiltinTypeQNames.XS_ANY_SIMPLE_TYPE_QNAME;
+        typeNames[BuiltinTypeConstants.XS_UNTYPED_TYPE_ID] = BuiltinTypeQNames.XS_UNTYPED_QNAME;
         typeNames[BuiltinTypeConstants.XS_ANY_ATOMIC_TYPE_ID] = BuiltinTypeQNames.XS_ANY_ATOMIC_TYPE_QNAME;
         typeNames[BuiltinTypeConstants.XS_STRING_TYPE_ID] = BuiltinTypeQNames.XS_STRING_TYPE_QNAME;
         typeNames[BuiltinTypeConstants.XS_NORMALIZED_STRING_TYPE_ID] = BuiltinTypeQNames.XS_NORMALIZED_STRING_TYPE_QNAME;

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/types/Quantifier.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/Quantifier.java b/vxquery-core/src/main/java/org/apache/vxquery/types/Quantifier.java
index bc2c11f..686986f 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/Quantifier.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/Quantifier.java
@@ -103,4 +103,15 @@ public enum Quantifier {
     public boolean allowsRepeating() {
         return this == QUANT_PLUS || this == QUANT_STAR;
     }
-}
\ No newline at end of file
+    
+    public static String toString(Quantifier q) {
+        switch (q) {
+            case QUANT_ONE: return " ";
+            case QUANT_PLUS: return "+";
+            case QUANT_QUESTION: return "?";
+            case QUANT_STAR: return "*";
+            case QUANT_ZERO: return "-";
+        }
+        throw new IllegalArgumentException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/04c11094/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
index 01b5314..2986a8c 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
@@ -148,6 +148,6 @@ public final class SequenceType implements Serializable {
     }
 
     public String toString() {
-        return String.valueOf(itemType) + " " + quantifier;
+        return String.valueOf(itemType) + Quantifier.toString(quantifier);
     }
-}
\ No newline at end of file
+}


Mime
View raw message