Class LegacyHistoryExecutor
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.sqltags.history.query.AbstractHistoryLoader<java.lang.Integer>
-
- com.inductiveautomation.gateway.tags.history.query.LegacyHistoryExecutor
-
- All Implemented Interfaces:
HistoryQueryExecutor
public class LegacyHistoryExecutor extends AbstractHistoryLoader<java.lang.Integer>
************** CORE QUERY FUNCTIONS This system works by doing the following:
1) Get tag meta: map paths to IDs, get SCIDs, etc between the range.
2) Get the scan class exec records, so we can tell when things were running.
3) Get the values between the range.
4) Pass though the values, checking SCEs, setting the "current" value in the column, returning the latest value.
Back up in the HistoryWriter...
5) At the end of every "block", commit the current values. ***************
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
LegacyHistoryExecutor.PreprocessedHistoryGroup
We implement our own history group here in hopes of being as efficient as possible.
-
Field Summary
-
Fields inherited from class com.inductiveautomation.ignition.gateway.sqltags.history.query.AbstractHistoryLoader
endTime, startTime
-
-
Constructor Summary
Constructors Constructor Description LegacyHistoryExecutor(GatewayContext context, QueryController controller, java.util.List<ColumnQueryDefinition> colDefs, java.lang.String execName, java.lang.String datasource, java.lang.String systemName, java.lang.String providerName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
advancePartition()
Queries data and sets up valueRS.protected HistoryNode
createColumn(QueryController controller, ColumnQueryDefinition column)
void
endReading()
If startReading was called, this function must be called (that is, it should be in a finally block).protected DSHistoryColumn
getColumnAt(int pos)
java.util.List<? extends HistoryNode>
getColumnNodes()
Returns the HistoryNodes of this executor.protected java.util.Collection<HistoryNode>
getColumns(java.lang.String path)
protected DataTypeClass
getDataTypeForTag(java.lang.Integer tagId)
protected DataTypeClass
getDataTypeForTagColumn(java.lang.Integer tagId)
int
getEffectiveWindowSizeMS()
When "natural" results are requested, this will be called to let the query executors say what they think "natural" means.protected java.util.Set<java.lang.Integer>
getIdsForPostQuery(long end)
protected java.util.Set<java.lang.Integer>
getIdsForTime(long start, long end, boolean compressedOnly)
Returns the tag ids that were in use during the span of time (inclusive).protected LoggerEx
getLogger()
protected java.util.Collection<java.lang.Integer>
getPathPositions(java.lang.String path)
Returns the positions of columns for the given path.protected QueryCache
getQueryCache()
protected java.lang.String
getReadQuery(int tagids, java.lang.String partitionName, boolean includeVType)
Returns a read query for the specified number of tag id parameters.protected com.google.common.collect.Multimap<java.lang.String,java.lang.Integer>
getSeedIdMap(boolean post)
protected java.util.Set<java.lang.String>
getTagPaths()
Returns the paths that correspond to the columns.protected RawTagValue
getValueFromDS(Dataset ds, int rowId)
protected RawTagValue
getValueFromRS(java.sql.ResultSet rs)
void
initialize()
The primary task of initialize is to load the information about the tags and update the columns, so that we'll be ready to query.protected long
loadValue(IdentifiedHistoricalValue<java.lang.Integer> value)
Puts the value into the appropriate column.protected void
maybeSortTagInfo()
protected void
primeRead()
This function starts the read process, and gets the system ready for the first call to readNextFromSourceprotected java.util.SortedSet<RawTagValue>
readCompletionValues()
protected IdentifiedHistoricalValue<java.lang.Integer>
readNextFromSource()
protected IdentifiedHistoricalValue<java.lang.Integer>
readPreProcessedSet()
This function reads a set of processed values.protected java.util.SortedSet<RawTagValue>
readSeedValues()
This function reads the "seed" values- the last value for each tag before the start time.protected IdentifiedHistoricalValue<java.lang.Integer>
readSingle()
protected HistoryNode
registerColumn(ColumnQueryDefinition column)
protected void
registerTagForPath(java.lang.String path, java.lang.Integer id, DataTypeClass dType, InterpolationMode queryMode, java.lang.Integer scid)
There can ultimately be multiple tags in the store that contribute to a single "tag path".protected void
registerTagInformation(java.lang.String path, java.util.List<HistoricalTagInfo> infos)
protected java.util.SortedSet<RawTagValue>
runSpecialValueQuery(java.lang.String query, java.lang.Long timeParam, java.util.List<Partition> partitions, com.google.common.collect.Multimap<java.lang.String,java.lang.Integer> toReadSet)
protected void
setScanClassRecordMap(SCExecMap map)
protected void
setupHistoryLoader(boolean readSeedValues, boolean readSce)
protected IdentifiedHistoricalValue<java.lang.Integer>
updatePreProcSet(IdentifiedHistoricalValue<java.lang.Integer> curVal, IdentifiedHistoricalValue<java.lang.Integer> newVal)
protected boolean
usingPreProcessed()
-
Methods inherited from class com.inductiveautomation.ignition.gateway.sqltags.history.query.AbstractHistoryLoader
getController, getEndTime, getQueryId, getSeedValues, getStartTime, hasMore, nextTime, pathToString, processData, readNext, setErrored, setPostValues, setSeedValues, startReading
-
-
-
-
Constructor Detail
-
LegacyHistoryExecutor
public LegacyHistoryExecutor(GatewayContext context, QueryController controller, java.util.List<ColumnQueryDefinition> colDefs, java.lang.String execName, java.lang.String datasource, java.lang.String systemName, java.lang.String providerName)
-
-
Method Detail
-
getLogger
protected LoggerEx getLogger()
- Specified by:
getLogger
in classAbstractHistoryLoader<java.lang.Integer>
-
getQueryCache
protected QueryCache getQueryCache()
-
getReadQuery
protected java.lang.String getReadQuery(int tagids, java.lang.String partitionName, boolean includeVType)
Returns a read query for the specified number of tag id parameters.
-
getColumnNodes
public java.util.List<? extends HistoryNode> getColumnNodes()
Description copied from interface:HistoryQueryExecutor
Returns the HistoryNodes of this executor. There MUST be one for every tag path, and they must be in the same order as the paths provided to the executor when it was created. Also, these values must be available as soon as the executor is created. However, they won't be consulted for their data type until after initialize is called, so the normal procedure is to create and returnDelegatingHistoryNode
s, which get filled in later.
-
getTagPaths
protected java.util.Set<java.lang.String> getTagPaths()
Returns the paths that correspond to the columns. May contain the same path multiple times.
-
getPathPositions
protected java.util.Collection<java.lang.Integer> getPathPositions(java.lang.String path)
Returns the positions of columns for the given path.
-
getColumns
protected java.util.Collection<HistoryNode> getColumns(java.lang.String path)
-
registerColumn
protected HistoryNode registerColumn(ColumnQueryDefinition column)
-
getColumnAt
protected DSHistoryColumn getColumnAt(int pos)
-
setScanClassRecordMap
protected void setScanClassRecordMap(SCExecMap map)
-
getEffectiveWindowSizeMS
public int getEffectiveWindowSizeMS()
Description copied from interface:HistoryQueryExecutor
When "natural" results are requested, this will be called to let the query executors say what they think "natural" means. If a query executor does not support natural results, it should return -1. If all of the query executors return -1, a raw query will be performed.
-
getSeedIdMap
protected com.google.common.collect.Multimap<java.lang.String,java.lang.Integer> getSeedIdMap(boolean post)
-
getDataTypeForTag
protected DataTypeClass getDataTypeForTag(java.lang.Integer tagId)
-
getDataTypeForTagColumn
protected DataTypeClass getDataTypeForTagColumn(java.lang.Integer tagId)
-
maybeSortTagInfo
protected void maybeSortTagInfo()
-
getIdsForTime
protected java.util.Set<java.lang.Integer> getIdsForTime(long start, long end, boolean compressedOnly)
Returns the tag ids that were in use during the span of time (inclusive). If end==0, it will return the ids for the seed values.
-
getIdsForPostQuery
protected java.util.Set<java.lang.Integer> getIdsForPostQuery(long end)
-
registerTagInformation
protected void registerTagInformation(java.lang.String path, java.util.List<HistoricalTagInfo> infos)
-
registerTagForPath
protected void registerTagForPath(java.lang.String path, java.lang.Integer id, DataTypeClass dType, InterpolationMode queryMode, java.lang.Integer scid)
There can ultimately be multiple tags in the store that contribute to a single "tag path". This function registers the information for a tag, given its path.
-
createColumn
protected HistoryNode createColumn(QueryController controller, ColumnQueryDefinition column)
-
loadValue
protected long loadValue(IdentifiedHistoricalValue<java.lang.Integer> value)
Description copied from class:AbstractHistoryLoader
Puts the value into the appropriate column.- Specified by:
loadValue
in classAbstractHistoryLoader<java.lang.Integer>
-
initialize
public void initialize() throws java.lang.Exception
The primary task of initialize is to load the information about the tags and update the columns, so that we'll be ready to query.- Specified by:
initialize
in interfaceHistoryQueryExecutor
- Overrides:
initialize
in classAbstractHistoryLoader<java.lang.Integer>
- Throws:
java.lang.Exception
-
setupHistoryLoader
protected void setupHistoryLoader(boolean readSeedValues, boolean readSce)
-
getValueFromRS
protected RawTagValue getValueFromRS(@Nonnull java.sql.ResultSet rs) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getValueFromDS
@Nullable protected RawTagValue getValueFromDS(@Nullable Dataset ds, int rowId) throws java.lang.Exception
- Throws:
java.lang.Exception
-
readSeedValues
protected java.util.SortedSet<RawTagValue> readSeedValues() throws java.lang.Exception
This function reads the "seed" values- the last value for each tag before the start time.- Throws:
java.lang.Exception
-
readCompletionValues
protected java.util.SortedSet<RawTagValue> readCompletionValues() throws java.lang.Exception
- Throws:
java.lang.Exception
-
runSpecialValueQuery
protected java.util.SortedSet<RawTagValue> runSpecialValueQuery(java.lang.String query, java.lang.Long timeParam, java.util.List<Partition> partitions, com.google.common.collect.Multimap<java.lang.String,java.lang.Integer> toReadSet) throws java.lang.Exception
- Throws:
java.lang.Exception
-
primeRead
protected void primeRead() throws java.lang.Exception
Description copied from class:AbstractHistoryLoader
This function starts the read process, and gets the system ready for the first call to readNextFromSource- Specified by:
primeRead
in classAbstractHistoryLoader<java.lang.Integer>
- Throws:
java.lang.Exception
-
endReading
public void endReading()
Description copied from interface:HistoryQueryExecutor
If startReading was called, this function must be called (that is, it should be in a finally block).- Specified by:
endReading
in interfaceHistoryQueryExecutor
- Overrides:
endReading
in classAbstractHistoryLoader<java.lang.Integer>
-
advancePartition
protected boolean advancePartition() throws java.lang.Exception
Queries data and sets up valueRS. Returns FALSE if no data is available. Returns TRUE if data is found. Important - if TRUE is returned, valueRS.next() will have been called, so first value is ready to be read.- Throws:
java.lang.Exception
-
readNextFromSource
protected IdentifiedHistoricalValue<java.lang.Integer> readNextFromSource() throws java.lang.Exception
- Specified by:
readNextFromSource
in classAbstractHistoryLoader<java.lang.Integer>
- Throws:
java.lang.Exception
-
usingPreProcessed
protected boolean usingPreProcessed()
-
readPreProcessedSet
protected IdentifiedHistoricalValue<java.lang.Integer> readPreProcessedSet() throws java.lang.Exception
This function reads a set of processed values. Processed values consist of "min, max, avg, entry, exit" (which might be combined), or potentially just a single "direct". Average and Direct are both identified by flags=0. All values are now stored with the same timestamp, as their order can be determined by the flags. However, for 7.4 & 7.5 this wasn't true- in those versions min and max had different times. So, we have to do a bit of work to make sure we only read our block. We read until the time progresses by too much (1/2 block size).- Throws:
java.lang.Exception
-
updatePreProcSet
protected IdentifiedHistoricalValue<java.lang.Integer> updatePreProcSet(IdentifiedHistoricalValue<java.lang.Integer> curVal, IdentifiedHistoricalValue<java.lang.Integer> newVal)
-
readSingle
protected IdentifiedHistoricalValue<java.lang.Integer> readSingle() throws java.lang.Exception
- Throws:
java.lang.Exception
-
-