Ejemplo n.º 1
0
        private static Pair <QueryPlanIndexItem, IndexMultiKey> PlanIndex(bool unique,
                                                                          IList <IndexedPropDesc> hashProps,
                                                                          IList <IndexedPropDesc> btreeProps,
                                                                          bool mustCoerce)
        {
            // not resolved as full match and not resolved as unique index match, allocate
            var indexPropKey = new IndexMultiKey(unique, hashProps, btreeProps);

            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);

            return(new Pair <QueryPlanIndexItem, IndexMultiKey>(indexItem, indexPropKey));
        }
Ejemplo n.º 2
0
        private static bool IsExactMatch(IndexMultiKey existing, bool unique, IList <IndexedPropDesc> hashProps, IList <IndexedPropDesc> btreeProps)
        {
            if (existing.IsUnique != unique)
            {
                return(false);
            }
            var keyPropCompare = IndexedPropDesc.Compare(existing.HashIndexedProps, hashProps);

            return(keyPropCompare && IndexedPropDesc.Compare(existing.RangeIndexedProps, btreeProps));
        }
Ejemplo n.º 3
0
        public String ToQueryPlan()
        {
            StringWriter writer = new StringWriter();

            writer.Write(IsUnique ? "unique " : "non-unique ");
            writer.Write("hash={");
            IndexedPropDesc.ToQueryPlan(writer, HashIndexedProps);
            writer.Write("} btree={");
            IndexedPropDesc.ToQueryPlan(writer, RangeIndexedProps);
            writer.Write("}");
            return(writer.ToString());
        }
Ejemplo n.º 4
0
        private static void ValidateBuiltin(
            CreateIndexItem columnDesc,
            EventType eventType,
            IList <IndexedPropDesc> hashProps,
            IList <IndexedPropDesc> btreeProps,
            ISet <string> indexedColumns)
        {
            if (columnDesc.Expressions.IsEmpty())
            {
                throw new ExprValidationException("Invalid empty list of index expressions");
            }
            if (columnDesc.Expressions.Count > 1)
            {
                throw new ExprValidationException("Invalid multiple index expressions for index type '" + columnDesc.IndexType + "'");
            }
            ExprNode expression = columnDesc.Expressions[0];

            if (!(expression is ExprIdentNode))
            {
                throw new ExprValidationException("Invalid index expression '" + expression.ToExpressionStringMinPrecedenceSafe() + "'");
            }
            ExprIdentNode identNode = (ExprIdentNode)expression;

            if (identNode.FullUnresolvedName.Contains("."))
            {
                throw new ExprValidationException("Invalid index expression '" + expression.ToExpressionStringMinPrecedenceSafe() + "'");
            }

            string columnName = identNode.FullUnresolvedName;
            Type   type       = eventType.GetPropertyType(columnName).GetBoxedType();

            if (type == null)
            {
                throw new ExprValidationException("Property named '" + columnName + "' not found");
            }
            if (!indexedColumns.Add(columnName))
            {
                throw new ExprValidationException("Property named '" + columnName + "' has been declared more then once");
            }

            var    desc      = new IndexedPropDesc(columnName, type);
            string indexType = columnDesc.IndexType;

            if (string.Equals(indexType, CreateIndexType.HASH.ToString(), StringComparison.InvariantCultureIgnoreCase))
            {
                hashProps.Add(desc);
            }
            else
            {
                btreeProps.Add(desc);
            }
        }
Ejemplo n.º 5
0
 public int Compare(IndexMultiKey o1, IndexMultiKey o2)
 {
     string[] indexedProps1 = IndexedPropDesc.GetIndexProperties(o1.HashIndexedProps);
     string[] indexedProps2 = IndexedPropDesc.GetIndexProperties(o2.HashIndexedProps);
     if (indexedProps1.Length > indexedProps2.Length)
     {
         return(1);  // sort desc by count columns
     }
     if (indexedProps1.Length == indexedProps2.Length)
     {
         return(0);
     }
     return(-1);
 }
        /// <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)));
        }
Ejemplo n.º 7
0
 private static bool IndexHashIsProvided(IndexedPropDesc hashPropIndexed, IList <IndexedPropDesc> hashPropsProvided)
 {
     foreach (var hashPropProvided in hashPropsProvided)
     {
         var nameMatch = hashPropProvided.IndexPropName.Equals(hashPropIndexed.IndexPropName);
         var typeMatch = true;
         if (hashPropProvided.CoercionType != null && !TypeHelper.IsSubclassOrImplementsInterface(hashPropProvided.CoercionType.GetBoxedType(), hashPropIndexed.CoercionType.GetBoxedType()))
         {
             typeMatch = false;
         }
         if (nameMatch && typeMatch)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
        public static EventTableCreateIndexDesc ValidateCompileExplicitIndex(bool unique, IList <CreateIndexItem> columns, EventType eventType)
        {
            IList <IndexedPropDesc> hashProps  = new List <IndexedPropDesc>();
            IList <IndexedPropDesc> btreeProps = new List <IndexedPropDesc>();

            ISet <string> indexed = new HashSet <string>();

            foreach (var columnDesc in columns)
            {
                var columnName = columnDesc.Name;

                var type = eventType.GetPropertyType(columnName).GetBoxedType();
                if (type == null)
                {
                    throw new ExprValidationException("Property named '" + columnName + "' not found");
                }
                if (!indexed.Add(columnName))
                {
                    throw new ExprValidationException("Property named '" + columnName + "' has been declared more then once");
                }

                var desc = new IndexedPropDesc(columnName, type);
                if (columnDesc.Type == CreateIndexType.HASH)
                {
                    hashProps.Add(desc);
                }
                else
                {
                    btreeProps.Add(desc);
                }
            }

            if (unique && !btreeProps.IsEmpty())
            {
                throw new ExprValidationException("Combination of unique index with btree (range) is not supported");
            }
            return(new EventTableCreateIndexDesc(hashProps, btreeProps, unique));
        }
Ejemplo n.º 9
0
 private static bool IsExactMatch(
     IndexMultiKey existing, bool unique,
     IList <IndexedPropDesc> hashProps,
     IList <IndexedPropDesc> btreeProps,
     AdvancedIndexDesc advancedIndexDesc)
 {
     if (existing.IsUnique != unique)
     {
         return(false);
     }
     if (!IndexedPropDesc.Compare(existing.HashIndexedProps, hashProps))
     {
         return(false);
     }
     if (!IndexedPropDesc.Compare(existing.RangeIndexedProps, btreeProps))
     {
         return(false);
     }
     if (existing.AdvancedIndexDesc == null)
     {
         return(advancedIndexDesc == null);
     }
     return(advancedIndexDesc != null && existing.AdvancedIndexDesc.EqualsAdvancedIndex(advancedIndexDesc));
 }