This project has moved and is read-only. For the latest updates, please go here.

Proposal to add some functions to debug MDX

Topics: Developer Forum
Dec 1, 2012 at 5:05 PM

Dear all,

I've just made 2 functions to debug MDX scripts - DebugTuple and DebugSet, they are at the end of this message. They allow to dump into a file the tuple or a set  during execution of MDX, and they return the same tuple or set without any modification.

Once I had a complicated MDX formula which did something like  Count(Filter(   some set,      (some tuple with coordinates calculated by mdx) > 0 ))

The result of calculation was wrong, and I couldn't figure out why.  So, I've made 

Count(Filter(   some set,      ASSP.DebugTuple(some tuple with coordinates calculated by mdx)) > 0 ))

- it has shown me what the tuple was - all coordinates (by dumping it to a file). And then I understood what was wrong with the formula.

 

I though it may be useful to add this code to ASSP, maybe with some modifications.

The code is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.AnalysisServices.AdomdServer;

namespace ASStoredProcs
{
    public class DebugProcs
    {
        public const string FILENAME = "c:\\temp\\as_debug.txt";

        private static void DumpTuple(Tuple aTuple, StringBuilder aBuilder)
        {
            int start = 0;
            aBuilder.Append("(");
            foreach (Member m in aTuple.Members)
            {
                if (start++ > 0)
                    aBuilder.Append(", ");
                aBuilder.Append(m.UniqueName);
            }
            aBuilder.Append(")");
        }

        [SafeToPrepare(true)]
        public static Tuple DebugTuple(Tuple aTuple)
        {
            StringBuilder b = new StringBuilder();
            b.AppendLine("--------- " + DateTime.Now.ToString());
            DumpTuple(aTuple, b);
            b.AppendLine("\n");
            File.AppendAllText(FILENAME, b.ToString());
            return aTuple;
        }

        [SafeToPrepare(true)]
        public static Set DebugSet(Set aSet)
        {
            StringBuilder b = new StringBuilder();
            b.AppendLine("--------- " + DateTime.Now.ToString());
            int start = 0;
            b.Append("{");
            foreach(Tuple t in aSet)
            {
                if (start++ > 0)
                    b.AppendLine(", ");
                DumpTuple(t, b);
            }
            b.AppendLine("}\n");
            File.AppendAllText(FILENAME, b.ToString());
            return aSet;
        }
    }
}