Пример #1
0
        public void QueryMembers()
        {
            IDataReader reader = null;

            try
            {
                Attribute.Clear();
                AttributeMember all = new AttributeMember(Attribute.Definition.Dimension.AttributeAllMemberName);
                all.IsTotal = true;
                Attribute.Levels[0].Members.Add(all);

                AttributeLevel level = (AttributeLevel)Attribute.Levels[1];
                reader = ExecuteReader(GetSql());
                while (reader.Read())
                {
                    AttributeMember m = new AttributeMember(reader[0], reader.GetString(1));
                    all.Children.Add(m);
                    level.Members.Add(m);
                }
            }
            finally
            {
                CloseReader(reader);
            }
        }
Пример #2
0
        // Generates a pseudo Measures attribute
        // Each members represent a measure by using the LinkedMeasure property
        private Attribute GetMeasuresAttribute()
        {
            Attribute measures = new Attribute(null, "Measures");

            Measure[] ms = Measures;
            foreach (Measure m in ms)
            {
                AttributeMember mm = new AttributeMember(m.Name);
                mm.LinkedMeasure = m;
                measures.Levels[0].Members.Add(mm);
            }
            return(measures);
        }
Пример #3
0
        public void QueryMembers()
        {
            IDataReader reader = null;

            try
            {
                Attribute first = Hierarchy.Dimension.Attributes[Hierarchy.Definition.Levels[0].Name];
                Hierarchy.Clear();
                HierarchyMember all = new HierarchyMember((AttributeMember)first.AllMember);
                Hierarchy.Levels[0].Members.Add(all);

                Attribute[]       attrs   = Hierarchy.Definition.Levels.Select(_ => Hierarchy.Dimension.Attributes[_.Attribute.Name]).ToArray();
                int               attrLen = attrs.Length;
                HierarchyMember[] last    = new HierarchyMember[attrLen];

                reader = ExecuteReader(GetSql());
                while (reader.Read())
                {
                    for (int i = 0; i <= attrLen - 1; i++)
                    {
                        AttributeMember curr = (AttributeMember)attrs[i].Levels[1].Members[reader[i]];
                        if (curr != null && (last[i] == null || last[i].Origin != curr))
                        {
                            HierarchyMember hm = new HierarchyMember(curr);
                            last[i] = hm;
                            if (i == 0)
                            {
                                all.Children.Add(hm);
                            }
                            else
                            {
                                last[i - 1].Children.Add(hm);
                            }
                            Hierarchy.Levels[i + 1].Members.Add(hm);
                        }
                    }
                }
            }
            finally
            {
                CloseReader(reader);
            }
        }
Пример #4
0
 public HierarchyMember(AttributeMember member)
 {
     Origin = member;
 }
Пример #5
0
        public JoinedMembers JoinMembers(Aggregation agg, bool shouldCleanUp = false)
        {
            if (agg == null && Attributes.Length == 0)
            {
                if (Measures.Length > 0)
                {
                    Measure[]     ms     = Measures;
                    JoinedMembers result = new JoinedMembers();
                    foreach (Measure m in ms)
                    {
                        AttributeMember mm = new AttributeMember(m.Name);
                        mm.LinkedMeasure = m;
                        result.Add(new AttributeMember[] { mm });
                    }
                    return(result);
                }
                else
                {
                    return(JoinedMembers.Empty);
                }
            }
            else
            {
                RearrangedSets sets = Rearrange();
                if (shouldCleanUp)
                {
                    sets.CleanUp();
                }

                // return empty if no sets left after cleaned up
                if (sets.Count == 0)
                {
                    return(JoinedMembers.Empty);
                }

                int   depth    = sets.Count;
                int[] indices  = new int[depth];
                int[] ceilings = new int[depth];
                List <List <AttributeMember> > list = new List <List <AttributeMember> >();
                for (int i = 0; i < depth; i++)
                {
                    indices[i]  = 0;
                    ceilings[i] = sets[i].Count;
                }

                Join(0);

                void Join(int level)
                {
                    for (int i = 0; i < ceilings[level]; i++)
                    {
                        indices[level] = i;
                        if (level == depth - 1)
                        {
                            List <AttributeMember> members = new List <AttributeMember>();
                            for (int j = 0; j < depth; j++)
                            {
                                IQueryMember member = sets[j][indices[j]];
                                members.Add(member is AttributeMember ? (AttributeMember)member : ((HierarchyMember)member).Origin);
                            }

                            if (agg.GetIndex(members) > -1)
                            {
                                list.Add(members);
                            }
                        }
                        else
                        {
                            Join(level + 1);
                        }
                    }
                }

                JoinedMembers result = new JoinedMembers();
                list.ForEach(_ => result.Add(_.ToArray()));
                return(result);
            }
        }
Пример #6
0
 public IndexTreeNode(AttributeMember member, int index)
 {
     Member = member;
     Index  = index;
 }
Пример #7
0
 public IndexTreeNode(AttributeMember member) : this(member, 0)
 {
 }
Пример #8
0
        public Aggregation Query()
        {
            DateTime t = DateTime.Now;

            int         attrLen = Attributes.Length;
            int         ceiling = attrLen - 1;
            int         mLen    = Measures.Length;
            Aggregation agg     = new Aggregation(Attributes, Measures);

            IDataReader reader = null;

            try
            {
                int rowIndex = 0;
                reader = ExecuteReader(GetSql(null));
                while (reader.Read())
                {
                    AttributeMember[] tuple = new AttributeMember[attrLen];
                    for (int i = 0; i < attrLen; i++)
                    {
                        tuple[i] = (AttributeMember)Attributes[i].Levels[1].Members[reader[i]];
                    }
                    if (rowIndex > 0)
                    {
                        AddTotals(tuple, ref rowIndex);
                    }
                    agg.Tuples.Add(tuple);

                    int index = attrLen;
                    for (int i = 0; i < mLen; i++)
                    {
                        agg.Values[i].Values.Add(reader[index]);
                        index++;
                    }
                    rowIndex++;
                }
                AddTotals(new AttributeMember[attrLen], ref rowIndex);
                BuildIndexTree();

                agg.QueryTime = (DateTime.Now - t).TotalMilliseconds;
                return(agg);
            }
            finally
            {
                CloseReader(reader);
            }

            void AddTotals(AttributeMember[] tuple, ref int ri)
            {
                AttributeMember[] last = agg.Tuples.Last();
                for (int i = tuple.Length - 2; i >= 0; i--)
                {
                    if (tuple[i] != last[i])
                    {
                        AttributeMember[] total = (AttributeMember[])last.Clone();
                        for (int j = i + 1; j < attrLen; j++)
                        {
                            Attribute attr = last[j].Attribute;
                            //Member tm = new Member(attr.Dimension.AttributeAllMemberName);
                            //tm.IsTotal = true;
                            //tm.Attribute = attr;
                            total[j] = (AttributeMember)attr.AllMember;
                        }
                        agg.Tuples.Add(total);
                        agg.TotalIndices.Add(ri);

                        int index = attrLen;
                        for (int j = 0; j < mLen; j++)
                        {
                            agg.Values[j].Values.Add(0);
                            index++;
                        }
                        ri++;
                    }
                }
            }

            void BuildIndexTree()
            {
                IndexTreeNode[] currNodes = new IndexTreeNode[attrLen];
                for (int i = 0; i < agg.Tuples.Count; i++)
                {
                    bool changed = false;
                    for (int j = 0; j < attrLen; j++)
                    {
                        AttributeMember member = agg.Tuples[i][j];

                        // Transfers flat columns to IndexTree structure
                        // currNode == 1 => first pass
                        // currNode.Member != member => current member is different from the previous row
                        // changed => any previous columns is different from the previous row
                        IndexTreeNode currNode = currNodes[j];
                        if (currNode == null || currNode.Member != member || changed)
                        {
                            changed = true;
                            // Only leaf nodes hold row index
                            IndexTreeNode n = new IndexTreeNode(member);
                            if (j == 0)
                            {
                                agg.IndexTree.Nodes.Add(n);
                                if (attrLen == 1)
                                {
                                    n.Index = i;
                                }
                            }
                            else
                            {
                                currNodes[j - 1].Children.Add(n);
                                if (j == ceiling)
                                {
                                    n.Index = i;
                                }
                            }
                            currNodes[j] = n;
                        }
                    }
                }
            }
        }