asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject [2/8] incubator-asterixdb git commit: ASTERIXDB-1220: print nested values using visitors
Date Thu, 26 May 2016 19:19:12 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AYearMonthDurationPrinterFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AYearMonthDurationPrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AYearMonthDurationPrinterFactory.java
index ca2201b..bafab7c 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AYearMonthDurationPrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AYearMonthDurationPrinterFactory.java
@@ -18,6 +18,9 @@
  */
 package org.apache.asterix.dataflow.data.nontagged.printers.json.lossless;
 
+import java.io.PrintStream;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -26,12 +29,14 @@ public class AYearMonthDurationPrinterFactory implements IPrinterFactory {
     private static final long serialVersionUID = 1L;
     public static final AYearMonthDurationPrinterFactory INSTANCE = new AYearMonthDurationPrinterFactory();
 
-    /* (non-Javadoc)
-     * @see org.apache.hyracks.algebricks.data.IPrinterFactory#createPrinter()
-     */
+    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) -> {
+        ps.print("{ \"year-month-duration\": ");
+        ps.print(AInt32SerializerDeserializer.getInt(b, s + 1));
+        ps.print("}");
+    };
+
     @Override
     public IPrinter createPrinter() {
-        return AYearMonthDurationPrinter.INSTANCE;
+        return PRINTER;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlADMPrinterFactoryProvider.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlADMPrinterFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlADMPrinterFactoryProvider.java
index d9db6de..5f1854d 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlADMPrinterFactoryProvider.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlADMPrinterFactoryProvider.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.formats.nontagged;
 
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABinaryPrinterFactory;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABinaryHexPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABooleanPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.ACirclePrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADatePrinterFactory;
@@ -116,7 +116,7 @@ public class AqlADMPrinterFactoryProvider implements IPrinterFactoryProvider {
                 case STRING:
                     return AStringPrinterFactory.INSTANCE;
                 case BINARY:
-                    return ABinaryPrinterFactory.INSTANCE;
+                    return ABinaryHexPrinterFactory.INSTANCE;
                 case RECORD:
                     return new ARecordPrinterFactory((ARecordType) aqlType);
                 case ORDEREDLIST:

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlCleanJSONPrinterFactoryProvider.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlCleanJSONPrinterFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlCleanJSONPrinterFactoryProvider.java
index 6220dde..9cf9f8e 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlCleanJSONPrinterFactoryProvider.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlCleanJSONPrinterFactoryProvider.java
@@ -20,7 +20,7 @@ package org.apache.asterix.formats.nontagged;
 
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinterFactory;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABinaryPrinterFactory;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABinaryHexPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABooleanPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ACirclePrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADatePrinterFactory;
@@ -116,7 +116,7 @@ public class AqlCleanJSONPrinterFactoryProvider implements IPrinterFactoryProvid
                 case STRING:
                     return AStringPrinterFactory.INSTANCE;
                 case BINARY:
-                    return ABinaryPrinterFactory.INSTANCE;
+                    return ABinaryHexPrinterFactory.INSTANCE;
                 case RECORD:
                     return new ARecordPrinterFactory((ARecordType) aqlType);
                 case ORDEREDLIST:

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlLosslessJSONPrinterFactoryProvider.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlLosslessJSONPrinterFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlLosslessJSONPrinterFactoryProvider.java
index 1950685..370a47b 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlLosslessJSONPrinterFactoryProvider.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlLosslessJSONPrinterFactoryProvider.java
@@ -20,7 +20,7 @@ package org.apache.asterix.formats.nontagged;
 
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinterFactory;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ABinaryPrinterFactory;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ABinaryHexPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ABooleanPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ACirclePrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADatePrinterFactory;
@@ -116,7 +116,7 @@ public class AqlLosslessJSONPrinterFactoryProvider implements IPrinterFactoryPro
                 case STRING:
                     return AStringPrinterFactory.INSTANCE;
                 case BINARY:
-                    return ABinaryPrinterFactory.INSTANCE;
+                    return ABinaryHexPrinterFactory.INSTANCE;
                 case RECORD:
                     return new ARecordPrinterFactory((ARecordType) aqlType);
                 case ORDEREDLIST:

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
index 6907334..7e64cb5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
@@ -18,29 +18,32 @@
  */
 package org.apache.asterix.om.base;
 
-import org.json.JSONException;
-import org.json.JSONObject;
-
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.visitors.IOMVisitor;
+import org.json.JSONException;
+import org.json.JSONObject;
 
 public final class ABoolean implements IAObject {
 
-    public static ABoolean TRUE = new ABoolean(true);
-    public static ABoolean FALSE = new ABoolean(false);
+    public static final ABoolean TRUE = new ABoolean(true);
+    public static final ABoolean FALSE = new ABoolean(false);
 
     private final Boolean bVal;
 
     private ABoolean(boolean b) {
-        bVal = new Boolean(b);
+        bVal = Boolean.valueOf(b);
     }
 
     public Boolean getBoolean() {
         return bVal;
     }
 
+    public ABoolean valueOf(boolean b) {
+        return b ? TRUE : FALSE;
+    }
+
     @Override
     public IAType getType() {
         return BuiltinType.ABOOLEAN;
@@ -51,12 +54,9 @@ public final class ABoolean implements IAObject {
         return "ABoolean: {" + bVal + "}";
     }
 
+    @Override
     public boolean equals(Object obj) {
-        if (!(obj instanceof ABoolean)) {
-            return false;
-        } else {
-            return bVal.equals(((ABoolean) obj).getBoolean());
-        }
+        return obj == this;
     }
 
     @Override
@@ -81,10 +81,6 @@ public final class ABoolean implements IAObject {
 
     @Override
     public JSONObject toJSON() throws JSONException {
-        JSONObject json = new JSONObject();
-
-        json.put("ABoolean", bVal);
-
-        return json;
+        return new JSONObject().put("ABoolean", bVal);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AListPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AListPrinter.java
new file mode 100644
index 0000000..704d06e
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/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;
+
+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.
+ */
+public class AListPrinter {
+    private final String startList;
+    private final String endList;
+    private final String separator;
+
+    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<>(null, null);
+
+    public AListPrinter(String startList, String endList, String separator) {
+        this.startList = startList;
+        this.endList = endList;
+        this.separator = separator;
+    }
+
+    public void printList(AListVisitablePointable listAccessor, PrintStream ps, IPrintVisitor visitor)
+            throws IOException, AsterixException {
+        List<IVisitablePointable> itemTags = listAccessor.getItemTags();
+        List<IVisitablePointable> items = listAccessor.getItems();
+        itemVisitorArg.first = ps;
+
+        ps.print(startList);
+
+        // print item 0 to n-2
+        final int size = items.size();
+        for (int i = 0; i < size - 1; i++) {
+            printItem(visitor, itemTags, items, i);
+            ps.print(separator);
+        }
+
+        // print item n-1
+        if (size > 0) {
+            printItem(visitor, itemTags, items, size - 1);
+        }
+
+        ps.print(endList);
+    }
+
+    private void printItem(IPrintVisitor 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/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/ARecordPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/ARecordPrinter.java
new file mode 100644
index 0000000..cfcd8b7
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/ARecordPrinter.java
@@ -0,0 +1,95 @@
+/*
+ * 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;
+
+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.
+ */
+public class ARecordPrinter {
+    private final String startRecord;
+    private final String endRecord;
+    private final String fieldSeparator;
+    private final String fieldNameSeparator;
+
+    private final Pair<PrintStream, ATypeTag> nameVisitorArg = new Pair<>(null, ATypeTag.STRING);
+    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<>(null, null);
+
+    public ARecordPrinter(final String startRecord, final String endRecord, final String fieldSeparator,
+            final String fieldNameSeparator) {
+        this.startRecord = startRecord;
+        this.endRecord = endRecord;
+        this.fieldSeparator = fieldSeparator;
+        this.fieldNameSeparator = fieldNameSeparator;
+    }
+
+    public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, IPrintVisitor 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;
+
+        ps.print(startRecord);
+
+        // print field 0 to n-2
+        final int size = fieldNames.size();
+        for (int i = 0; i < size - 1; i++) {
+            printField(ps, visitor, fieldNames, fieldTags, fieldValues, i);
+            ps.print(fieldSeparator);
+        }
+
+        // print field n-1
+        if (size > 0) {
+            printField(ps, visitor, fieldNames, fieldTags, fieldValues, size - 1);
+        }
+
+        ps.print(endRecord);
+    }
+
+    private void printField(PrintStream ps, IPrintVisitor 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;
+
+        if (fieldNameSeparator != null) {
+            // print field name
+            fieldNames.get(i).accept(visitor, nameVisitorArg);
+            ps.print(fieldNameSeparator);
+        }
+        // print field value
+        item.accept(visitor, itemVisitorArg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AbstractPrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AbstractPrintVisitor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AbstractPrintVisitor.java
new file mode 100644
index 0000000..82fe048
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/AbstractPrintVisitor.java
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+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.types.ATypeTag;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public abstract class AbstractPrintVisitor implements IPrintVisitor {
+    private final Map<IVisitablePointable, ARecordPrinter> raccessorToPrinter = new HashMap<>();
+    private final Map<IVisitablePointable, AListPrinter> laccessorToPrinter = new HashMap<>();
+
+    @Override
+    public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+        AListPrinter printer = laccessorToPrinter.get(accessor);
+        if (printer == null) {
+            printer = createListPrinter(accessor);
+            laccessorToPrinter.put(accessor, printer);
+        }
+        try {
+            printer.printList(accessor, arg.first, this);
+        } catch (IOException 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 = createRecordPrinter(accessor);
+            raccessorToPrinter.put(accessor, printer);
+        }
+        try {
+            printer.printRecord(accessor, arg.first, this);
+        } catch (IOException e) {
+            throw new AsterixException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public Void visit(AFlatValuePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+        try {
+            byte[] b = accessor.getByteArray();
+            int s = accessor.getStartOffset();
+            int l = accessor.getLength();
+            PrintStream ps = arg.first;
+            ATypeTag typeTag = arg.second;
+            if (!printFlatValue(typeTag, b, s, l, ps)) {
+                throw new AsterixException("No printer for type " + typeTag);
+            }
+            return null;
+        } catch (HyracksDataException e) {
+            throw new AsterixException(e);
+        }
+    }
+
+    protected abstract AListPrinter createListPrinter(AListVisitablePointable accessor) throws AsterixException;
+
+    protected abstract ARecordPrinter createRecordPrinter(ARecordVisitablePointable accessor) throws AsterixException;
+
+    protected abstract boolean printFlatValue(ATypeTag typeTag, byte[] b, int s, int l, PrintStream ps)
+            throws HyracksDataException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/IPrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/IPrintVisitor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/IPrintVisitor.java
new file mode 100644
index 0000000..353d89f
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/IPrintVisitor.java
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import org.apache.asterix.om.pointables.visitor.IVisitablePointableVisitor;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+
+import java.io.PrintStream;
+
+public interface IPrintVisitor extends IVisitablePointableVisitor<Void, Pair<PrintStream, ATypeTag>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/AListPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/AListPrinter.java
deleted file mode 100644
index afa3fb7..0000000
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/AListPrinter.java
+++ /dev/null
@@ -1,89 +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.adm;
-
-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 LEFT_PAREN = "{{ ";
-    private static String RIGHT_PAREN = " }}";
-    private static String LEFT_PAREN_ORDERED = "[ ";
-    private static String RIGHT_PAREN_ORDERED = " ]";
-    private static String COMMA = ", ";
-
-    private final Pair<PrintStream, ATypeTag> itemVisitorArg = new Pair<PrintStream, ATypeTag>(null, null);
-    private String leftParen = LEFT_PAREN;
-    private String rightParen = RIGHT_PAREN;
-
-    public AListPrinter(boolean ordered) {
-        if (ordered) {
-            leftParen = LEFT_PAREN_ORDERED;
-            rightParen = RIGHT_PAREN_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(leftParen);
-
-        // 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(rightParen);
-    }
-
-    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/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/APrintVisitor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/APrintVisitor.java
index cd91c09..532f8c5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/APrintVisitor.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/APrintVisitor.java
@@ -19,203 +19,36 @@
 
 package org.apache.asterix.om.pointables.printer.adm;
 
-import java.io.IOException;
 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.ABooleanPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ACirclePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADatePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADateTimePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADayTimeDurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADoublePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AFloatPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AInt16Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AInt32Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AInt64Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AInt8Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AIntervalPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ALinePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ANullPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.APoint3DPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.APointPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.APolygonPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ARectanglePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AStringPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ATimePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.AYearMonthDurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinter;
-import org.apache.asterix.om.pointables.AFlatValuePointable;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.AObjectPrinterFactory;
 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.pointables.printer.AListPrinter;
+import org.apache.asterix.om.pointables.printer.ARecordPrinter;
+import org.apache.asterix.om.pointables.printer.AbstractPrintVisitor;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
-import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 /**
  * 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 adm 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>();
-
+public class APrintVisitor extends AbstractPrintVisitor {
     @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 (IOException e) {
-            throw new AsterixException(e);
-        }
-        return null;
+    protected AListPrinter createListPrinter(AListVisitablePointable accessor) {
+        return accessor.ordered() ? new AListPrinter("[ ", " ]", ", ") : new AListPrinter("{{ ", " }}", ", ");
     }
 
     @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 (IOException e) {
-            throw new AsterixException(e);
-        }
-        return null;
+    protected ARecordPrinter createRecordPrinter(ARecordVisitablePointable accessor) {
+        return new ARecordPrinter("{ ", " }", ", ", ": ");
     }
 
     @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 MISSING:
-                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 YEARMONTHDURATION: {
-                    AYearMonthDurationPrinter.INSTANCE.print(b, s, l, ps);
-                    break;
-                }
-                case DAYTIMEDURATION: {
-                    ADayTimeDurationPrinter.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 INTERVAL: {
-                    AIntervalPrinter.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 (IOException e) {
-            throw new IllegalStateException(e);
-        }
+    protected boolean printFlatValue(ATypeTag typeTag, byte[] b, int s, int l, PrintStream ps)
+            throws HyracksDataException {
+        return AObjectPrinterFactory.printFlatValue(typeTag, b, s, l, ps);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/ARecordPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/ARecordPrinter.java
deleted file mode 100644
index ef14e3e..0000000
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/adm/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.adm;
-
-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_BRACE = "{ ";
-    private static String RIGHT_BRACE = " }";
-    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_BRACE);
-
-        // 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_BRACE);
-    }
-
-    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/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/APrintVisitor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/APrintVisitor.java
index 306ed99..926d9f0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/APrintVisitor.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/APrintVisitor.java
@@ -19,195 +19,37 @@
 
 package org.apache.asterix.om.pointables.printer.csv;
 
-import java.io.IOException;
 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.ShortWithoutTypeInfoPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ABinaryHexPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ABooleanPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ACirclePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADatePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADateTimePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADayTimeDurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADoublePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADurationPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AFloatPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt16Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt32Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt64Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt8Printer;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ALinePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ANullPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.APoint3DPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.APointPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.APolygonPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ARectanglePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AStringPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.ATimePrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AUUIDPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.csv.AYearMonthDurationPrinter;
-import org.apache.asterix.om.pointables.AFlatValuePointable;
+import org.apache.asterix.dataflow.data.nontagged.printers.csv.AObjectPrinterFactory;
 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.pointables.printer.AListPrinter;
+import org.apache.asterix.om.pointables.printer.ARecordPrinter;
+import org.apache.asterix.om.pointables.printer.AbstractPrintVisitor;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
-import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 /**
  * 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 CSV format.
  */
-public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<PrintStream, ATypeTag>> {
-
-    private final Map<IVisitablePointable, ARecordPrinter> raccessorToPrinter = new HashMap<IVisitablePointable, ARecordPrinter>();
-
-    private int level = 0;
-
+public class APrintVisitor extends AbstractPrintVisitor {
     @Override
-    public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+    protected AListPrinter createListPrinter(AListVisitablePointable accessor) throws AsterixException {
         throw new AsterixException("'List' type unsupported for CSV output");
     }
 
     @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);
-        }
-        if (level > 0) {
-            throw new AsterixException("Nested 'Record' instances unsupported for CSV output");
-        }
-
-        try {
-            level++;
-            printer.printRecord(accessor, arg.first, this);
-            level--;
-        } catch (IOException e) {
-            throw new AsterixException(e);
-        }
-        return null;
+    protected ARecordPrinter createRecordPrinter(ARecordVisitablePointable accessor) {
+        return new ARecordPrinter("", "", ",", 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 MISSING:
-                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 (IOException e) {
-            throw new IllegalStateException(e);
-        }
+    protected boolean printFlatValue(ATypeTag typeTag, byte[] b, int s, int l, PrintStream ps)
+            throws HyracksDataException {
+        return AObjectPrinterFactory.printFlatValue(typeTag, b, s, l, ps);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/ARecordPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/ARecordPrinter.java
deleted file mode 100644
index 5388837..0000000
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/csv/ARecordPrinter.java
+++ /dev/null
@@ -1,81 +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.csv;
-
-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 {
-    // QQQ Might we want to make this a configurable delimiter?
-    private static String COMMA = ",";
-
-    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 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);
-        }
-    }
-
-    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 value
-        item.accept(visitor, itemVisitorArg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java
deleted file mode 100644
index 826c465..0000000
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/AListPrinter.java
+++ /dev/null
@@ -1,81 +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.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/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
index 81677f1..76768aa 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
@@ -19,203 +19,36 @@
 
 package org.apache.asterix.om.pointables.printer.json.clean;
 
-import java.io.IOException;
 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.ShortWithoutTypeInfoPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABinaryHexPrinter;
-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.AIntervalPrinter;
-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.AUUIDPrinter;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AYearMonthDurationPrinter;
-import org.apache.asterix.om.pointables.AFlatValuePointable;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AObjectPrinterFactory;
 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.pointables.printer.AListPrinter;
+import org.apache.asterix.om.pointables.printer.ARecordPrinter;
+import org.apache.asterix.om.pointables.printer.AbstractPrintVisitor;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
-import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 /**
  * 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>();
-
+public class APrintVisitor extends AbstractPrintVisitor {
     @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 (IOException e) {
-            throw new AsterixException(e);
-        }
-        return null;
+    protected AListPrinter createListPrinter(AListVisitablePointable accessor) {
+        return new AListPrinter("[ ", " ]", ", ");
     }
 
     @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 (IOException e) {
-            throw new AsterixException(e);
-        }
-        return null;
+    protected ARecordPrinter createRecordPrinter(ARecordVisitablePointable accessor) {
+        return new ARecordPrinter("{ ", " }", ", ", ": ");
     }
 
     @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 MISSING:
-                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 INTERVAL: {
-                    AIntervalPrinter.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 (IOException e) {
-            throw new IllegalStateException(e);
-        }
+    protected boolean printFlatValue(ATypeTag typeTag, byte[] b, int s, int l, PrintStream ps)
+            throws HyracksDataException {
+        return AObjectPrinterFactory.printFlatValue(typeTag, b, s, l, ps);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/ARecordPrinter.java
deleted file mode 100644
index 6644f3a..0000000
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/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.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/fd7fb5a1/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java
deleted file mode 100644
index 3b6310a..0000000
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/AListPrinter.java
+++ /dev/null
@@ -1,86 +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.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);
-    }
-}


Mime
View raw message