/// <summary> /// The AddExplicitIndexOrReuse /// </summary> /// <param name="unique">The <see cref="bool"/></param> /// <param name="hashProps">The <see cref="IList{IndexedPropDesc}"/></param> /// <param name="btreeProps">The <see cref="IList{IndexedPropDesc}"/></param> /// <param name="advancedIndexProvisionDesc">The <see cref="EventAdvancedIndexProvisionDesc"/></param> /// <param name="prefilledEvents">The <see cref="IEnumerable{EventBean}"/></param> /// <param name="indexedType">The <see cref="EventType"/></param> /// <param name="indexName">The <see cref="string"/></param> /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param> /// <param name="optionalSerde">The <see cref="object"/></param> /// <returns>The <see cref="Pair{IndexMultiKey, EventTableAndNamePair}"/></returns> public Pair <IndexMultiKey, EventTableAndNamePair> AddExplicitIndexOrReuse( bool unique, IList <IndexedPropDesc> hashProps, IList <IndexedPropDesc> btreeProps, EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc, IEnumerable <EventBean> prefilledEvents, EventType indexedType, string indexName, AgentInstanceContext agentInstanceContext, object optionalSerde) { if (hashProps.IsEmpty() && btreeProps.IsEmpty() && advancedIndexProvisionDesc == null) { throw new ArgumentException("Invalid zero element list for hash and btree columns"); } // Get an existing table, if any, matching the exact requirement var indexPropKeyMatch = EventTableIndexUtil.FindExactMatchNameAndType(_tableIndexesRefCount.Keys, unique, hashProps, btreeProps, advancedIndexProvisionDesc == null ? null : advancedIndexProvisionDesc.IndexDesc); if (indexPropKeyMatch != null) { EventTableIndexRepositoryEntry refTablePair = _tableIndexesRefCount.Get(indexPropKeyMatch); return(new Pair <IndexMultiKey, EventTableAndNamePair>(indexPropKeyMatch, new EventTableAndNamePair(refTablePair.Table, refTablePair.OptionalIndexName))); } return(AddIndex(unique, hashProps, btreeProps, advancedIndexProvisionDesc, prefilledEvents, indexedType, indexName, false, agentInstanceContext, optionalSerde)); }
/// <summary> /// Ctor. /// </summary> /// <param name="indexProps"> /// - array of property names with the first dimension suplying the number of /// distinct indexes. The second dimension can be empty and indicates a full table scan. /// </param> /// <param name="optIndexCoercionTypes">- array of coercion types for each index, or null entry for no coercion required</param> /// <param name="rangeProps">range props</param> /// <param name="optRangeCoercionTypes">coercion for ranges</param> /// <param name="unique">whether index is unique on index props (not applicable to range-only)</param> /// <param name="advancedIndexProvisionDesc">advanced indexes</param> public QueryPlanIndexItem( IList <string> indexProps, IList <Type> optIndexCoercionTypes, IList <string> rangeProps, IList <Type> optRangeCoercionTypes, bool unique, EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc) { if (advancedIndexProvisionDesc == null) { if (unique && indexProps.Count == 0) { throw new ArgumentException("Invalid unique index planned without hash index props"); } if (unique && rangeProps.Count > 0) { throw new ArgumentException("Invalid unique index planned that includes range props"); } } _indexProps = indexProps; _optIndexCoercionTypes = optIndexCoercionTypes; _rangeProps = (rangeProps == null || rangeProps.Count == 0) ? null : rangeProps; _optRangeCoercionTypes = optRangeCoercionTypes; _unique = unique; _advancedIndexProvisionDesc = advancedIndexProvisionDesc; }
/// <summary> /// The AddIndex /// </summary> /// <param name="unique">The <see cref="bool"/></param> /// <param name="hashProps">The <see cref="IList{IndexedPropDesc}"/></param> /// <param name="btreeProps">The <see cref="IList{IndexedPropDesc}"/></param> /// <param name="advancedIndexProvisionDesc">The <see cref="EventAdvancedIndexProvisionDesc"/></param> /// <param name="prefilledEvents">The <see cref="IEnumerable{EventBean}"/></param> /// <param name="indexedType">The <see cref="EventType"/></param> /// <param name="indexName">The <see cref="string"/></param> /// <param name="mustCoerce">The <see cref="bool"/></param> /// <param name="agentInstanceContext">The <see cref="AgentInstanceContext"/></param> /// <param name="optionalSerde">The <see cref="object"/></param> /// <returns>The <see cref="Pair{IndexMultiKey, EventTableAndNamePair}"/></returns> private Pair <IndexMultiKey, EventTableAndNamePair> AddIndex( bool unique, IList <IndexedPropDesc> hashProps, IList <IndexedPropDesc> btreeProps, EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc, IEnumerable <EventBean> prefilledEvents, EventType indexedType, string indexName, bool mustCoerce, AgentInstanceContext agentInstanceContext, object optionalSerde) { // not resolved as full match and not resolved as unique index match, allocate var indexPropKey = new IndexMultiKey(unique, hashProps, btreeProps, advancedIndexProvisionDesc == null ? null : advancedIndexProvisionDesc.IndexDesc); var indexedPropDescs = hashProps.ToArray(); var indexProps = IndexedPropDesc.GetIndexProperties(indexedPropDescs); var indexCoercionTypes = IndexedPropDesc.GetCoercionTypes(indexedPropDescs); if (!mustCoerce) { indexCoercionTypes = null; } var rangePropDescs = btreeProps.ToArray(); var rangeProps = IndexedPropDesc.GetIndexProperties(rangePropDescs); var rangeCoercionTypes = IndexedPropDesc.GetCoercionTypes(rangePropDescs); var indexItem = new QueryPlanIndexItem(indexProps, indexCoercionTypes, rangeProps, rangeCoercionTypes, unique, advancedIndexProvisionDesc); var table = EventTableUtil.BuildIndex(agentInstanceContext, 0, indexItem, indexedType, true, unique, indexName, optionalSerde, false); // fill table since its new var events = new EventBean[1]; foreach (EventBean prefilledEvent in prefilledEvents) { events[0] = prefilledEvent; table.Add(events, agentInstanceContext); } // add table _tables.Add(table); // add index, reference counted _tableIndexesRefCount.Put(indexPropKey, new EventTableIndexRepositoryEntry(indexName, table)); return(new Pair <IndexMultiKey, EventTableAndNamePair>(indexPropKey, new EventTableAndNamePair(table, indexName))); }
public static QueryPlanIndexItem ValidateCompileExplicitIndex( string indexName, bool unique, IList <CreateIndexItem> columns, EventType eventType, StatementContext statementContext) { var hashProps = new List <IndexedPropDesc>(); var btreeProps = new List <IndexedPropDesc>(); var indexedColumns = new HashSet <string>(); EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc = null; foreach (CreateIndexItem columnDesc in columns) { string indexType = columnDesc.IndexType.ToLowerInvariant(); if ((indexType == CreateIndexType.HASH.GetNameInvariant()) || (indexType == CreateIndexType.BTREE.GetNameInvariant())) { ValidateBuiltin(columnDesc, eventType, hashProps, btreeProps, indexedColumns); } else { if (advancedIndexProvisionDesc != null) { throw new ExprValidationException("Nested advanced-type indexes are not supported"); } advancedIndexProvisionDesc = ValidateAdvanced(indexName, indexType, columnDesc, eventType, statementContext); } } if (unique && !btreeProps.IsEmpty()) { throw new ExprValidationException("Combination of unique index with btree (range) is not supported"); } if ((!btreeProps.IsEmpty() || !hashProps.IsEmpty()) && advancedIndexProvisionDesc != null) { throw new ExprValidationException("Combination of hash/btree columns an advanced-type indexes is not supported"); } return(new QueryPlanIndexItem(hashProps, btreeProps, unique, advancedIndexProvisionDesc)); }
/// <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)); }
public EventTableFactory CreateCustom(string indexName, int indexedStreamNum, EventType eventType, bool unique, EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc) { return(new EventTableFactoryCustomIndex(indexName, indexedStreamNum, eventType, unique, advancedIndexProvisionDesc)); }
public QueryPlanIndexItem(IList <IndexedPropDesc> hashProps, IList <IndexedPropDesc> btreeProps, bool unique, EventAdvancedIndexProvisionDesc advancedIndexProvisionDesc) : this(GetNames(hashProps), GetTypes(hashProps), GetNames(btreeProps), GetTypes(btreeProps), unique, advancedIndexProvisionDesc) { }