You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2017/03/17 02:49:33 UTC
asterixdb git commit: Better indentation of results.
Repository: asterixdb
Updated Branches:
refs/heads/master c3b4e4161 -> 58e0184e5
Better indentation of results.
Change-Id: Iab09135b0b08b43346244269e0bc252a24525f15
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1592
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <bu...@gmail.com>
BAD: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/58e0184e
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/58e0184e
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/58e0184e
Branch: refs/heads/master
Commit: 58e0184e52a51cac405e2484f7f5a75f1b4fcc45
Parents: c3b4e41
Author: Till Westmann <ti...@apache.org>
Authored: Thu Mar 16 16:29:48 2017 -0700
Committer: Michael Blow <mb...@apache.org>
Committed: Thu Mar 16 19:49:11 2017 -0700
----------------------------------------------------------------------
.../asterix/app/result/ResultPrinter.java | 43 ++++++++++++++------
1 file changed, 31 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/58e0184e/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
index 088d153..61d0eed 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
@@ -24,10 +24,6 @@ import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
import org.apache.asterix.common.utils.JSONUtil;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.translator.IStatementExecutor.Stats;
@@ -40,6 +36,12 @@ import org.apache.hyracks.api.comm.VSizeFrame;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.control.nc.resources.memory.FrameManager;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.PrettyPrinter;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+
public class ResultPrinter {
// TODO(tillw): Should this be static?
@@ -57,12 +59,35 @@ public class ResultPrinter {
// Whether this is the first instance being output
private boolean notFirst = false;
+ private ObjectMapper om;
+ private ObjectWriter ow;
+
public ResultPrinter(SessionConfig conf, Stats stats, ARecordType recordType) {
this.conf = conf;
this.stats = stats;
this.recordType = recordType;
this.indentJSON = conf.is(SessionConfig.FORMAT_INDENT_JSON);
this.quoteRecord = conf.is(SessionConfig.FORMAT_QUOTE_RECORD);
+ if (indentJSON) {
+ this.om = new ObjectMapper();
+ DefaultPrettyPrinter.Indenter i = new DefaultPrettyPrinter.Indenter() {
+
+ @Override
+ public void writeIndentation(JsonGenerator jsonGenerator, int i) throws IOException {
+ jsonGenerator.writeRaw('\n');
+ for (int j = 0; j < i + 1; ++j) {
+ jsonGenerator.writeRaw('\t');
+ }
+ }
+
+ @Override
+ public boolean isInline() {
+ return false;
+ }
+ };
+ PrettyPrinter pp = new DefaultPrettyPrinter().withObjectIndenter(i).withArrayIndenter(i);
+ this.ow = om.writer(pp);
+ }
}
private static void appendCSVHeader(Appendable app, ARecordType recordType) throws HyracksDataException {
@@ -134,13 +159,11 @@ public class ResultPrinter {
}
private void displayRecord(String result) throws HyracksDataException {
- ObjectMapper om = new ObjectMapper();
- om.enable(SerializationFeature.INDENT_OUTPUT);
String record = result;
if (indentJSON) {
// TODO(tillw): this is inefficient - do this during record generation
try {
- record = om.writerWithDefaultPrettyPrinter().writeValueAsString(om.readValue(result, Object.class));
+ record = ow.writeValueAsString(om.readValue(result, Object.class));
} catch (IOException e) {
throw new HyracksDataException(e);
}
@@ -190,11 +213,7 @@ public class ResultPrinter {
conf.out().print(", ");
}
notFirst = true;
- try {
- displayRecord(result);
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
+ displayRecord(result);
}
frameBuffer.clear();
}