Interface SqlWriter

All Known Implementing Classes:
DefaultAvroSqlWriter, RecordSqlWriter

public interface SqlWriter
The SqlWriter interface provides a standard way for processors such as ExecuteSQL, ExecuteSQLRecord, QueryDatabaseTable, and QueryDatabaseTableRecord to write SQL result sets out to a flow file in whichever manner is appropriate. For example, ExecuteSQL writes the result set as Avro but ExecuteSQLRecord uses the Record API to write the result set out as prescribed by the selected RecordSetWriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Map<String,String>
    Returns a map of attribute key/value pairs to be added to any outgoing flow file(s).
    Returns the MIME type of the output format.
    default void
    updateCounters(org.apache.nifi.processor.ProcessSession session)
    Updates any session counters as a result of processing result sets.
    void
    writeEmptyResultSet(OutputStream outputStream, org.apache.nifi.logging.ComponentLog logger)
    Writes an empty result set to the output stream.
    long
    writeResultSet(ResultSet resultSet, OutputStream outputStream, org.apache.nifi.logging.ComponentLog logger, JdbcCommon.ResultSetRowCallback callback)
    Writes the given result set out to the given output stream, possibly applying a callback as each row is processed.
  • Method Details

    • writeResultSet

      long writeResultSet(ResultSet resultSet, OutputStream outputStream, org.apache.nifi.logging.ComponentLog logger, JdbcCommon.ResultSetRowCallback callback) throws Exception
      Writes the given result set out to the given output stream, possibly applying a callback as each row is processed.
      Parameters:
      resultSet - the ResultSet to be written
      outputStream - the OutputStream to write the result set to
      logger - a common logger that can be used to log messages during write
      callback - a MaxValueResultSetRowCollector that may be called as each row in the ResultSet is processed
      Returns:
      the number of rows written to the output stream
      Throws:
      Exception - if any errors occur during the writing of the result set to the output stream
    • getAttributesToAdd

      default Map<String,String> getAttributesToAdd()
      Returns a map of attribute key/value pairs to be added to any outgoing flow file(s). The default implementation is to return an empty map.
      Returns:
      a map of attribute key/value pairs
    • updateCounters

      default void updateCounters(org.apache.nifi.processor.ProcessSession session)
      Updates any session counters as a result of processing result sets. The default implementation is empty, no counters will be updated.
      Parameters:
      session - the session upon which to update counters
    • writeEmptyResultSet

      void writeEmptyResultSet(OutputStream outputStream, org.apache.nifi.logging.ComponentLog logger) throws IOException
      Writes an empty result set to the output stream. In some cases a ResultSet might not have any viable rows, but will throw an error or behave unexpectedly if rows are attempted to be retrieved. This method indicates the implementation should write whatever output is appropriate for a result set with no rows.
      Parameters:
      outputStream - the OutputStream to write the empty result set to
      logger - a common logger that can be used to log messages during write
      Throws:
      IOException - if any errors occur during the writing of an empty result set to the output stream
    • getMimeType

      String getMimeType()
      Returns the MIME type of the output format. This can be used in FlowFile attributes or to perform format-specific processing as necessary.
      Returns:
      the MIME type string of the output format.