java.lang.Object
com.inductiveautomation.historian.gateway.query.writing.HistoryWriter
All Implemented Interfaces:
QueryController
Direct Known Subclasses:
CalculationHistoryWriter, TallHistoryWriter

public class HistoryWriter extends Object implements QueryController
The history writer controls the flow of data from the QueryExecutor to the StreamingDatasetWriter. It also acts as the query controller, providing access to the query settings.
  • Field Details

  • Constructor Details

  • Method Details

    • calculateMaxRowLimit

      protected long calculateMaxRowLimit()
    • getLogger

      protected LoggerEx getLogger()
    • getQueryId

      public String getQueryId()
      The QueryId is an identifier for this particular query, so we can trace the route of the query across the various parts of SQLTags history. Any logging should include this id.
      Specified by:
      getQueryId in interface QueryController
    • getQueryStart

      public long getQueryStart()
      Specified by:
      getQueryStart in interface QueryController
    • getQueryEnd

      public long getQueryEnd()
      Specified by:
      getQueryEnd in interface QueryController
    • getBlockId

      public long getBlockId(long time)
      Description copied from interface: QueryController
      Returns which block the time belongs to. Generally, will be some multiple of the block window on top of the start time. There is one special case that we accommodate: seed values. Those belong to a block BEFORE the start time. For that reason, we calculate everything off of the start time, and not the block end.
      Specified by:
      getBlockId in interface QueryController
    • setQueryExecutor

      public void setQueryExecutor(HistoryQueryExecutor executor)
    • registerColumn

      protected void registerColumn(ResultNode column)
    • getColumns

      protected List<ResultNode> getColumns()
    • initLoader

      protected void initLoader() throws Exception
      Throws:
      Exception
    • initColumns

      protected void initColumns() throws Exception
      Creates the arrays rowData and rowQuality, which will get filled in, and then written from. If a HistoryWriter subclass returns a set of columns that are different than the natural set, this function should be overridden.
      Throws:
      Exception
    • getRowCount

      protected long getRowCount()
    • incrementRowCount

      protected void incrementRowCount()
    • getQueryParameters

      public TagHistoryQueryParams getQueryParameters()
      Description copied from interface: QueryController
      The parameters for the current query.
      Specified by:
      getQueryParameters in interface QueryController
    • getBlockSize

      public long getBlockSize()
      Description copied from interface: QueryController
      Returns the size of the blocks in milliseconds. Will be 0 if the results should be raw data.
      Specified by:
      getBlockSize in interface QueryController
      Returns:
      time in milliseconds covered by each block.
    • isRawQuery

      protected boolean isRawQuery()
    • calculateBlockSize

      protected void calculateBlockSize()
    • setWriter

      public void setWriter(StreamingDatasetWriter writer)
    • execute

      public void execute()
    • initializeWriter

      protected void initializeWriter()
    • finalizeWriter

      protected void finalizeWriter() throws Exception
      Throws:
      Exception
    • markCompletedTo

      protected void markCompletedTo(long time)
    • commitRows

      protected void commitRows() throws Exception
      Throws:
      Exception
    • advanceBlockEnd

      protected void advanceBlockEnd()
      Increments the block end by the block window size.
    • insertInList

      protected void insertInList(ResultNode node)