@Override public final WriteResult write(final Record record) throws IOException { final Map<String, String> attributes = writeRecord(record); return WriteResult.of(++recordCount, attributes); }
@Override public RecordSchema getSchema() { return new SimpleRecordSchema(fields); } };
/** * Returns the next record in the stream or <code>null</code> if no more records are available. Types will be coerced and any unknown fields will be dropped. * * @return the next record in the stream or <code>null</code> if no more records are available. * * @throws IOException if unable to read from the underlying data * @throws MalformedRecordException if an unrecoverable failure occurs when trying to parse a record * @throws SchemaValidationException if a Record contains a field that violates the schema and cannot be coerced into the appropriate field type. */ default Record nextRecord() throws IOException, MalformedRecordException { return nextRecord(true, true); }
@Override public void writeEmptyResultSet(OutputStream outputStream, ComponentLog logger) throws IOException { try (final RecordSetWriter resultSetWriter = recordSetWriterFactory.createWriter(logger, writeSchema, outputStream)) { mimeType = resultSetWriter.getMimeType(); resultSetWriter.beginRecordSet(); resultSetWriter.finishRecordSet(); } catch (final Exception e) { throw new IOException(e); } }
@Override public void process(final OutputStream out) throws IOException { try { final RecordSetWriter writer = writerFactory.createWriter(getLogger(), schema, out); writer.write(recordSet); writer.flush(); mimeType.append(writer.getMimeType()); } catch (SchemaNotFoundException e) { throw new ProcessException("Could not parse Solr response", e); } } });
private RecordSetWriter createIfNecessary(final RecordSetWriter writer, final RecordSetWriterFactory factory, final ProcessSession session, final FlowFile flowFile, final RecordSchema outputSchema) throws SchemaNotFoundException, IOException { if (writer != null) { return writer; } final OutputStream out = session.write(flowFile); final RecordSetWriter created = factory.createWriter(getLogger(), outputSchema, out); created.beginRecordSet(); return created; }
@Override public WriteResult write(final RecordSet recordSet) throws IOException { beginRecordSet(); Record record; while ((record = recordSet.next()) != null) { write(record); } return finishRecordSet(); }
@Override public RecordSchema getSchema() throws IOException { try { return RecordReader.this.getSchema(); } catch (final MalformedRecordException mre) { throw new IOException(mre); } }
private void closeWriter(final RecordSetWriter writer) { try { if (writer != null) { writer.close(); } } catch (final Exception ioe) { logger.warn("Failed to close Record Writer", ioe); } }
@Override public final WriteResult finishRecordSet() throws IOException { if (!isActiveRecordSet()) { throw new IllegalStateException("Cannot finish RecordSet because no RecordSet has begun"); } final Map<String, String> attributes = onFinishRecordSet(); return WriteResult.of(recordCount, attributes == null ? Collections.emptyMap() : attributes); }
@Override public WriteResult finishRecordSet() throws IOException { return WriteResult.of(recordCount, Collections.emptyMap()); } };
private SimpleRecordSchema(final List<RecordField> fields, final String text, final String schemaFormat, final boolean textAvailable, final SchemaIdentifier id) { this(text, schemaFormat, textAvailable, id); setFields(fields); }
public SimpleRecordSchema(final List<RecordField> fields, final SchemaIdentifier id) { this(fields, createText(fields), null, false, id); }
public RecordSchema getSchema(final Map<String, String> variables, final RecordSchema readSchema) throws SchemaNotFoundException, IOException { return getSchema(variables, EMPTY_INPUT_STREAM, readSchema); }
@Override public final void beginRecordSet() throws IOException { if (activeRecordSet) { throw new IllegalStateException("Cannot begin a RecordSet because a RecordSet has already begun"); } activeRecordSet = true; onBeginRecordSet(); }
@Override public void close() throws IOException { if (generator != null) { generator.close(); } super.close(); }
@Override public Record next() throws IOException { try { return RecordReader.this.nextRecord(); } catch (final MalformedRecordException mre) { throw new IOException(mre); } } };
@Override public RecordSchema getSchema() { return new SimpleRecordSchema(fields); } };
private void closeWriter(final RecordSetWriter writer) { try { if (writer != null) { writer.close(); } } catch (final Exception ioe) { logger.warn("Failed to close Record Writer", ioe); } }
public SimpleRecordSchema(final List<RecordField> fields) { this(fields, createText(fields), null, false, SchemaIdentifier.EMPTY); }