Class DatasourceQueryExecutor
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.sqltags.history.query.AbstractHistoryLoader<java.lang.Integer>
-
- com.inductiveautomation.gateway.tags.history.query.DatasourceQueryExecutor
-
- All Implemented Interfaces:
HistoryQueryExecutor
public class DatasourceQueryExecutor 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
DatasourceQueryExecutor.MixedModeInterpolator
protected static class
DatasourceQueryExecutor.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 DatasourceQueryExecutor(GatewayContext context, QueryController controller, java.util.List<ColumnQueryDefinition> colDefs, java.lang.String datasource, java.lang.String gatewayName, 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 void
buildColumns()
protected Interpolator
createInterpolator(DataTypeClass dataType, TimelineList<InterpolationMode> timelineList)
void
endReading()
If startReading was called, this function must be called (that is, it should be in a finally block).protected HistoryColumn
getColumnAt(int pos)
Returns HistoryColumn, or null if the node isn't a column, which shouldn't happen after 7.8.2.java.util.List<? extends HistoryNode>
getColumnNodes()
Returns the HistoryNodes of this executor.protected java.util.Collection<HistoryNode>
getColumns(java.lang.String path)
protected DataTypeClass
getDataTypeFor(java.lang.String name, HistoricalInfoMap.HistoricalInfo info)
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 HistoryNode
getNodeAt(int pos)
protected java.util.Collection<java.lang.Integer>
getPathPositions(java.lang.String path)
Returns the positions of columns for the given path.protected HistoricalValue
getPotentiallyStaleDatapoint(long valueTS)
Returns a stale datapoint for the appropriate time if the system was down sometime between the last value to now.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 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 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 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
-
DatasourceQueryExecutor
public DatasourceQueryExecutor(@Nonnull GatewayContext context, @Nonnull QueryController controller, @Nonnull java.util.List<ColumnQueryDefinition> colDefs, java.lang.String datasource, @Nullable java.lang.String gatewayName, 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.
-
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)
-
getDataTypeFor
protected DataTypeClass getDataTypeFor(java.lang.String name, HistoricalInfoMap.HistoricalInfo info)
-
buildColumns
protected void buildColumns()
-
getNodeAt
protected HistoryNode getNodeAt(int pos)
-
getColumnAt
protected HistoryColumn getColumnAt(int pos)
Returns HistoryColumn, or null if the node isn't a column, which shouldn't happen after 7.8.2. Previous to that ErrorColumn was erroneously not an actual HistoryColumn
-
createInterpolator
protected Interpolator createInterpolator(DataTypeClass dataType, TimelineList<InterpolationMode> timelineList)
-
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)
-
getPotentiallyStaleDatapoint
protected HistoricalValue getPotentiallyStaleDatapoint(long valueTS)
Returns a stale datapoint for the appropriate time if the system was down sometime between the last value to now.
-
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
-
getValueFromRS
protected RawTagValue getValueFromRS(java.sql.ResultSet rs) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getValueFromDS
protected RawTagValue getValueFromDS(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
-
-