Package com.tangosol.util.aggregator
Class QueryRecorder<K,V>
- java.lang.Object
-
- com.tangosol.util.aggregator.QueryRecorder<K,V>
-
- Type Parameters:
K
- the type of the Map entry keysV
- the type of the Map entry values
- All Implemented Interfaces:
ExternalizableLite
,PortableObject
,InvocableMap.EntryAggregator<K,V,QueryRecord>
,InvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
,Serializable
public class QueryRecorder<K,V> extends Object implements InvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>, ExternalizableLite, PortableObject
This aggregator is used to produce aQueryRecord
object that contains an estimated or actual cost of the query execution for a given filter.For example, the following code will print a QueryRecord, containing the estimated query cost and corresponding execution steps.
QueryRecorder agent = new QueryRecorder(RecordType.EXPLAIN); QueryRecord record = (QueryRecord) cache.aggregate(filter, agent); System.out.println(record);
- Author:
- tb 2011.05.26
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueryRecorder.RecordType
RecordType enum specifies whether theQueryRecorder
should be used to produce aQueryRecord
object that contains an estimated or an actual cost of the query execution.
-
Field Summary
-
Fields inherited from interface com.tangosol.util.InvocableMap.StreamingAggregator
ALLOW_INCONSISTENCIES, BY_MEMBER, BY_PARTITION, PARALLEL, PRESENT_ONLY, RETAINS_ENTRIES, SERIAL
-
-
Constructor Summary
Constructors Constructor Description QueryRecorder()
Default constructor (necessary for the ExternalizableLite interface).QueryRecorder(QueryRecorder.RecordType type)
Construct a QueryRecorder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accumulate(InvocableMap.Entry<? extends K,? extends V> entry)
Accumulate one entry into the result.boolean
accumulate(Streamer<? extends InvocableMap.Entry<? extends K,? extends V>> streamer)
Accumulate multiple entries into the result.QueryRecord
aggregate(Set<? extends InvocableMap.Entry<? extends K,? extends V>> setEntries)
Process a set of InvocableMap.Entry objects in order to produce an aggregated result.int
characteristics()
A bit mask representing the set of characteristics of this aggregator.boolean
combine(QueryRecord.PartialResult partialResult)
Merge another partial result into the result.QueryRecord
finalizeResult()
Return the final result of the aggregation.QueryRecord.PartialResult
getPartialResult()
Return the partial result of the aggregation.QueryRecorder.RecordType
getType()
Get the record type for this query recorder.void
readExternal(PofReader in)
Restore the contents of a user type instance by reading its state using the specified PofReader object.void
readExternal(DataInput in)
Restore the contents of this object by loading the object's state from the passed DataInput object.InvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
supply()
Create a new instance of this aggregator.void
writeExternal(PofWriter out)
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.void
writeExternal(DataOutput out)
Save the contents of this object by storing the object's state into the passed DataOutput object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tangosol.util.InvocableMap.StreamingAggregator
isAllowInconsistencies, isByMember, isByPartition, isParallel, isPresentOnly, isRetainsEntries, isSerial
-
-
-
-
Constructor Detail
-
QueryRecorder
public QueryRecorder()
Default constructor (necessary for the ExternalizableLite interface).
-
QueryRecorder
public QueryRecorder(QueryRecorder.RecordType type)
Construct a QueryRecorder.- Parameters:
type
- the type for this aggregator
-
-
Method Detail
-
getType
public QueryRecorder.RecordType getType()
Get the record type for this query recorder.- Returns:
- the record type enum
-
aggregate
public QueryRecord aggregate(Set<? extends InvocableMap.Entry<? extends K,? extends V>> setEntries)
Process a set of InvocableMap.Entry objects in order to produce an aggregated result.- Specified by:
aggregate
in interfaceInvocableMap.EntryAggregator<K,V,QueryRecord>
- Specified by:
aggregate
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Parameters:
setEntries
- a Set of read-only InvocableMap.Entry objects to aggregate- Returns:
- the aggregated result from processing the entries
-
supply
public InvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord> supply()
Description copied from interface:InvocableMap.StreamingAggregator
Create a new instance of this aggregator.- Specified by:
supply
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Returns:
- a StreamAggregator
-
accumulate
public boolean accumulate(Streamer<? extends InvocableMap.Entry<? extends K,? extends V>> streamer)
Description copied from interface:InvocableMap.StreamingAggregator
Accumulate multiple entries into the result.Important note: The default implementation of this method provides necessary logic for aggregation short-circuiting and should rarely (if ever) be overridden by the custom aggregator implementation.
- Specified by:
accumulate
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Parameters:
streamer
- aStreamer
that can be used to iterate over entries to add- Returns:
true
to continue the aggregation, andfalse
to signal to the caller that the result is ready and the aggregation can be short-circuited
-
accumulate
public boolean accumulate(InvocableMap.Entry<? extends K,? extends V> entry)
Description copied from interface:InvocableMap.StreamingAggregator
Accumulate one entry into the result.- Specified by:
accumulate
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Parameters:
entry
- the entry to accumulate into the aggregation result- Returns:
true
to continue the aggregation, andfalse
to signal to the caller that the result is ready and the aggregation can be short-circuited
-
combine
public boolean combine(QueryRecord.PartialResult partialResult)
Description copied from interface:InvocableMap.StreamingAggregator
Merge another partial result into the result.- Specified by:
combine
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Parameters:
partialResult
- the partial result to merge- Returns:
true
to continue the aggregation, andfalse
to signal to the caller that the result is ready and the aggregation can be short-circuited
-
getPartialResult
public QueryRecord.PartialResult getPartialResult()
Description copied from interface:InvocableMap.StreamingAggregator
Return the partial result of the aggregation.- Specified by:
getPartialResult
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Returns:
- the partial result of the aggregation
-
finalizeResult
public QueryRecord finalizeResult()
Description copied from interface:InvocableMap.StreamingAggregator
Return the final result of the aggregation.- Specified by:
finalizeResult
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Returns:
- the final result of the aggregation
-
characteristics
public int characteristics()
Description copied from interface:InvocableMap.StreamingAggregator
A bit mask representing the set of characteristics of this aggregator.By default, characteristics are a combination of
InvocableMap.StreamingAggregator.PARALLEL
andInvocableMap.StreamingAggregator.RETAINS_ENTRIES
, which is sub-optimal and should be overridden by the aggregator implementation if the aggregator does not need to retain entries (which is often the case).- Specified by:
characteristics
in interfaceInvocableMap.StreamingAggregator<K,V,QueryRecord.PartialResult,QueryRecord>
- Returns:
- a bit mask representing the set of characteristics of this aggregator
- See Also:
InvocableMap.StreamingAggregator.ALLOW_INCONSISTENCIES
,InvocableMap.StreamingAggregator.BY_MEMBER
,InvocableMap.StreamingAggregator.BY_PARTITION
,InvocableMap.StreamingAggregator.PARALLEL
,InvocableMap.StreamingAggregator.PRESENT_ONLY
,InvocableMap.StreamingAggregator.RETAINS_ENTRIES
,InvocableMap.StreamingAggregator.SERIAL
-
readExternal
public void readExternal(DataInput in) throws IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternal
in interfaceExternalizableLite
- Parameters:
in
- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException
- if an I/O exception occursNotActiveException
- if the object is not in its initial state, and therefore cannot be deserialized into
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternal
in interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-
readExternal
public void readExternal(PofReader in) throws IOException
Restore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
readExternal
in interfacePortableObject
- Parameters:
in
- the PofReader from which to read the object's state- Throws:
IOException
- if an I/O error occurs
-
writeExternal
public void writeExternal(PofWriter out) throws IOException
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
writeExternal
in interfacePortableObject
- Parameters:
out
- the PofWriter to which to write the object's state- Throws:
IOException
- if an I/O error occurs
-
-