@Override public KeyValue next() throws IOException { boolean endOfBatch = false; StringWriter sw = new StringWriter(); if (rowIndex > batch.size - 1) { endOfBatch = !rows.nextBatch(batch); rowIndex = 0; } if (endOfBatch) { rows.close(); return null; } try { JsonFieldFiller.processRow(new JSONWriter(sw), batch, schema, rowIndex); } catch (JSONException e) { LOG.error("Unable to parse json {}", sw.toString()); return null; } rowIndex++; return new KeyValue(offset++, sw.toString().getBytes("UTF-8")); }
static void printJsonData(Configuration conf, String filename) throws IOException, JSONException { Path path = new Path(filename); Reader reader = OrcFile.createReader(path.getFileSystem(conf), path); OutputStreamWriter out = new OutputStreamWriter(System.out, "UTF-8"); RecordReader rows = reader.rows(null); Object row = null; List<OrcProto.Type> types = reader.getTypes(); while (rows.hasNext()) { row = rows.next(row); JSONWriter writer = new JSONWriter(out); printObject(writer, row, types, 0); out.write("\n"); out.flush(); } } }
static void printJsonData(final Reader reader) throws IOException, JSONException { PrintStream printStream = System.out; OutputStreamWriter out = new OutputStreamWriter(printStream, "UTF-8"); RecordReader rows = reader.rows(); try { TypeDescription schema = reader.getSchema(); VectorizedRowBatch batch = schema.createRowBatch(); while (rows.nextBatch(batch)) { for(int r=0; r < batch.size; ++r) { JSONWriter writer = new JSONWriter(out); printRow(writer, batch, schema, r); out.write("\n"); out.flush(); if (printStream.checkError()) { throw new IOException("Error encountered when writing to stdout."); } } } } finally { rows.close(); } } }