public NamedWindowRootViewInstance( NamedWindowRootView rootView, AgentInstanceContext agentInstanceContext, EventTableIndexMetadata eventTableIndexMetadata) { this.rootView = rootView; AgentInstanceContext = agentInstanceContext; IndexRepository = new EventTableIndexRepository(eventTableIndexMetadata); foreach (var entry in eventTableIndexMetadata.Indexes ) { if (entry.Value.OptionalQueryPlanIndexItem != null) { var index = EventTableUtil.BuildIndex( agentInstanceContext, 0, entry.Value.OptionalQueryPlanIndexItem, rootView.EventType, true, entry.Key.IsUnique, entry.Value.OptionalIndexName, null, false); IndexRepository.AddIndex( entry.Key, new EventTableIndexRepositoryEntry( entry.Value.OptionalIndexName, entry.Value.OptionalIndexModuleName, index)); } } }
public NamedWindowRootViewInstance(NamedWindowRootView rootView, AgentInstanceContext agentInstanceContext) { _rootView = rootView; _agentInstanceContext = agentInstanceContext; _indexRepository = new EventTableIndexRepository(); _tablePerMultiLookup = new Dictionary <SubordWMatchExprLookupStrategy, EventTable[]>(); }
protected TableInstanceBase( Table table, AgentInstanceContext agentInstanceContext) { this.table = table; this.agentInstanceContext = agentInstanceContext; indexRepository = new EventTableIndexRepository(table.EventTableIndexMetadata); }
protected TableStateInstance( TableMetadata tableMetadata, AgentInstanceContext agentInstanceContext, IReaderWriterLockManager rwLockManager) { this._tableLevelRWLock = rwLockManager.CreateLock(GetType()); this._tableMetadata = tableMetadata; this._agentInstanceContext = agentInstanceContext; this._indexRepository = new EventTableIndexRepository(tableMetadata.EventTableIndexMetadataRepo); }
public NamedWindowRootViewInstance(NamedWindowRootView rootView, AgentInstanceContext agentInstanceContext, EventTableIndexMetadata eventTableIndexMetadata) { _rootView = rootView; _agentInstanceContext = agentInstanceContext; _indexRepository = new EventTableIndexRepository(); foreach (KeyValuePair <IndexMultiKey, EventTableIndexMetadataEntry> entry in eventTableIndexMetadata.Indexes) { if (entry.Value.QueryPlanIndexItem != null) { EventTable index = EventTableUtil.BuildIndex(agentInstanceContext, 0, entry.Value.QueryPlanIndexItem, rootView.EventType, true, entry.Key.IsUnique, entry.Value.OptionalIndexName, null, false); _indexRepository.AddIndex(entry.Key, new EventTableIndexRepositoryEntry(entry.Value.OptionalIndexName, index)); } } _tablePerMultiLookup = new Dictionary <SubordWMatchExprLookupStrategy, EventTable[]>(); }
/// <summary> /// The FindIndex /// </summary> /// <param name="keyNamesAvailable">The key names available.</param> /// <param name="rangeNamesAvailable">The range names available.</param> /// <param name="indexRepository">The <see cref="EventTableIndexRepository" /></param> /// <param name="virtualDataWindow">The <see cref="VirtualDWView" /></param> /// <param name="attributes">The <see cref="Attribute" /> array</param> /// <returns></returns> private static Pair <IndexMultiKey, EventTableAndNamePair> FindIndex( ISet <string> keyNamesAvailable, ISet <string> rangeNamesAvailable, EventTableIndexRepository indexRepository, VirtualDWView virtualDataWindow, Attribute[] attributes) { if (virtualDataWindow != null) { var tablePairNoName = virtualDataWindow.GetFireAndForgetDesc(keyNamesAvailable, rangeNamesAvailable); return(new Pair <IndexMultiKey, EventTableAndNamePair>(tablePairNoName.First, new EventTableAndNamePair(tablePairNoName.Second, null))); } var indexHint = IndexHint.GetIndexHint(attributes); var optionalIndexHintInstructions = indexHint != null ? indexHint.InstructionsFireAndForget : null; return(indexRepository.FindTable(keyNamesAvailable, rangeNamesAvailable, optionalIndexHintInstructions)); }
public override void RemoveOldData(EventBean[] oldData, EventTableIndexRepository indexRepository) { for (int i = 0; i < oldData.Length; i++) { var theEvent = (RevisionEventBeanDeclared)oldData[i]; // If the remove event is the latest event, remove from all caches if (theEvent.IsLatest) { var key = theEvent.Key; _statePerKey.Remove(key); foreach (EventTable table in indexRepository.GetTables()) { table.Remove(oldData); } } } }
public override void RemoveOldData(EventBean[] oldData, EventTableIndexRepository indexRepository) { foreach (EventBean anOldData in oldData) { var theEvent = (RevisionEventBeanMerge)anOldData; // If the remove event is the latest event, remove from all caches if (theEvent.IsLatest) { var key = theEvent.Key; _statePerKey.Remove(key); foreach (EventTable table in indexRepository.GetTables()) { table.Remove(oldData); } } } }
private static Pair<IndexMultiKey, EventTableAndNamePair> FindIndex( ISet<string> keyNamesAvailable, ISet<string> rangeNamesAvailable, EventTableIndexRepository indexRepository, VirtualDWView virtualDataWindow, Attribute[] annotations) { if (virtualDataWindow != null) { var tablePairNoName = VirtualDWQueryPlanUtil.GetFireAndForgetDesc( virtualDataWindow.EventType, keyNamesAvailable, rangeNamesAvailable); return new Pair<IndexMultiKey, EventTableAndNamePair>( tablePairNoName.First, new EventTableAndNamePair(tablePairNoName.Second, null)); } var indexHint = IndexHint.GetIndexHint(annotations); IList<IndexHintInstruction> optionalIndexHintInstructions = indexHint != null ? indexHint.GetInstructionsFireAndForget() : null; return indexRepository.FindTable(keyNamesAvailable, rangeNamesAvailable, optionalIndexHintInstructions); }
public override void OnUpdate(EventBean[] newData, EventBean[] oldData, NamedWindowRootViewInstance namedWindowRootView, EventTableIndexRepository indexRepository) { // If new data is filled, it is not a delete RevisionEventBeanDeclared revisionEvent; Object key; if ((newData == null) || (newData.Length == 0)) { // we are removing an event revisionEvent = (RevisionEventBeanDeclared)oldData[0]; key = revisionEvent.Key; _statePerKey.Remove(key); // Insert into indexes for fast deletion, if there are any foreach (EventTable table in indexRepository.GetTables()) { table.Remove(oldData); } // make as not the latest event since its due for removal revisionEvent.IsLatest = false; namedWindowRootView.UpdateChildren(null, oldData); return; } revisionEvent = (RevisionEventBeanDeclared)newData[0]; EventBean underlyingEvent = revisionEvent.UnderlyingFullOrDelta; EventType underyingEventType = underlyingEvent.EventType; // obtain key values key = null; RevisionTypeDesc typesDesc = null; bool isBaseEventType = false; if (underyingEventType == _baseEventType) { key = PropertyUtility.GetKeys(underlyingEvent, _fullKeyGetters); isBaseEventType = true; } else { typesDesc = TypeDescriptors.Get(underyingEventType); // if this type cannot be found, check all supertypes, if any if (typesDesc == null) { IEnumerable <EventType> superTypes = underyingEventType.DeepSuperTypes; if (superTypes != null) { foreach (var superType in superTypes) { if (superType == _baseEventType) { key = PropertyUtility.GetKeys(underlyingEvent, _fullKeyGetters); isBaseEventType = true; break; } typesDesc = TypeDescriptors.Get(superType); if (typesDesc != null) { TypeDescriptors.Put(underyingEventType, typesDesc); key = PropertyUtility.GetKeys(underlyingEvent, typesDesc.KeyPropertyGetters); break; } } } } else { key = PropertyUtility.GetKeys(underlyingEvent, typesDesc.KeyPropertyGetters); } } // get the state for this key value RevisionStateDeclared revisionState = _statePerKey.Get(key); // Delta event and no full if ((!isBaseEventType) && (revisionState == null)) { return; // Ignore the event, its a delta and we don't currently have a full event for it } // New full event if (revisionState == null) { revisionState = new RevisionStateDeclared(underlyingEvent, null, null); _statePerKey.Put(key, revisionState); // prepare revison event revisionEvent.LastBaseEvent = underlyingEvent; revisionEvent.Key = key; revisionEvent.Holders = null; revisionEvent.IsLatest = true; // Insert into indexes for fast deletion, if there are any foreach (EventTable table in indexRepository.GetTables()) { table.Add(newData); } // post to data window revisionState.LastEvent = revisionEvent; namedWindowRootView.UpdateChildren(new EventBean[] { revisionEvent }, null); return; } // new version long versionNumber = revisionState.IncRevisionNumber(); // Previously-seen full event if (isBaseEventType) { revisionState.Holders = null; revisionState.BaseEventUnderlying = underlyingEvent; } // Delta event to existing full event else { var groupNum = typesDesc.Group.GroupNum; var holders = revisionState.Holders; if (holders == null) // optimization - the full event sets it to null, deltas all get a new one { holders = new RevisionBeanHolder[_groups.Length]; } else { holders = ArrayCopy(holders); // preserve the last revisions } // add the new revision for a property group on top holders[groupNum] = new RevisionBeanHolder(versionNumber, underlyingEvent, typesDesc.ChangesetPropertyGetters); revisionState.Holders = holders; } // prepare revision event revisionEvent.LastBaseEvent = revisionState.BaseEventUnderlying; revisionEvent.Holders = revisionState.Holders; revisionEvent.Key = key; revisionEvent.IsLatest = true; // get prior event RevisionEventBeanDeclared lastEvent = revisionState.LastEvent; lastEvent.IsLatest = false; // data to post var newDataPost = new EventBean[] { revisionEvent }; var oldDataPost = new EventBean[] { lastEvent }; // Update indexes foreach (EventTable table in indexRepository.GetTables()) { table.Remove(oldDataPost); table.Add(newDataPost); } // keep reference to last event revisionState.LastEvent = revisionEvent; namedWindowRootView.UpdateChildren(newDataPost, oldDataPost); }
public override void OnUpdate(EventBean[] newData, EventBean[] oldData, NamedWindowRootViewInstance namedWindowRootView, EventTableIndexRepository indexRepository) { // If new data is filled, it is not a delete RevisionEventBeanMerge revisionEvent; Object key; if ((newData == null) || (newData.Length == 0)) { // we are removing an event revisionEvent = (RevisionEventBeanMerge)oldData[0]; key = revisionEvent.Key; _statePerKey.Remove(key); // Insert into indexes for fast deletion, if there are any foreach (EventTable table in indexRepository.GetTables()) { table.Remove(oldData); } // make as not the latest event since its due for removal revisionEvent.IsLatest = false; namedWindowRootView.UpdateChildren(null, oldData); return; } revisionEvent = (RevisionEventBeanMerge)newData[0]; EventBean underlyingEvent = revisionEvent.UnderlyingFullOrDelta; EventType underyingEventType = underlyingEvent.EventType; // obtain key values key = null; RevisionTypeDesc typesDesc; Boolean isBaseEventType = false; if (underyingEventType == RevisionSpec.BaseEventType) { typesDesc = _infoFullType; key = PropertyUtility.GetKeys(underlyingEvent, _infoFullType.KeyPropertyGetters); isBaseEventType = true; } else { typesDesc = TypeDescriptors.Get(underyingEventType); // if this type cannot be found, check all supertypes, if any if (typesDesc == null) { EventType[] superTypes = underyingEventType.DeepSuperTypes; if (superTypes != null) { foreach (var superType in superTypes) { if (superType == RevisionSpec.BaseEventType) { typesDesc = _infoFullType; key = PropertyUtility.GetKeys(underlyingEvent, _infoFullType.KeyPropertyGetters); isBaseEventType = true; break; } typesDesc = TypeDescriptors.Get(superType); if (typesDesc != null) { TypeDescriptors.Put(underyingEventType, typesDesc); key = PropertyUtility.GetKeys(underlyingEvent, typesDesc.KeyPropertyGetters); break; } } } } else { key = PropertyUtility.GetKeys(underlyingEvent, typesDesc.KeyPropertyGetters); } } // get the state for this key value RevisionStateMerge revisionState = _statePerKey.Get(key); // Delta event and no full if ((!isBaseEventType) && (revisionState == null)) { return; // Ignore the event, its a delta and we don't currently have a full event for it } // New full event if (revisionState == null) { revisionState = new RevisionStateMerge(underlyingEvent, null, null); _statePerKey.Put(key, revisionState); // prepare revison event revisionEvent.LastBaseEvent = underlyingEvent; revisionEvent.Key = key; revisionEvent.Overlay = null; revisionEvent.IsLatest = true; // Insert into indexes for fast deletion, if there are any foreach (EventTable table in indexRepository.GetTables()) { table.Add(newData); } // post to data window revisionState.LastEvent = revisionEvent; namedWindowRootView.UpdateChildren(new EventBean[] { revisionEvent }, null); return; } // handle Update, changing revision state and event as required _updateStrategy.HandleUpdate(isBaseEventType, revisionState, revisionEvent, typesDesc); // prepare revision event revisionEvent.LastBaseEvent = revisionState.BaseEventUnderlying; revisionEvent.Overlay = revisionState.Overlays; revisionEvent.Key = key; revisionEvent.IsLatest = true; // get prior event RevisionEventBeanMerge lastEvent = revisionState.LastEvent; lastEvent.IsLatest = false; // data to post var newDataPost = new EventBean[] { revisionEvent }; var oldDataPost = new EventBean[] { lastEvent }; // Update indexes foreach (EventTable table in indexRepository.GetTables()) { table.Remove(oldDataPost); table.Add(newDataPost); } // keep reference to last event revisionState.LastEvent = revisionEvent; namedWindowRootView.UpdateChildren(newDataPost, oldDataPost); }
/// <summary>Called each time a data window posts a remove stream event, to indicate that a data window remove an event as it expired according to a specified expiration policy. </summary> /// <param name="oldData">to remove</param> /// <param name="indexRepository">the indexes to Update</param> public abstract void RemoveOldData(EventBean[] oldData, EventTableIndexRepository indexRepository);
private static NullableObject<ICollection<EventBean>> SnapshotCustomIndex( QueryGraphValue queryGraphValue, EventTableIndexRepository indexRepository, Attribute[] annotations, AgentInstanceContext agentInstanceContext, string objectName) { EventTable table = null; string indexName = null; QueryGraphValueEntryCustomOperation values = null; // find matching index var found = false; foreach (var valueDesc in queryGraphValue.Items) { if (valueDesc.Entry is QueryGraphValueEntryCustom) { var customIndex = (QueryGraphValueEntryCustom) valueDesc.Entry; foreach (var entry in indexRepository.TableIndexesRefCount) { if (entry.Key.AdvancedIndexDesc == null) { continue; } var metadata = indexRepository.EventTableIndexMetadata.Indexes.Get(entry.Key); if (metadata == null || metadata.ExplicitIndexNameIfExplicit == null) { continue; } var provision = metadata.OptionalQueryPlanIndexItem.AdvancedIndexProvisionDesc; if (provision == null) { continue; } foreach (var op in customIndex.Operations) { if (!provision.Factory.Forge.ProvidesIndexForOperation(op.Key.OperationName)) { continue; } var indexProperties = entry.Key.AdvancedIndexDesc.IndexExpressions; var expressions = op.Key.Expressions; if (Arrays.AreEqual(indexProperties, expressions)) { values = op.Value; table = entry.Value.Table; indexName = metadata.ExplicitIndexNameIfExplicit; found = true; break; } } if (found) { break; } } } if (found) { break; } } if (table == null) { return null; } // report QueryPlanReport(indexName, table, annotations, agentInstanceContext, objectName); // execute var index = (EventTableQuadTree) table; var x = Eval(values.PositionalExpressions.Get(0), agentInstanceContext, "x"); var y = Eval(values.PositionalExpressions.Get(1), agentInstanceContext, "y"); var width = Eval(values.PositionalExpressions.Get(2), agentInstanceContext, "width"); var height = Eval(values.PositionalExpressions.Get(3), agentInstanceContext, "height"); return new NullableObject<ICollection<EventBean>>( index.QueryRange(x, y, width, height)); }
public static ICollection <EventBean> Snapshot( FilterSpecCompiled optionalFilter, Attribute[] annotations, VirtualDWView virtualDataWindow, EventTableIndexRepository indexRepository, bool queryPlanLogging, ILog queryPlanLogDestination, string objectName, AgentInstanceContext agentInstanceContext) { if (optionalFilter == null || optionalFilter.Parameters.Length == 0) { if (virtualDataWindow != null) { var pair = virtualDataWindow.GetFireAndForgetDesc(Collections.GetEmptySet <string>(), Collections.GetEmptySet <string>()); return(virtualDataWindow.GetFireAndForgetData(pair.Second, new object[0], new RangeIndexLookupValue[0], annotations)); } return(null); } // Determine what straight-equals keys and which ranges are available. // Widening/Coercion is part of filter spec compile. ISet <string> keysAvailable = new HashSet <string>(); ISet <string> rangesAvailable = new HashSet <string>(); if (optionalFilter.Parameters.Length == 1) { foreach (FilterSpecParam param in optionalFilter.Parameters[0]) { if (!(param is FilterSpecParamConstant || param is FilterSpecParamRange || param is FilterSpecParamIn)) { continue; } if (param.FilterOperator == FilterOperator.EQUAL || param.FilterOperator == FilterOperator.IS || param.FilterOperator == FilterOperator.IN_LIST_OF_VALUES) { keysAvailable.Add(param.Lookupable.Expression); } else if (param.FilterOperator.IsRangeOperator() || param.FilterOperator.IsInvertedRangeOperator() || param.FilterOperator.IsComparisonOperator()) { rangesAvailable.Add(param.Lookupable.Expression); } else if (param.FilterOperator.IsRangeOperator()) { rangesAvailable.Add(param.Lookupable.Expression); } } } // Find an index that matches the needs Pair <IndexMultiKey, EventTableAndNamePair> tablePair; if (virtualDataWindow != null) { var tablePairNoName = virtualDataWindow.GetFireAndForgetDesc(keysAvailable, rangesAvailable); tablePair = new Pair <IndexMultiKey, EventTableAndNamePair>(tablePairNoName.First, new EventTableAndNamePair(tablePairNoName.Second, null)); } else { var indexHint = IndexHint.GetIndexHint(annotations); IList <IndexHintInstruction> optionalIndexHintInstructions = null; if (indexHint != null) { optionalIndexHintInstructions = indexHint.InstructionsFireAndForget; } tablePair = indexRepository.FindTable(keysAvailable, rangesAvailable, optionalIndexHintInstructions); } var hook = QueryPlanIndexHookUtil.GetHook(annotations); if (queryPlanLogging && (queryPlanLogDestination.IsInfoEnabled || hook != null)) { var prefix = "Fire-and-forget from " + objectName + " "; var indexName = tablePair != null && tablePair.Second != null ? tablePair.Second.IndexName : null; var indexText = indexName != null ? "index " + indexName + " " : "full table scan "; indexText += "(snapshot only, for join see separate query plan)"; if (tablePair == null) { queryPlanLogDestination.Info(prefix + indexText); } else { queryPlanLogDestination.Info(prefix + indexText + tablePair.Second.EventTable.ToQueryPlan()); } if (hook != null) { hook.FireAndForget(new QueryPlanIndexDescFAF( new IndexNameAndDescPair[] { new IndexNameAndDescPair(indexName, tablePair != null ? tablePair.Second.EventTable.ProviderClass.Name : null) })); } } if (tablePair == null) { return(null); // indicates table scan } // Compile key sets which contain key index lookup values var keyIndexProps = IndexedPropDesc.GetIndexProperties(tablePair.First.HashIndexedProps); var hasKeyWithInClause = false; var keyValues = new object[keyIndexProps.Length]; for (var keyIndex = 0; keyIndex < keyIndexProps.Length; keyIndex++) { foreach (var param in optionalFilter.Parameters[0]) { if (param.Lookupable.Expression.Equals(keyIndexProps[keyIndex])) { if (param.FilterOperator == FilterOperator.IN_LIST_OF_VALUES) { var keyValuesList = ((MultiKeyUntyped)param.GetFilterValue(null, agentInstanceContext)).Keys; if (keyValuesList.Length == 0) { continue; } else if (keyValuesList.Length == 1) { keyValues[keyIndex] = keyValuesList[0]; } else { keyValues[keyIndex] = keyValuesList; hasKeyWithInClause = true; } } else { keyValues[keyIndex] = param.GetFilterValue(null, agentInstanceContext); } break; } } } // Analyze ranges - these may include key lookup value (EQUALS semantics) var rangeIndexProps = IndexedPropDesc.GetIndexProperties(tablePair.First.RangeIndexedProps); RangeIndexLookupValue[] rangeValues; if (rangeIndexProps.Length > 0) { rangeValues = CompileRangeLookupValues(rangeIndexProps, optionalFilter.Parameters[0], agentInstanceContext); } else { rangeValues = new RangeIndexLookupValue[0]; } var eventTable = tablePair.Second.EventTable; var indexMultiKey = tablePair.First; // table lookup without in-clause if (!hasKeyWithInClause) { return(FafTableLookup(virtualDataWindow, indexMultiKey, eventTable, keyValues, rangeValues, annotations)); } // table lookup with in-clause: determine combinations var combinations = new object[keyIndexProps.Length][]; for (var i = 0; i < keyValues.Length; i++) { if (keyValues[i] is object[]) { combinations[i] = (object[])keyValues[i]; } else { combinations[i] = new object[] { keyValues[i] }; } } // enumerate combinations var enumeration = new CombinationEnumeration(combinations); var events = new HashSet <EventBean>(); for (; enumeration.MoveNext();) { object[] keys = enumeration.Current; var result = FafTableLookup(virtualDataWindow, indexMultiKey, eventTable, keys, rangeValues, annotations); events.AddAll(result); } return(events); }
/// <summary>Upon new events arriving into a named window (new data), and upon events being deleted via on-delete (old data), Update child views of the root view and apply to index repository as required (fast deletion). </summary> /// <param name="newData">new events</param> /// <param name="oldData">remove stream</param> /// <param name="namedWindowRootView">the root view</param> /// <param name="indexRepository">delete and select indexes</param> public abstract void OnUpdate(EventBean[] newData, EventBean[] oldData, NamedWindowRootViewInstance namedWindowRootView, EventTableIndexRepository indexRepository);
/// <summary> /// The SnapshotCustomIndex /// </summary> /// <param name="queryGraphValue">The <see cref="QueryGraphValue"/></param> /// <param name="indexRepository">The <see cref="EventTableIndexRepository"/></param> /// <param name="attributes">The <see cref="Attribute"/> array</param> /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param> /// <param name="queryPlanLogging">The <see cref="bool"/></param> /// <param name="queryPlanLogDestination">The <see cref="ILog"/></param> /// <param name="objectName">The <see cref="string"/></param> /// <returns>The <see cref="ICollection{EventBean}"/></returns> private static NullableObject <ICollection <EventBean> > SnapshotCustomIndex( QueryGraphValue queryGraphValue, EventTableIndexRepository indexRepository, Attribute[] attributes, AgentInstanceContext agentInstanceContext, bool queryPlanLogging, ILog queryPlanLogDestination, string objectName) { EventTable table = null; string indexName = null; QueryGraphValueEntryCustomOperation values = null; // find matching index var found = false; foreach (var valueDesc in queryGraphValue.Items) { if (valueDesc.Entry is QueryGraphValueEntryCustom) { var customIndex = (QueryGraphValueEntryCustom)valueDesc.Entry; foreach (var entry in indexRepository.TableIndexesRefCount) { if (entry.Key.AdvancedIndexDesc == null) { continue; } var metadata = indexRepository.EventTableIndexMetadata.Indexes.Get(entry.Key); if (metadata == null || metadata.ExplicitIndexNameIfExplicit == null) { continue; } EventAdvancedIndexProvisionDesc provision = metadata.QueryPlanIndexItem.AdvancedIndexProvisionDesc; if (provision == null) { continue; } foreach (var op in customIndex.Operations) { if (!provision.Factory.ProvidesIndexForOperation(op.Key.OperationName, op.Value.PositionalExpressions)) { continue; } if (ExprNodeUtility.DeepEquals(entry.Key.AdvancedIndexDesc.IndexedExpressions, op.Key.ExprNodes, true)) { values = op.Value; table = entry.Value.Table; indexName = metadata.ExplicitIndexNameIfExplicit; found = true; break; } } if (found) { break; } } } if (found) { break; } } if (table == null) { return(null); } // report queryPlanReport(indexName, table, attributes, agentInstanceContext, queryPlanLogging, queryPlanLogDestination, objectName); // execute EventTableQuadTree index = (EventTableQuadTree)table; var x = Eval(values.PositionalExpressions.Get(0).ExprEvaluator, agentInstanceContext, "x"); var y = Eval(values.PositionalExpressions.Get(1).ExprEvaluator, agentInstanceContext, "y"); var width = Eval(values.PositionalExpressions.Get(2).ExprEvaluator, agentInstanceContext, "width"); var height = Eval(values.PositionalExpressions.Get(3).ExprEvaluator, agentInstanceContext, "height"); var result = index.QueryRange(x, y, width, height); return(new NullableObject <ICollection <EventBean> >(result)); }
/// <summary> /// The snapshot /// </summary> /// <param name="queryGraph">The <see cref="QueryGraph"/></param> /// <param name="attributes">The <see cref="Attribute" /> array</param> /// <param name="virtualDataWindow">The <see cref="VirtualDWView"/></param> /// <param name="indexRepository">The <see cref="EventTableIndexRepository"/></param> /// <param name="queryPlanLogging">The <see cref="bool"/></param> /// <param name="queryPlanLogDestination">The <see cref="ILog"/></param> /// <param name="objectName">The <see cref="string"/></param> /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param> /// <returns>The <see cref="ICollection{EventBean}"/></returns> public static ICollection <EventBean> Snapshot( QueryGraph queryGraph, Attribute[] attributes, VirtualDWView virtualDataWindow, EventTableIndexRepository indexRepository, bool queryPlanLogging, ILog queryPlanLogDestination, string objectName, AgentInstanceContext agentInstanceContext) { var queryGraphValue = queryGraph == null ? null : queryGraph.GetGraphValue(QueryGraph.SELF_STREAM, 0); if (queryGraphValue == null || queryGraphValue.Items.IsEmpty()) { if (virtualDataWindow != null) { var pair = virtualDataWindow.GetFireAndForgetDesc(Collections.GetEmptySet <string>(), Collections.GetEmptySet <string>()); return(virtualDataWindow.GetFireAndForgetData(pair.Second, new Object[0], new RangeIndexLookupValue[0], attributes)); } return(null); } // determine custom index var customResult = SnapshotCustomIndex( queryGraphValue, indexRepository, attributes, agentInstanceContext, queryPlanLogging, queryPlanLogDestination, objectName); if (customResult != null) { return(customResult.Value); } // determine lookup based on hash-keys and ranges var keysAvailable = queryGraphValue.HashKeyProps; var keyNamesAvailable = keysAvailable.Indexed.Count == 0 ? Collections.GetEmptySet <string>() : new HashSet <string>(keysAvailable.Indexed); var rangesAvailable = queryGraphValue.RangeProps; var rangeNamesAvailable = rangesAvailable.Indexed.Count == 0 ? Collections.GetEmptySet <string>() : new HashSet <string>(rangesAvailable.Indexed); // find index that matches the needs var tablePair = FindIndex(keyNamesAvailable, rangeNamesAvailable, indexRepository, virtualDataWindow, attributes); // regular index lookup if (tablePair != null) { return(SnapshotIndex(keysAvailable, rangesAvailable, tablePair, virtualDataWindow, attributes, agentInstanceContext, queryPlanLogging, queryPlanLogDestination, objectName)); } // in-keyword lookup var inkwResult = SnapshotInKeyword(queryGraphValue, indexRepository, virtualDataWindow, attributes, agentInstanceContext, queryPlanLogging, queryPlanLogDestination, objectName); if (inkwResult != null) { return(inkwResult.Value); } QueryPlanReportTableScan(attributes, agentInstanceContext, queryPlanLogging, queryPlanLogDestination, objectName); return(null); }
private static NullableObject<ICollection<EventBean>> SnapshotInKeyword( QueryGraphValue queryGraphValue, EventTableIndexRepository indexRepository, VirtualDWView virtualDataWindow, Attribute[] annotations, AgentInstanceContext agentInstanceContext, string objectName) { var inkwSingles = queryGraphValue.InKeywordSingles; if (inkwSingles.Indexed.Length == 0) { return null; } Pair<IndexMultiKey, EventTableAndNamePair> tablePair = FindIndex( new HashSet<string>(inkwSingles.Indexed), new EmptySet<string>(), indexRepository, virtualDataWindow, annotations); if (tablePair == null) { return null; } QueryPlanReport( tablePair.Second.IndexName, tablePair.Second.EventTable, annotations, agentInstanceContext, objectName); // table lookup with in-clause: determine combinations var tableHashProps = tablePair.First.HashIndexedProps; var combinations = new object[tableHashProps.Length][]; for (var tableHashPropNum = 0; tableHashPropNum < tableHashProps.Length; tableHashPropNum++) { for (var i = 0; i < inkwSingles.Indexed.Length; i++) { if (inkwSingles.Indexed[i].Equals(tableHashProps[tableHashPropNum].IndexPropName)) { QueryGraphValueEntryInKeywordSingleIdx keysExpressions = inkwSingles.Key[i]; var values = new object[keysExpressions.KeyExprs.Length]; combinations[tableHashPropNum] = values; for (var j = 0; j < keysExpressions.KeyExprs.Length; j++) { values[j] = keysExpressions.KeyExprs[j].Evaluate(null, true, agentInstanceContext); } } } } // enumerate combinations var enumeration = new CombinationEnumeration(combinations); var events = new HashSet<EventBean>(); while (enumeration.MoveNext()) { object[] keys = enumeration.Current; var result = FafTableLookup( virtualDataWindow, tablePair.First, tablePair.Second.EventTable, keys, null, annotations, agentInstanceContext); events.AddAll(result); } return new NullableObject<ICollection<EventBean>>(events); }
/// <summary> /// The SnapshotInKeyword /// </summary> /// <param name="queryGraphValue">The <see cref="QueryGraphValue"/></param> /// <param name="indexRepository">The <see cref="EventTableIndexRepository"/></param> /// <param name="virtualDataWindow">The <see cref="VirtualDWView"/></param> /// <param name="attributes">The <see cref="Attribute" /> array</param> /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param> /// <param name="queryPlanLogging">The <see cref="bool"/></param> /// <param name="queryPlanLogDestination">The <see cref="ILog"/></param> /// <param name="objectName">The <see cref="string"/></param> /// <returns>The collection of event beans</returns> private static NullableObject <ICollection <EventBean> > SnapshotInKeyword( QueryGraphValue queryGraphValue, EventTableIndexRepository indexRepository, VirtualDWView virtualDataWindow, Attribute[] attributes, AgentInstanceContext agentInstanceContext, bool queryPlanLogging, ILog queryPlanLogDestination, string objectName) { var inkwSingles = queryGraphValue.InKeywordSingles; if (inkwSingles.Indexed.Length == 0) { return(null); } var tablePair = FindIndex( new HashSet <string>(inkwSingles.Indexed), Collections.GetEmptySet <string>(), indexRepository, virtualDataWindow, attributes); if (tablePair == null) { return(null); } queryPlanReport(tablePair.Second.IndexName, tablePair.Second.EventTable, attributes, agentInstanceContext, queryPlanLogging, queryPlanLogDestination, objectName); var evaluateParamsTrue = new EvaluateParams(null, true, agentInstanceContext); // table lookup with in-clause: determine combinations var tableHashProps = tablePair.First.HashIndexedProps; var combinations = new Object[tableHashProps.Length][]; for (var tableHashPropNum = 0; tableHashPropNum < tableHashProps.Length; tableHashPropNum++) { for (var i = 0; i < inkwSingles.Indexed.Length; i++) { if (inkwSingles.Indexed[i].Equals(tableHashProps[tableHashPropNum].IndexPropName)) { var keysExpressions = inkwSingles.Key[i]; var values = new Object[keysExpressions.KeyExprs.Count]; combinations[tableHashPropNum] = values; for (var j = 0; j < keysExpressions.KeyExprs.Count; j++) { values[j] = keysExpressions.KeyExprs[j].ExprEvaluator.Evaluate(evaluateParamsTrue); } } } } // enumerate combinations var enumeration = CombinationEnumeration.New(combinations); var events = new HashSet <EventBean>(); foreach (Object[] keys in enumeration) { var result = FafTableLookup(virtualDataWindow, tablePair.First, tablePair.Second.EventTable, keys, null, attributes); events.AddAll(result); } return(new NullableObject <ICollection <EventBean> >(events)); }
public static ICollection<EventBean> Snapshot( QueryGraph filterQueryGraph, Attribute[] annotations, VirtualDWView virtualDataWindow, EventTableIndexRepository indexRepository, string objectName, AgentInstanceContext agentInstanceContext) { var queryGraphValue = filterQueryGraph == null ? null : filterQueryGraph.GetGraphValue(QueryGraphForge.SELF_STREAM, 0); if (queryGraphValue == null || queryGraphValue.Items.IsEmpty()) { if (virtualDataWindow != null) { Pair<IndexMultiKey, EventTable> pair = VirtualDWQueryPlanUtil.GetFireAndForgetDesc( virtualDataWindow.EventType, new EmptySet<string>(), new EmptySet<string>()); return virtualDataWindow.GetFireAndForgetData( pair.Second, CollectionUtil.OBJECTARRAY_EMPTY, new RangeIndexLookupValue[0], annotations); } return null; } // determine custom index var customResult = SnapshotCustomIndex( queryGraphValue, indexRepository, annotations, agentInstanceContext, objectName); if (customResult != null) { return customResult.Value; } // determine lookup based on hash-keys and ranges var keysAvailable = queryGraphValue.HashKeyProps; ISet<string> keyNamesAvailable = keysAvailable.Indexed.Length == 0 ? (ISet<string>) new EmptySet<string>() : (ISet<string>) new HashSet<string>(keysAvailable.Indexed); var rangesAvailable = queryGraphValue.RangeProps; ISet<string> rangeNamesAvailable = rangesAvailable.Indexed.Length == 0 ? (ISet<string>) new EmptySet<string>() : (ISet<string>) new HashSet<string>(rangesAvailable.Indexed); Pair<IndexMultiKey, EventTableAndNamePair> tablePair; // find index that matches the needs tablePair = FindIndex( keyNamesAvailable, rangeNamesAvailable, indexRepository, virtualDataWindow, annotations); // regular index lookup if (tablePair != null) { return SnapshotIndex( keysAvailable, rangesAvailable, tablePair, virtualDataWindow, annotations, agentInstanceContext, objectName); } // in-keyword lookup var inkwResult = SnapshotInKeyword( queryGraphValue, indexRepository, virtualDataWindow, annotations, agentInstanceContext, objectName); if (inkwResult != null) { return inkwResult.Value; } QueryPlanReportTableScan(annotations, agentInstanceContext, objectName); return null; }
/// <summary> /// Called each time a data window posts a remove stream event, to indicate that a data window remove /// an event as it expired according to a specified expiration policy. /// </summary> /// <param name="oldData">to remove</param> /// <param name="indexRepository">the indexes to Update</param> /// <param name="agentInstanceContext">The agent instance context.</param> public abstract void RemoveOldData( EventBean[] oldData, EventTableIndexRepository indexRepository, AgentInstanceContext agentInstanceContext);
public void RemoveOldData(EventBean[] oldData, EventTableIndexRepository indexRepository) { throw new UnsupportedOperationException(); }
public void OnUpdate(EventBean[] newData, EventBean[] oldData, NamedWindowRootViewInstance namedWindowRootView, EventTableIndexRepository indexRepository) { throw new UnsupportedOperationException(); }
public virtual void RemoveOldData(EventBean[] oldData, EventTableIndexRepository indexRepository, AgentInstanceContext agentInstanceContext) { throw new UnsupportedOperationException(); }