asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject [1/6] incubator-asterixdb git commit: Adding 'cleanjson' output format, along with implementation of lists.
Date Thu, 08 Oct 2015 16:44:59 GMT
Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master 2574f43d8 -> f4a1c3c60


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/APrintVisitor.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/APrintVisitor.java
deleted file mode 100644
index b459138..0000000
--- a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/APrintVisitor.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.asterix.om.pointables.printer.json;
-
-import java.io.PrintStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABinaryHexPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ABooleanPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ACirclePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ADatePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ADateTimePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ADayTimeDurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ADoublePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ADurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AFloatPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AInt16Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AInt32Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AInt64Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AInt8Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ALinePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ANullPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.APoint3DPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.APointPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.APolygonPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ARectanglePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AStringPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.ATimePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.AYearMonthDurationPrinter;
-import org.apache.asterix.om.pointables.AFlatValuePointable;
-import org.apache.asterix.om.pointables.AListVisitablePointable;
-import org.apache.asterix.om.pointables.ARecordVisitablePointable;
-import org.apache.asterix.om.pointables.base.IVisitablePointable;
-import org.apache.asterix.om.pointables.visitor.IVisitablePointableVisitor;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-
-/**
- * This class is a IVisitablePointableVisitor implementation which recursively
- * visit a given record, list or flat value of a given type, and print it to a
- * PrintStream in JSON format.
- */
-public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<PrintStream, ATypeTag>> {
-
-    private final Map<IVisitablePointable, ARecordPrinter> raccessorToPrinter = new HashMap<IVisitablePointable, ARecordPrinter>();
-    private final Map<IVisitablePointable, AListPrinter> laccessorToPrinter = new HashMap<IVisitablePointable, AListPrinter>();
-
-    @Override
-    public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
-        AListPrinter printer = laccessorToPrinter.get(accessor);
-        if (printer == null) {
-            printer = new AListPrinter(accessor.ordered());
-            laccessorToPrinter.put(accessor, printer);
-        }
-        try {
-            printer.printList(accessor, arg.first, this);
-        } catch (Exception e) {
-            throw new AsterixException(e);
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(ARecordVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
-        ARecordPrinter printer = raccessorToPrinter.get(accessor);
-        if (printer == null) {
-            printer = new ARecordPrinter();
-            raccessorToPrinter.put(accessor, printer);
-        }
-        try {
-            printer.printRecord(accessor, arg.first, this);
-        } catch (Exception e) {
-            throw new AsterixException(e);
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(AFlatValuePointable accessor, Pair<PrintStream, ATypeTag> arg) {
-        try {
-            byte[] b = accessor.getByteArray();
-            int s = accessor.getStartOffset();
-            int l = accessor.getLength();
-            PrintStream ps = arg.first;
-            ATypeTag typeTag = arg.second;
-            switch (typeTag) {
-                case INT8: {
-                    AInt8Printer.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case INT16: {
-                    AInt16Printer.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case INT32: {
-                    AInt32Printer.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case INT64: {
-                    AInt64Printer.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case NULL: {
-                    ANullPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case BOOLEAN: {
-                    ABooleanPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case FLOAT: {
-                    AFloatPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case DOUBLE: {
-                    ADoublePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case DATE: {
-                    ADatePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case TIME: {
-                    ATimePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case DATETIME: {
-                    ADateTimePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case DURATION: {
-                    ADurationPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case POINT: {
-                    APointPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case POINT3D: {
-                    APoint3DPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case LINE: {
-                    ALinePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case POLYGON: {
-                    APolygonPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case CIRCLE: {
-                    ACirclePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case RECTANGLE: {
-                    ARectanglePrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case STRING: {
-                    AStringPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case BINARY: {
-                    ABinaryHexPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case YEARMONTHDURATION: {
-                    AYearMonthDurationPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case DAYTIMEDURATION: {
-                    ADayTimeDurationPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case UUID: {
-                    AUUIDPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case SHORTWITHOUTTYPEINFO: {
-                    ShortWithoutTypeInfoPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                default: {
-                    throw new NotImplementedException("No printer for type " + typeTag);
-                }
-            }
-            return null;
-        } catch (Exception e) {
-            throw new IllegalStateException(e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/ARecordPrinter.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/ARecordPrinter.java
deleted file mode 100644
index aa0570b..0000000
--- a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/ARecordPrinter.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.asterix.om.pointables.printer.json;
-
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.List;
-
-import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.om.pointables.ARecordVisitablePointable;
-import org.apache.asterix.om.pointables.base.IVisitablePointable;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-
-/**
- * This class is to print the content of a record. It is ONLY visible to
- * APrintVisitor.
- */
-class ARecordPrinter {
-    private static String LEFT_PAREN = "{ ";
-    private static String RIGHT_PAREN = " }";
-    private static String COMMA = ", ";
-    private static String COLON = ": ";
-
-    private final Pair<PrintStream, ATypeTag> nameVisitorArg = new Pair<PrintStream, ATypeTag>(null, ATypeTag.STRING);
-    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<PrintStream, ATypeTag>(null, null);
-
-    public ARecordPrinter() {
-
-    }
-
-    public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
-            AsterixException {
-        List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
-        List<IVisitablePointable> fieldTags = recordAccessor.getFieldTypeTags();
-        List<IVisitablePointable> fieldValues = recordAccessor.getFieldValues();
-
-        nameVisitorArg.first = ps;
-        itemVisitorArg.first = ps;
-
-        // print the beginning part
-        ps.print(LEFT_PAREN);
-
-        // print field 0 to n-2
-        for (int i = 0; i < fieldNames.size() - 1; i++) {
-            printField(ps, visitor, fieldNames, fieldTags, fieldValues, i);
-            // print the comma
-            ps.print(COMMA);
-        }
-
-        // print field n-1
-        if (fieldValues.size() > 0) {
-            printField(ps, visitor, fieldNames, fieldTags, fieldValues, fieldValues.size() - 1);
-        }
-
-        // print the end part
-        ps.print(RIGHT_PAREN);
-    }
-
-    private void printField(PrintStream ps, APrintVisitor visitor, List<IVisitablePointable> fieldNames,
-            List<IVisitablePointable> fieldTags, List<IVisitablePointable> fieldValues, int i) throws AsterixException {
-        IVisitablePointable itemTypeTag = fieldTags.get(i);
-        IVisitablePointable item = fieldValues.get(i);
-        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(itemTypeTag.getByteArray()[itemTypeTag
-                .getStartOffset()]);
-        itemVisitorArg.second = item.getLength() <= 1 ? ATypeTag.NULL : typeTag;
-
-        // print field name
-        fieldNames.get(i).accept(visitor, nameVisitorArg);
-        ps.print(COLON);
-        // print field value
-        item.accept(visitor, itemVisitorArg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java
new file mode 100644
index 0000000..892a8b6
--- /dev/null
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.om.pointables.printer.json.clean;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.om.pointables.AListVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+/**
+ * This class is to print the content of a list. It is ONLY visible to
+ * APrintVisitor.
+ */
+class AListPrinter {
+    private static String BEGIN = "[ ";
+    private static String END = " ]";
+    private static String COMMA = ", ";
+
+    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<PrintStream, ATypeTag>(null, null);
+
+    public AListPrinter(boolean ordered) {
+    }
+
+    public void printList(AListVisitablePointable listAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+            AsterixException {
+        List<IVisitablePointable> itemTags = listAccessor.getItemTags();
+        List<IVisitablePointable> items = listAccessor.getItems();
+        itemVisitorArg.first = ps;
+
+        // print the beginning part
+        ps.print(BEGIN);
+
+        // print item 0 to n-2
+        for (int i = 0; i < items.size() - 1; i++) {
+            printItem(visitor, itemTags, items, i);
+            // print the comma
+            ps.print(COMMA);
+        }
+
+        // print item n-1
+        if (items.size() > 0) {
+            printItem(visitor, itemTags, items, items.size() - 1);
+        }
+
+        // print the end part
+        ps.print(END);
+    }
+
+    private void printItem(APrintVisitor visitor, List<IVisitablePointable> itemTags, List<IVisitablePointable> items,
+            int i) throws AsterixException {
+        IVisitablePointable itemTypeTag = itemTags.get(i);
+        IVisitablePointable item = items.get(i);
+        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(itemTypeTag.getByteArray()[itemTypeTag
+                .getStartOffset()]);
+        itemVisitorArg.second = item.getLength() <= 1 ? ATypeTag.NULL : typeTag;
+        item.accept(visitor, itemVisitorArg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
new file mode 100644
index 0000000..716069e
--- /dev/null
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
@@ -0,0 +1,214 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.om.pointables.printer.json.clean;
+
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABinaryHexPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABooleanPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ACirclePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADatePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADateTimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADayTimeDurationPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADoublePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADurationPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AFloatPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt16Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt32Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt64Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt8Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ALinePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ANullPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APoint3DPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APointPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APolygonPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ARectanglePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AStringPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ATimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AYearMonthDurationPrinter;
+import org.apache.asterix.om.pointables.AFlatValuePointable;
+import org.apache.asterix.om.pointables.AListVisitablePointable;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.pointables.visitor.IVisitablePointableVisitor;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+/**
+ * This class is a IVisitablePointableVisitor implementation which recursively
+ * visit a given record, list or flat value of a given type, and print it to a
+ * PrintStream in Clean JSON format.
+ */
+public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<PrintStream, ATypeTag>> {
+
+    private final Map<IVisitablePointable, ARecordPrinter> raccessorToPrinter = new HashMap<IVisitablePointable, ARecordPrinter>();
+    private final Map<IVisitablePointable, AListPrinter> laccessorToPrinter = new HashMap<IVisitablePointable, AListPrinter>();
+
+    @Override
+    public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+        AListPrinter printer = laccessorToPrinter.get(accessor);
+        if (printer == null) {
+            printer = new AListPrinter(accessor.ordered());
+            laccessorToPrinter.put(accessor, printer);
+        }
+        try {
+            printer.printList(accessor, arg.first, this);
+        } catch (Exception e) {
+            throw new AsterixException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public Void visit(ARecordVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+        ARecordPrinter printer = raccessorToPrinter.get(accessor);
+        if (printer == null) {
+            printer = new ARecordPrinter();
+            raccessorToPrinter.put(accessor, printer);
+        }
+        try {
+            printer.printRecord(accessor, arg.first, this);
+        } catch (Exception e) {
+            throw new AsterixException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public Void visit(AFlatValuePointable accessor, Pair<PrintStream, ATypeTag> arg) {
+        try {
+            byte[] b = accessor.getByteArray();
+            int s = accessor.getStartOffset();
+            int l = accessor.getLength();
+            PrintStream ps = arg.first;
+            ATypeTag typeTag = arg.second;
+            switch (typeTag) {
+                case INT8: {
+                    AInt8Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case INT16: {
+                    AInt16Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case INT32: {
+                    AInt32Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case INT64: {
+                    AInt64Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case NULL: {
+                    ANullPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case BOOLEAN: {
+                    ABooleanPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case FLOAT: {
+                    AFloatPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DOUBLE: {
+                    ADoublePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DATE: {
+                    ADatePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case TIME: {
+                    ATimePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DATETIME: {
+                    ADateTimePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DURATION: {
+                    ADurationPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case POINT: {
+                    APointPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case POINT3D: {
+                    APoint3DPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case LINE: {
+                    ALinePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case POLYGON: {
+                    APolygonPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case CIRCLE: {
+                    ACirclePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case RECTANGLE: {
+                    ARectanglePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case STRING: {
+                    AStringPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case BINARY: {
+                    ABinaryHexPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case YEARMONTHDURATION: {
+                    AYearMonthDurationPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DAYTIMEDURATION: {
+                    ADayTimeDurationPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case UUID: {
+                    AUUIDPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case SHORTWITHOUTTYPEINFO: {
+                    ShortWithoutTypeInfoPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                default: {
+                    throw new NotImplementedException("No printer for type " + typeTag);
+                }
+            }
+            return null;
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java
new file mode 100644
index 0000000..24815b0
--- /dev/null
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.om.pointables.printer.json.clean;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+/**
+ * This class is to print the content of a record. It is ONLY visible to
+ * APrintVisitor.
+ */
+class ARecordPrinter {
+    private static String LEFT_PAREN = "{ ";
+    private static String RIGHT_PAREN = " }";
+    private static String COMMA = ", ";
+    private static String COLON = ": ";
+
+    private final Pair<PrintStream, ATypeTag> nameVisitorArg = new Pair<PrintStream, ATypeTag>(null, ATypeTag.STRING);
+    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<PrintStream, ATypeTag>(null, null);
+
+    public ARecordPrinter() {
+
+    }
+
+    public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+            AsterixException {
+        List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
+        List<IVisitablePointable> fieldTags = recordAccessor.getFieldTypeTags();
+        List<IVisitablePointable> fieldValues = recordAccessor.getFieldValues();
+
+        nameVisitorArg.first = ps;
+        itemVisitorArg.first = ps;
+
+        // print the beginning part
+        ps.print(LEFT_PAREN);
+
+        // print field 0 to n-2
+        for (int i = 0; i < fieldNames.size() - 1; i++) {
+            printField(ps, visitor, fieldNames, fieldTags, fieldValues, i);
+            // print the comma
+            ps.print(COMMA);
+        }
+
+        // print field n-1
+        if (fieldValues.size() > 0) {
+            printField(ps, visitor, fieldNames, fieldTags, fieldValues, fieldValues.size() - 1);
+        }
+
+        // print the end part
+        ps.print(RIGHT_PAREN);
+    }
+
+    private void printField(PrintStream ps, APrintVisitor visitor, List<IVisitablePointable> fieldNames,
+            List<IVisitablePointable> fieldTags, List<IVisitablePointable> fieldValues, int i) throws AsterixException {
+        IVisitablePointable itemTypeTag = fieldTags.get(i);
+        IVisitablePointable item = fieldValues.get(i);
+        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(itemTypeTag.getByteArray()[itemTypeTag
+                .getStartOffset()]);
+        itemVisitorArg.second = item.getLength() <= 1 ? ATypeTag.NULL : typeTag;
+
+        // print field name
+        fieldNames.get(i).accept(visitor, nameVisitorArg);
+        ps.print(COLON);
+        // print field value
+        item.accept(visitor, itemVisitorArg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java
new file mode 100644
index 0000000..435a674
--- /dev/null
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.om.pointables.printer.json.lossless;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.om.pointables.AListVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+/**
+ * This class is to print the content of a list. It is ONLY visible to
+ * APrintVisitor.
+ */
+class AListPrinter {
+    private static String BEGIN = "{ \"unorderedlist\": [ ";
+    private static String BEGIN_ORDERED = "{ \"orderedlist\": [ ";
+    private static String END = " ] }";
+    private static String COMMA = ", ";
+
+    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<PrintStream, ATypeTag>(null, null);
+    private String begin = BEGIN;
+
+    public AListPrinter(boolean ordered) {
+        if (ordered) {
+            begin = BEGIN_ORDERED;
+        }
+    }
+
+    public void printList(AListVisitablePointable listAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+            AsterixException {
+        List<IVisitablePointable> itemTags = listAccessor.getItemTags();
+        List<IVisitablePointable> items = listAccessor.getItems();
+        itemVisitorArg.first = ps;
+
+        // print the beginning part
+        ps.print(begin);
+
+        // print item 0 to n-2
+        for (int i = 0; i < items.size() - 1; i++) {
+            printItem(visitor, itemTags, items, i);
+            // print the comma
+            ps.print(COMMA);
+        }
+
+        // print item n-1
+        if (items.size() > 0) {
+            printItem(visitor, itemTags, items, items.size() - 1);
+        }
+
+        // print the end part
+        ps.print(END);
+    }
+
+    private void printItem(APrintVisitor visitor, List<IVisitablePointable> itemTags, List<IVisitablePointable> items,
+            int i) throws AsterixException {
+        IVisitablePointable itemTypeTag = itemTags.get(i);
+        IVisitablePointable item = items.get(i);
+        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(itemTypeTag.getByteArray()[itemTypeTag
+                .getStartOffset()]);
+        itemVisitorArg.second = item.getLength() <= 1 ? ATypeTag.NULL : typeTag;
+        item.accept(visitor, itemVisitorArg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
new file mode 100644
index 0000000..4bb5633
--- /dev/null
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
@@ -0,0 +1,214 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.om.pointables.printer.json.lossless;
+
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABinaryHexPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ABooleanPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ACirclePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADatePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADateTimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADayTimeDurationPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADoublePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADurationPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AFloatPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt16Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt32Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt64Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt8Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ALinePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ANullPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APoint3DPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APointPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APolygonPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ARectanglePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AStringPrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ATimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AYearMonthDurationPrinter;
+import org.apache.asterix.om.pointables.AFlatValuePointable;
+import org.apache.asterix.om.pointables.AListVisitablePointable;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.pointables.visitor.IVisitablePointableVisitor;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+/**
+ * This class is a IVisitablePointableVisitor implementation which recursively
+ * visit a given record, list or flat value of a given type, and print it to a
+ * PrintStream in JSON format.
+ */
+public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<PrintStream, ATypeTag>> {
+
+    private final Map<IVisitablePointable, ARecordPrinter> raccessorToPrinter = new HashMap<IVisitablePointable, ARecordPrinter>();
+    private final Map<IVisitablePointable, AListPrinter> laccessorToPrinter = new HashMap<IVisitablePointable, AListPrinter>();
+
+    @Override
+    public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+        AListPrinter printer = laccessorToPrinter.get(accessor);
+        if (printer == null) {
+            printer = new AListPrinter(accessor.ordered());
+            laccessorToPrinter.put(accessor, printer);
+        }
+        try {
+            printer.printList(accessor, arg.first, this);
+        } catch (Exception e) {
+            throw new AsterixException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public Void visit(ARecordVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+        ARecordPrinter printer = raccessorToPrinter.get(accessor);
+        if (printer == null) {
+            printer = new ARecordPrinter();
+            raccessorToPrinter.put(accessor, printer);
+        }
+        try {
+            printer.printRecord(accessor, arg.first, this);
+        } catch (Exception e) {
+            throw new AsterixException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public Void visit(AFlatValuePointable accessor, Pair<PrintStream, ATypeTag> arg) {
+        try {
+            byte[] b = accessor.getByteArray();
+            int s = accessor.getStartOffset();
+            int l = accessor.getLength();
+            PrintStream ps = arg.first;
+            ATypeTag typeTag = arg.second;
+            switch (typeTag) {
+                case INT8: {
+                    AInt8Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case INT16: {
+                    AInt16Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case INT32: {
+                    AInt32Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case INT64: {
+                    AInt64Printer.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case NULL: {
+                    ANullPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case BOOLEAN: {
+                    ABooleanPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case FLOAT: {
+                    AFloatPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DOUBLE: {
+                    ADoublePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DATE: {
+                    ADatePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case TIME: {
+                    ATimePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DATETIME: {
+                    ADateTimePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DURATION: {
+                    ADurationPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case POINT: {
+                    APointPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case POINT3D: {
+                    APoint3DPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case LINE: {
+                    ALinePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case POLYGON: {
+                    APolygonPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case CIRCLE: {
+                    ACirclePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case RECTANGLE: {
+                    ARectanglePrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case STRING: {
+                    AStringPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case BINARY: {
+                    ABinaryHexPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case YEARMONTHDURATION: {
+                    AYearMonthDurationPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case DAYTIMEDURATION: {
+                    ADayTimeDurationPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case UUID: {
+                    AUUIDPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                case SHORTWITHOUTTYPEINFO: {
+                    ShortWithoutTypeInfoPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
+                default: {
+                    throw new NotImplementedException("No printer for type " + typeTag);
+                }
+            }
+            return null;
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/ARecordPrinter.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/ARecordPrinter.java
new file mode 100644
index 0000000..e111f76
--- /dev/null
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/ARecordPrinter.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.om.pointables.printer.json.lossless;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+/**
+ * This class is to print the content of a record. It is ONLY visible to
+ * APrintVisitor.
+ */
+class ARecordPrinter {
+    private static String LEFT_PAREN = "{ ";
+    private static String RIGHT_PAREN = " }";
+    private static String COMMA = ", ";
+    private static String COLON = ": ";
+
+    private final Pair<PrintStream, ATypeTag> nameVisitorArg = new Pair<PrintStream, ATypeTag>(null, ATypeTag.STRING);
+    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<PrintStream, ATypeTag>(null, null);
+
+    public ARecordPrinter() {
+
+    }
+
+    public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+            AsterixException {
+        List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
+        List<IVisitablePointable> fieldTags = recordAccessor.getFieldTypeTags();
+        List<IVisitablePointable> fieldValues = recordAccessor.getFieldValues();
+
+        nameVisitorArg.first = ps;
+        itemVisitorArg.first = ps;
+
+        // print the beginning part
+        ps.print(LEFT_PAREN);
+
+        // print field 0 to n-2
+        for (int i = 0; i < fieldNames.size() - 1; i++) {
+            printField(ps, visitor, fieldNames, fieldTags, fieldValues, i);
+            // print the comma
+            ps.print(COMMA);
+        }
+
+        // print field n-1
+        if (fieldValues.size() > 0) {
+            printField(ps, visitor, fieldNames, fieldTags, fieldValues, fieldValues.size() - 1);
+        }
+
+        // print the end part
+        ps.print(RIGHT_PAREN);
+    }
+
+    private void printField(PrintStream ps, APrintVisitor visitor, List<IVisitablePointable> fieldNames,
+            List<IVisitablePointable> fieldTags, List<IVisitablePointable> fieldValues, int i) throws AsterixException {
+        IVisitablePointable itemTypeTag = fieldTags.get(i);
+        IVisitablePointable item = fieldValues.get(i);
+        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(itemTypeTag.getByteArray()[itemTypeTag
+                .getStartOffset()]);
+        itemVisitorArg.second = item.getLength() <= 1 ? ATypeTag.NULL : typeTag;
+
+        // print field name
+        fieldNames.get(i).accept(visitor, nameVisitorArg);
+        ps.print(COLON);
+        // print field value
+        item.accept(visitor, itemVisitorArg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
index 1ccdf94..72c7eb1 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -29,7 +29,8 @@ import org.apache.asterix.formats.nontagged.AqlBinaryHashFunctionFactoryProvider
 import org.apache.asterix.formats.nontagged.AqlBinaryHashFunctionFamilyProvider;
 import org.apache.asterix.formats.nontagged.AqlBinaryIntegerInspector;
 import org.apache.asterix.formats.nontagged.AqlCSVPrinterFactoryProvider;
-import org.apache.asterix.formats.nontagged.AqlJSONPrinterFactoryProvider;
+import org.apache.asterix.formats.nontagged.AqlCleanJSONPrinterFactoryProvider;
+import org.apache.asterix.formats.nontagged.AqlLosslessJSONPrinterFactoryProvider;
 import org.apache.asterix.formats.nontagged.AqlNormalizedKeyComputerFactoryProvider;
 import org.apache.asterix.formats.nontagged.AqlPredicateEvaluatorFactoryProvider;
 import org.apache.asterix.formats.nontagged.AqlADMPrinterFactoryProvider;
@@ -1058,8 +1059,13 @@ public class NonTaggedDataFormat implements IDataFormat {
     }
 
     @Override
-    public IPrinterFactoryProvider getJSONPrinterFactoryProvider() {
-        return AqlJSONPrinterFactoryProvider.INSTANCE;
+    public IPrinterFactoryProvider getLosslessJSONPrinterFactoryProvider() {
+        return AqlLosslessJSONPrinterFactoryProvider.INSTANCE;
+    }
+
+    @Override
+    public IPrinterFactoryProvider getCleanJSONPrinterFactoryProvider() {
+        return AqlCleanJSONPrinterFactoryProvider.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
----------------------------------------------------------------------
diff --git a/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java b/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
index 53ba3c9..b78ad10 100644
--- a/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
+++ b/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
@@ -39,7 +39,8 @@ public class TestCaseContext {
     public enum OutputFormat {
         NONE  ("", ""),
         ADM   ("adm", "application/x-adm"),
-        JSON  ("json", "application/json"),
+        LOSSLESS_JSON("json", "application/json; lossless=true"),
+        CLEAN_JSON ("json", "application/json"),
         CSV   ("csv", "text/csv"),
         CSV_HEADER ("csv-header", "text/csv; header=present");
 
@@ -63,8 +64,10 @@ public class TestCaseContext {
             switch (cUnit.getOutputDir().getCompare()) {
             case TEXT:
                 return OutputFormat.ADM;
-            case JSON:
-                return OutputFormat.JSON;
+            case LOSSLESS_JSON:
+                return OutputFormat.LOSSLESS_JSON;
+            case CLEAN_JSON:
+                return OutputFormat.CLEAN_JSON;
             case CSV:
                 return OutputFormat.CSV;
             case CSV_HEADER:

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/f4a1c3c6/asterix-test-framework/src/main/resources/Catalog.xsd
----------------------------------------------------------------------
diff --git a/asterix-test-framework/src/main/resources/Catalog.xsd b/asterix-test-framework/src/main/resources/Catalog.xsd
index 771c216..c54ff61 100644
--- a/asterix-test-framework/src/main/resources/Catalog.xsd
+++ b/asterix-test-framework/src/main/resources/Catalog.xsd
@@ -186,7 +186,8 @@
          <xs:enumeration value="Text"/>
          <xs:enumeration value="Inspect"/>
          <xs:enumeration value="Ignore"/>
-         <xs:enumeration value="JSON"/>
+         <xs:enumeration value="Clean-JSON"/>
+         <xs:enumeration value="Lossless-JSON"/>
          <xs:enumeration value="CSV"/>
          <xs:enumeration value="CSV_Header"/>
       </xs:restriction>
@@ -217,5 +218,5 @@
          <xs:pattern value="\*|([A-Z]{4}[0-9]{4})"/>
       </xs:restriction>
    </xs:simpleType>
-   
+
 </xs:schema>


Mime
View raw message