public IndexDetail( IndexMultiKey indexMultiKey, QueryPlanIndexItem queryPlanIndexItem) { this.indexMultiKey = indexMultiKey; this.queryPlanIndexItem = queryPlanIndexItem; }
private TableMetaData( string tableName, string tableModuleName, NameAccessModifier tableVisibility, string optionalContextName, NameAccessModifier? optionalContextVisibility, string optionalContextModule, EventType internalEventType, EventType publicEventType, string[] keyColumns, Type[] keyTypes, int[] keyColNums, IDictionary<string, TableMetadataColumn> columns, int numMethodAggs, IndexMultiKey keyIndexMultiKey, EventTableIndexMetadata indexMetadata) { TableName = tableName; TableModuleName = tableModuleName; TableVisibility = tableVisibility; OptionalContextName = optionalContextName; OptionalContextVisibility = optionalContextVisibility; OptionalContextModule = optionalContextModule; InternalEventType = internalEventType; PublicEventType = publicEventType; KeyColumns = keyColumns; KeyTypes = keyTypes; KeyColNums = keyColNums; Columns = columns; NumMethodAggs = numMethodAggs; KeyIndexMultiKey = keyIndexMultiKey; IndexMetadata = indexMetadata; }
public void AddIndexReference( IndexMultiKey indexMultiKey, string deploymentId) { var entry = Indexes.Get(indexMultiKey); entry?.AddReferringDeployment(deploymentId); }
private EventTableIndexMetadataEntry GetIndexEntry(EPServiceProvider epService, bool namedWindow, string name) { var descOne = new IndexedPropDesc("col0", typeof(string)); var index = new IndexMultiKey(false, Collections.List(descOne), Collections. GetEmptyList<IndexedPropDesc>(), null); var meta = GetIndexMetaRepo(epService, namedWindow, name); return meta.Indexes.Get(index); }
public void AddIndexExplicit( bool isPrimary, IndexMultiKey indexMultiKey, string explicitIndexName, string explicitIndexModuleName, QueryPlanIndexItem explicitIndexDesc, string deploymentId) { if (GetIndexByName(explicitIndexName) != null) { throw new ExprValidationException("An index by name '" + explicitIndexName + "' already exists"); } if (Indexes.ContainsKey(indexMultiKey)) { throw new ExprValidationException("An index for the same columns already exists"); } var entry = new EventTableIndexMetadataEntry( explicitIndexName, explicitIndexModuleName, isPrimary, explicitIndexDesc, explicitIndexName, explicitIndexModuleName, deploymentId); entry.AddReferringDeployment(deploymentId); Indexes.Put(indexMultiKey, entry); }
public Pair <IndexMultiKey, EventTable> GetFireAndForgetDesc( ISet <String> keysAvailable, ISet <String> rangesAvailable) { IList <VirtualDataWindowLookupFieldDesc> hashFields = new List <VirtualDataWindowLookupFieldDesc>(); IList <IndexedPropDesc> hashIndexedFields = new List <IndexedPropDesc>(); foreach (var hashprop in keysAvailable) { hashFields.Add(new VirtualDataWindowLookupFieldDesc(hashprop, VirtualDataWindowLookupOp.EQUALS, null)); hashIndexedFields.Add(new IndexedPropDesc(hashprop, _eventType.GetPropertyType(hashprop))); } IList <VirtualDataWindowLookupFieldDesc> btreeFields = new List <VirtualDataWindowLookupFieldDesc>(); IList <IndexedPropDesc> btreeIndexedFields = new List <IndexedPropDesc>(); foreach (var btreeprop in rangesAvailable) { btreeFields.Add(new VirtualDataWindowLookupFieldDesc(btreeprop, null, null)); btreeIndexedFields.Add(new IndexedPropDesc(btreeprop, _eventType.GetPropertyType(btreeprop))); } var noopTable = new VirtualDWEventTable(false, hashFields, btreeFields, TABLE_ORGANIZATION); var imk = new IndexMultiKey(false, hashIndexedFields, btreeIndexedFields, null); return(new Pair <IndexMultiKey, EventTable>(imk, noopTable)); }
public void AddIndex( string indexName, string indexModuleName, IndexMultiKey imk, QueryPlanIndexItem optionalQueryPlanIndexItem) { IndexMetadata.AddIndexExplicit(false, imk, indexName, indexModuleName, optionalQueryPlanIndexItem, ""); }
private static Pair<IndexMultiKey, EventTableIndexEntryBase> GetPair<T>( IDictionary<IndexMultiKey, T> tableIndexesRefCount, IndexMultiKey indexMultiKey) where T : EventTableIndexEntryBase { EventTableIndexEntryBase indexFound = tableIndexesRefCount.Get(indexMultiKey); return new Pair<IndexMultiKey, EventTableIndexEntryBase>(indexMultiKey, indexFound); }
private EventTableIndexMetadataEntry GetIndexEntry(bool namedWindow) { var descOne = new IndexedPropDesc("col0", typeof(string)); var index = new IndexMultiKey(false, Collections.SingletonList(descOne), Collections.GetEmptyList <IndexedPropDesc>()); var meta = GetIndexMetaRepo(namedWindow); return(meta.Indexes.Get(index)); }
public SubordinateQueryIndexPlan( QueryPlanIndexItemForge indexItem, IndexMultiKey indexPropKey, IList<StmtClassForgeableFactory> multiKeyForgeables) { IndexItem = indexItem; IndexPropKey = indexPropKey; MultiKeyForgeables = multiKeyForgeables; }
public void RemoveIndexReferencesStmtMayRemoveIndex(IndexMultiKey imk, string finalStatementName) { bool last = _eventTableIndexMetadataRepo.RemoveIndexReference(imk, finalStatementName); if (last) { _eventTableIndexMetadataRepo.RemoveIndex(imk); RemoveAllInstanceIndexes(imk); } }
public SubordinateQueryIndexDesc( IndexKeyInfo optionalIndexKeyInfo, string indexName, IndexMultiKey indexMultiKey, QueryPlanIndexItem queryPlanIndexItem) { OptionalIndexKeyInfo = optionalIndexKeyInfo; IndexName = indexName; IndexMultiKey = indexMultiKey; QueryPlanIndexItem = queryPlanIndexItem; }
/// <summary> /// Given an index with a defined set of hash(equals) and range(btree) props and uniqueness flag, /// and given a list of indexable properties and accessAccessors for both hash and range, /// return the ordered keys and coercion information. /// </summary> /// <param name="indexMultiKey">index definition</param> /// <param name="hashIndexPropsProvided">hash indexable properties</param> /// <param name="hashJoinedProps">keys for hash indexable properties</param> /// <param name="rangeIndexPropsProvided">btree indexable properties</param> /// <param name="rangeJoinedProps">keys for btree indexable properties</param> /// <returns>ordered set of key information</returns> public static IndexKeyInfo CompileIndexKeyInfo( IndexMultiKey indexMultiKey, string[] hashIndexPropsProvided, SubordPropHashKeyForge[] hashJoinedProps, string[] rangeIndexPropsProvided, SubordPropRangeKeyForge[] rangeJoinedProps) { // map the order of indexed columns (key) to the key information available var indexedKeyProps = indexMultiKey.HashIndexedProps; var isCoerceHash = false; var hashesDesc = new SubordPropHashKeyForge[indexedKeyProps.Length]; var hashPropCoercionTypes = new Type[indexedKeyProps.Length]; for (var i = 0; i < indexedKeyProps.Length; i++) { var indexField = indexedKeyProps[i].IndexPropName; var index = CollectionUtil.FindItem(hashIndexPropsProvided, indexField); if (index == -1) { throw new IllegalStateException("Could not find index property for lookup '" + indexedKeyProps[i]); } hashesDesc[i] = hashJoinedProps[index]; hashPropCoercionTypes[i] = indexedKeyProps[i].CoercionType; var keyForge = hashesDesc[i].HashKey.KeyExpr.Forge; if (indexedKeyProps[i].CoercionType.GetBoxedType() != keyForge.EvaluationType.GetBoxedType()) { // we allow null evaluator isCoerceHash = true; } } // map the order of range columns (range) to the range information available indexedKeyProps = indexMultiKey.RangeIndexedProps; var rangesDesc = new SubordPropRangeKeyForge[indexedKeyProps.Length]; var rangePropCoercionTypes = new Type[indexedKeyProps.Length]; var isCoerceRange = false; for (var i = 0; i < indexedKeyProps.Length; i++) { var indexField = indexedKeyProps[i].IndexPropName; var index = CollectionUtil.FindItem(rangeIndexPropsProvided, indexField); if (index == -1) { throw new IllegalStateException("Could not find range property for lookup '" + indexedKeyProps[i]); } rangesDesc[i] = rangeJoinedProps[index]; rangePropCoercionTypes[i] = rangeJoinedProps[index].CoercionType; if (indexedKeyProps[i].CoercionType.GetBoxedType() != rangePropCoercionTypes[i].GetBoxedType()) { isCoerceRange = true; } } return new IndexKeyInfo( hashesDesc, new CoercionDesc(isCoerceHash, hashPropCoercionTypes), rangesDesc, new CoercionDesc(isCoerceRange, rangePropCoercionTypes)); }
public static IndexMultiKey FindExactMatchNameAndType( ICollection<IndexMultiKey> indexMultiKeys, IndexMultiKey proposed) { foreach (var existing in indexMultiKeys) { if (existing.Equals(proposed)) { return existing; } } return null; }
public SubordinateQueryIndexDescForge( IndexKeyInfo optionalIndexKeyInfo, string indexName, string indexModuleName, IndexMultiKey indexMultiKey, QueryPlanIndexItemForge optionalQueryPlanIndexItem) { OptionalIndexKeyInfo = optionalIndexKeyInfo; IndexName = indexName; IndexModuleName = indexModuleName; IndexMultiKey = indexMultiKey; OptionalQueryPlanIndexItem = optionalQueryPlanIndexItem; }
private static EventTableIndexMetadataEntry GetIndexEntry( RegressionEnvironment env, bool namedWindow, string name) { var descOne = new IndexedPropDesc("col0", typeof(string)); var index = new IndexMultiKey( false, Arrays.AsList(descOne), Collections.GetEmptyList<IndexedPropDesc>(), null); var meta = GetIndexMetaRepo(env, namedWindow, name); return meta.Indexes.Get(index); }
public bool RemoveIndexReference( IndexMultiKey index, string referringDeploymentId) { if (index == null) { throw new ArgumentException("Null index multikey"); } var entry = Indexes.Get(index); if (entry == null) { return false; } return entry.RemoveReferringStatement(referringDeploymentId); }
/// <summary> /// The FafTableLookup /// </summary> /// <param name="virtualDataWindow">The <see cref="VirtualDWView"/></param> /// <param name="indexMultiKey">The <see cref="IndexMultiKey"/></param> /// <param name="eventTable">The <see cref="EventTable"/></param> /// <param name="keyValues">The <see cref="Object"/> array</param> /// <param name="rangeValues">The <see cref="RangeIndexLookupValue" /> array</param> /// <param name="attributes">The <see cref="Attribute" /> array</param> /// <returns>The <see cref="ICollection{EventBean}"/></returns> private static ICollection <EventBean> FafTableLookup( VirtualDWView virtualDataWindow, IndexMultiKey indexMultiKey, EventTable eventTable, Object[] keyValues, RangeIndexLookupValue[] rangeValues, Attribute[] attributes) { if (virtualDataWindow != null) { return(virtualDataWindow.GetFireAndForgetData(eventTable, keyValues, rangeValues, attributes)); } ISet <EventBean> result; if (indexMultiKey.HashIndexedProps.Length > 0 && indexMultiKey.RangeIndexedProps.Length == 0) { if (indexMultiKey.HashIndexedProps.Length == 1) { var table = (PropertyIndexedEventTableSingle)eventTable; result = table.Lookup(keyValues[0]); } else { var table = (PropertyIndexedEventTable)eventTable; result = table.Lookup(keyValues); } } else if (indexMultiKey.HashIndexedProps.Length == 0 && indexMultiKey.RangeIndexedProps.Length == 1) { var table = (PropertySortedEventTable)eventTable; result = table.LookupConstants(rangeValues[0]); } else { var table = (PropertyCompositeEventTable)eventTable; var rangeCoercion = table.OptRangeCoercedTypes; var lookup = CompositeIndexLookupFactory.Make(keyValues, rangeValues, rangeCoercion); result = new HashSet <EventBean>(); lookup.Lookup(table.MapIndex, result, table.PostProcessor); } if (result != null) { return(result); } return(Collections.GetEmptyList <EventBean>()); }
public Pair <IndexMultiKey, EventTable> GetSubordinateQueryDesc( bool unique, IList <IndexedPropDesc> hashedProps, IList <IndexedPropDesc> btreeProps) { var hashFields = hashedProps .Select(hashprop => new VirtualDataWindowLookupFieldDesc(hashprop.IndexPropName, VirtualDataWindowLookupOp.EQUALS, hashprop.CoercionType)) .ToList(); var btreeFields = btreeProps .Select(btreeprop => new VirtualDataWindowLookupFieldDesc(btreeprop.IndexPropName, null, btreeprop.CoercionType)) .ToList(); var eventTable = new VirtualDWEventTable( unique, hashFields, btreeFields, TABLE_ORGANIZATION); var imk = new IndexMultiKey(unique, hashedProps, btreeProps, null); return(new Pair <IndexMultiKey, EventTable>(imk, eventTable)); }
public StatementAgentInstanceFactoryCreateIndexForge( EventType eventType, string indexName, string indexModuleName, QueryPlanIndexItemForge explicitIndexDesc, IndexMultiKey imk, NamedWindowMetaData namedWindow, TableMetaData table) { this.eventType = eventType; this.indexName = indexName; this.indexModuleName = indexModuleName; this.explicitIndexDesc = explicitIndexDesc; this.imk = imk; this.namedWindow = namedWindow; this.table = table; }
private static bool DetermineUpdatesIndex( string updatedProperty, IndexMultiKey key) { foreach (var prop in key.HashIndexedProps) { if (prop.IndexPropName.Equals(updatedProperty)) { return true; } } foreach (var prop in key.RangeIndexedProps) { if (prop.IndexPropName.Equals(updatedProperty)) { return true; } } return false; }
private static bool DetermineUpdatesIndex(EventBeanUpdateItem updateItem, IndexMultiKey key) { foreach (IndexedPropDesc prop in key.HashIndexedProps) { if (prop.IndexPropName.Equals(updateItem.OptionalPropertyName)) { return(true); } } foreach (IndexedPropDesc prop in key.RangeIndexedProps) { if (prop.IndexPropName.Equals(updateItem.OptionalPropertyName)) { return(true); } } return(false); }
public TableStateInstanceGroupedImpl( TableMetadata tableMetadata, AgentInstanceContext agentInstanceContext, IReaderWriterLockManager rwLockManager) : base(tableMetadata, agentInstanceContext, rwLockManager) { IList <EventPropertyGetter> indexGetters = new List <EventPropertyGetter>(); IList <string> keyNames = new List <string>(); foreach (var entry in tableMetadata.TableColumns) { if (entry.Value.IsKey) { keyNames.Add(entry.Key); indexGetters.Add(tableMetadata.InternalEventType.GetGetter(entry.Key)); } } var tableName = "primary-" + tableMetadata.TableName; var organization = new EventTableOrganization(tableName, true, false, 0, Collections.GetEmptyList <string>(), EventTableOrganizationType.HASH); EventTable table; if (indexGetters.Count == 1) { var tableMap = new TransformDictionary <object, EventBean, object, ObjectArrayBackedEventBean>( _rows, k => k, v => v, k => k, v => v as ObjectArrayBackedEventBean); table = new PropertyIndexedEventTableSingleUnique(indexGetters[0], organization, tableMap); } else { var getters = indexGetters.ToArrayOrNull(); var tableMap = new TransformDictionary <MultiKeyUntyped, EventBean, object, ObjectArrayBackedEventBean>( _rows, k => k as MultiKeyUntyped, v => v, k => k, v => v as ObjectArrayBackedEventBean); table = new PropertyIndexedEventTableUnique(getters, organization, tableMap); } var pair = TableServiceUtil.GetIndexMultikeyForKeys(tableMetadata.TableColumns, tableMetadata.InternalEventType); _primaryIndexKey = pair.Second; _indexRepository.AddIndex(_primaryIndexKey, new EventTableIndexRepositoryEntry(tableName, table)); }
private static bool IsExactMatch( IndexMultiKey existing, bool unique, IList<IndexedPropDesc> hashProps, IList<IndexedPropDesc> btreeProps) { if (existing.IsUnique != unique) { return false; } if (!IndexedPropDesc.Compare(existing.HashIndexedProps, hashProps)) { return false; } if (!IndexedPropDesc.Compare(existing.RangeIndexedProps, btreeProps)) { return false; } return true; }
public void RemoveAllInstanceIndexes(IndexMultiKey index) { if (_contextName == null) { StatementResourceHolder holder = _statementResourceService.Unpartitioned; if (holder != null && holder.NamedWindowProcessorInstance != null) { holder.NamedWindowProcessorInstance.RemoveIndex(index); } } else { foreach (var entry in _statementResourceService.ResourcesPartitioned) { if (entry.Value.NamedWindowProcessorInstance != null) { entry.Value.NamedWindowProcessorInstance.RemoveIndex(index); } } } }
public CodegenExpression Make( CodegenMethodScope parent, SAIFFInitializeSymbol symbols, CodegenClassScope classScope) { var method = parent.MakeChild(typeof(SubordinateQueryIndexDesc), GetType(), classScope); method.Block .DeclareVar<IndexMultiKey>("indexMultiKey", IndexMultiKey.Make(method, classScope)) .DeclareVar<QueryPlanIndexItem>( "queryPlanIndexItem", OptionalQueryPlanIndexItem == null ? ConstantNull() : OptionalQueryPlanIndexItem.Make(method, classScope)); method.Block.MethodReturn( NewInstance<SubordinateQueryIndexDesc>( ConstantNull(), Constant(IndexName), Ref("indexMultiKey"), Ref("queryPlanIndexItem"))); return LocalMethod(method); }
private static SubordinateQueryIndexPlan PlanIndex( bool unique, IList<IndexedPropDesc> hashProps, IList<IndexedPropDesc> btreeProps, EventType eventTypeIndexed, StatementRawInfo raw, StatementCompileTimeServices services) { // not resolved as full match and not resolved as unique index match, allocate var indexPropKey = new IndexMultiKey(unique, hashProps, btreeProps, null); var indexedPropDescs = hashProps.ToArray(); var indexProps = IndexedPropDesc.GetIndexProperties(indexedPropDescs); var indexCoercionTypes = IndexedPropDesc.GetCoercionTypes(indexedPropDescs); var rangePropDescs = btreeProps.ToArray(); var rangeProps = IndexedPropDesc.GetIndexProperties(rangePropDescs); var rangeCoercionTypes = IndexedPropDesc.GetCoercionTypes(rangePropDescs); var indexItem = new QueryPlanIndexItemForge( indexProps, indexCoercionTypes, rangeProps, rangeCoercionTypes, unique, null, eventTypeIndexed); var multiKeyPlan = MultiKeyPlanner.PlanMultiKey(indexCoercionTypes, true, raw, services.SerdeResolver); indexItem.HashMultiKeyClasses = multiKeyPlan.ClassRef; var rangeSerdes = new DataInputOutputSerdeForge[rangeCoercionTypes.Length]; for (var i = 0; i < rangeCoercionTypes.Length; i++) { rangeSerdes[i] = services.SerdeResolver.SerdeForIndexBtree(rangeCoercionTypes[i], raw); } indexItem.RangeSerdes = rangeSerdes; return new SubordinateQueryIndexPlan(indexItem, indexPropKey, multiKeyPlan.MultiKeyForgeables); }
public void ValidateAddIndexAssignUpdateStrategies( string createIndexStatementName, IndexMultiKey imk, string explicitIndexName, QueryPlanIndexItem explicitIndexDesc) { // add index - for now _eventTableIndexMetadataRepo.AddIndexExplicit(false, imk, explicitIndexName, explicitIndexDesc, createIndexStatementName); // validate strategies, rollback if required foreach (var stmtEntry in _stmtNameToUpdateStrategyReceivers) { foreach (var strategyReceiver in stmtEntry.Value) { try { TableUpdateStrategyFactory.ValidateGetTableUpdateStrategy( this, strategyReceiver.UpdateHelper, strategyReceiver.IsOnMerge); } catch (ExprValidationException ex) { _eventTableIndexMetadataRepo.RemoveIndex(imk); throw new ExprValidationException( "Failed to validate statement '" + stmtEntry.Key + "' as a recipient of the proposed index: " + ex.Message); } } } // assign new strategies foreach (var stmtEntry in _stmtNameToUpdateStrategyReceivers) { foreach (var strategyReceiver in stmtEntry.Value) { var strategy = TableUpdateStrategyFactory.ValidateGetTableUpdateStrategy( this, strategyReceiver.UpdateHelper, strategyReceiver.IsOnMerge); strategyReceiver.Receiver.Update(strategy); } } }
private static bool IndexMatchesProvided( IndexMultiKey indexDesc, IList<IndexedPropDesc> hashPropsProvided, IList<IndexedPropDesc> rangePropsProvided) { var hashPropIndexedList = indexDesc.HashIndexedProps; foreach (var hashPropIndexed in hashPropIndexedList) { var foundHashProp = IndexHashIsProvided(hashPropIndexed, hashPropsProvided); if (!foundHashProp) { return false; } } var rangePropIndexedList = indexDesc.RangeIndexedProps; foreach (var rangePropIndexed in rangePropIndexedList) { var foundRangeProp = IndexHashIsProvided(rangePropIndexed, rangePropsProvided); if (!foundRangeProp) { return false; } } return true; }
private static ICollection<EventBean> FafTableLookup( VirtualDWView virtualDataWindow, IndexMultiKey indexMultiKey, EventTable eventTable, object[] keyValues, RangeIndexLookupValue[] rangeValues, Attribute[] annotations, AgentInstanceContext agentInstanceContext) { if (virtualDataWindow != null) { return virtualDataWindow.GetFireAndForgetData(eventTable, keyValues, rangeValues, annotations); } ISet<EventBean> result; if (indexMultiKey.HashIndexedProps.Length > 0 && indexMultiKey.RangeIndexedProps.Length == 0) { var table = (PropertyHashedEventTable) eventTable; var lookupKey = table.MultiKeyTransform.From(keyValues); result = table.Lookup(lookupKey); } else if (indexMultiKey.HashIndexedProps.Length == 0 && indexMultiKey.RangeIndexedProps.Length == 1) { var table = (PropertySortedEventTable) eventTable; result = table.LookupConstants(rangeValues[0]); } else { var table = (PropertyCompositeEventTable) eventTable; var rangeCoercion = table.OptRangeCoercedTypes; var lookup = CompositeIndexLookupFactory.Make(keyValues, table.MultiKeyTransform, rangeValues, rangeCoercion); result = new HashSet<EventBean>(); lookup.Lookup(table.Index, result, table.PostProcessor); } if (result != null) { return result; } return EmptyList<EventBean>.Instance; }