Return-Path: X-Original-To: apmail-asterixdb-commits-archive@minotaur.apache.org Delivered-To: apmail-asterixdb-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7E7A719AF7 for ; Sat, 16 Apr 2016 06:30:54 +0000 (UTC) Received: (qmail 23293 invoked by uid 500); 16 Apr 2016 06:30:53 -0000 Delivered-To: apmail-asterixdb-commits-archive@asterixdb.apache.org Received: (qmail 23255 invoked by uid 500); 16 Apr 2016 06:30:53 -0000 Mailing-List: contact commits-help@asterixdb.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@asterixdb.incubator.apache.org Delivered-To: mailing list commits@asterixdb.incubator.apache.org Received: (qmail 23246 invoked by uid 99); 16 Apr 2016 06:30:53 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Apr 2016 06:30:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 1CEEFC1732 for ; Sat, 16 Apr 2016 06:30:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.216 X-Spam-Level: X-Spam-Status: No, score=-4.216 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.996] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id p0poT0l_ZD4b for ; Sat, 16 Apr 2016 06:30:52 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id DC7965F23C for ; Sat, 16 Apr 2016 06:30:50 +0000 (UTC) Received: (qmail 23242 invoked by uid 99); 16 Apr 2016 06:30:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Apr 2016 06:30:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CFE01DFB95; Sat, 16 Apr 2016 06:30:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tillw@apache.org To: commits@asterixdb.incubator.apache.org Message-Id: <2162a74dd8994863bd8e9a2b7a4982db@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-asterixdb git commit: Avoid 1 copy of the data when returning results Date: Sat, 16 Apr 2016 06:30:49 +0000 (UTC) Repository: incubator-asterixdb Updated Branches: refs/heads/master f3bcb73ce -> 02dbadddc Avoid 1 copy of the data when returning results Change-Id: I8728b218e8f8e20d3e58be46c704f75ef2288933 Reviewed-on: https://asterix-gerrit.ics.uci.edu/808 Tested-by: Jenkins Reviewed-by: Murtadha Hubail Project: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/commit/02dbaddd Tree: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/tree/02dbaddd Diff: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/diff/02dbaddd Branch: refs/heads/master Commit: 02dbadddc0122c5ba5461321df84dca30732984c Parents: f3bcb73 Author: Till Westmann Authored: Fri Apr 15 22:49:59 2016 -0700 Committer: Till Westmann Committed: Fri Apr 15 23:25:10 2016 -0700 ---------------------------------------------------------------------- .../org/apache/asterix/result/ResultUtils.java | 90 ++++++++------------ 1 file changed, 37 insertions(+), 53 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/02dbaddd/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java index d7ddce5..b140bef 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; @@ -43,7 +44,6 @@ import org.apache.hyracks.api.comm.IFrameTupleAccessor; import org.apache.hyracks.api.comm.VSizeFrame; import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.control.nc.resources.memory.FrameManager; -import org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -74,11 +74,9 @@ public class ResultUtils { return s; } - public static void displayCSVHeader(ARecordType recordType, SessionConfig conf) - throws AsterixException { + public static void displayCSVHeader(ARecordType recordType, SessionConfig conf) throws AsterixException { if (recordType == null) { - throw new AsterixException( - "Cannot output CSV with header without specifying output-record-type"); + throw new AsterixException("Cannot output CSV with header without specifying output-record-type"); } // If HTML-ifying, we have to output this here before the header - // pretty ugly @@ -105,12 +103,6 @@ public class ResultUtils { public static void displayResults(ResultReader resultReader, SessionConfig conf, Stats stats) throws HyracksDataException { - IFrameTupleAccessor fta = resultReader.getFrameTupleAccessor(); - - IFrame frame = new VSizeFrame(resultDisplayFrameMgr); - int bytesRead = resultReader.read(frame); - ByteBufferInputStream bbis = new ByteBufferInputStream(); - // Whether we are wrapping the output sequence in an array boolean wrap_array = false; // Whether this is the first instance being output @@ -143,49 +135,41 @@ public class ResultUtils { } final boolean indentJSON = conf.is(SessionConfig.INDENT_JSON); - if (bytesRead > 0) { - do { - try { - fta.reset(frame.getBuffer()); - int last = fta.getTupleCount(); - String result; - for (int tIndex = 0; tIndex < last; tIndex++) { - int start = fta.getTupleStartOffset(tIndex); - int length = fta.getTupleEndOffset(tIndex) - start; - bbis.setByteBuffer(frame.getBuffer(), start); - byte[] recordBytes = new byte[length]; - int numread = bbis.read(recordBytes, 0, length); - if (conf.fmt() == OutputFormat.CSV) { - if ((numread > 0) && (recordBytes[numread - 1] == '\n')) { - numread--; - } - } - result = new String(recordBytes, 0, numread, UTF_8); - if (wrap_array && notfirst) { - conf.out().print(", "); - } - notfirst = true; - if (indentJSON) { - // TODO(tillw): this is inefficient - do this during result generation - result = JSONUtil.indent(result, 2); - } - conf.out().print(result); - if (conf.fmt() == OutputFormat.CSV) { - conf.out().print("\r\n"); - } - ++stats.count; - // TODO(tillw) fix this approximation - stats.size += result.length(); - } - frame.getBuffer().clear(); - } finally { - try { - bbis.close(); - } catch (IOException e) { - throw new HyracksDataException(e); + + final IFrameTupleAccessor fta = resultReader.getFrameTupleAccessor(); + final IFrame frame = new VSizeFrame(resultDisplayFrameMgr); + + while (resultReader.read(frame) > 0) { + final ByteBuffer frameBuffer = frame.getBuffer(); + final byte[] frameBytes = frameBuffer.array(); + fta.reset(frameBuffer); + final int last = fta.getTupleCount(); + for (int tIndex = 0; tIndex < last; tIndex++) { + final int start = fta.getTupleStartOffset(tIndex); + int length = fta.getTupleEndOffset(tIndex) - start; + if (conf.fmt() == OutputFormat.CSV) { + if ((length > 0) && (frameBytes[start + length - 1] == '\n')) { + length--; } } - } while (resultReader.read(frame) > 0); + String result = new String(frameBytes, start, length, UTF_8); + if (wrap_array && notfirst) { + conf.out().print(", "); + } + notfirst = true; + if (indentJSON) { + // TODO(tillw): this is inefficient - do this during result generation + result = JSONUtil.indent(result, 2); + } + conf.out().print(result); + if (conf.fmt() == OutputFormat.CSV) { + conf.out().print("\r\n"); + } + ++stats.count; + // TODO(tillw) fix this approximation + stats.size += result.length(); + } + frameBuffer.clear(); } conf.out().flush(); @@ -209,7 +193,7 @@ public class ResultUtils { errorArray.put(errorMessage); try { errorResp.put("error-code", errorArray); - if (errorSummary != "") { + if (! "".equals(errorSummary)) { errorResp.put("summary", errorSummary); } else { //parse exception