问题
What is the difference between tuple
and set
in MDX. How we can distinguish both and when we are using them.
回答1:
A tuple is a single hierarchy member taken from all the dimensions.
Suppose Time.[2nd half]
is a tuple of time dimension. At the same way we can have multiple tuples and we represent them in '(',')' brackets.
Eg:
(Time.[2nd half], Color.Dark.Red).
This is nothing but the mathematical intersection of nodes. we can represent the nodes in maths as (2,1) in the same way above expression will work.
Now coming to sets it is nothing but the composition of tuples. set contains one or more tuples it may zero also. we represent them in { , } braces. Eg:
{ (Time.[1st half], Color.Dark.Red), (Time.[2nd half], Color.Dark.Blue) }
回答2:
Having come to MDX from a more maths perspective this is my take on the question:
Imagine you have 3d Cube with dimensions X, Y and Z. The number of cells in the cube is number of members in X multiplied by the number of members of Y multiplied by the number of members of Z.
Each cell with have a coordinate in the cube based on a value from X, Y and Z. That coordinate is a Tuple.
So lets say :
- X is Measures,
- Y is Years,
- Z is Products,
Then a single cell could be the laptop sales for 1999. The cell coordinate will be:
logically (X, Y, Z)
and physically this is a tuple such as
(Measures.Sales, Years.[1999], Products.[Laptop])
Now lets say we want multiple cells, then we need multiple tuples, right? Yes, a Set is basically multiple tuples. Actually by multiple I include 0 and 1. So extending our example, we could have laptops from 1999 and desktops from 2001:
{
(Measures.Sales, Years.[1999], Products.[Laptop]) ,
(Measures.Sales, Years.[2001], Products.[Desktop])
}
So you can see that you end up with multiple items with a set, and a single item with a tuple......
回答3:
This article describes the terms Member, Tuple and Set in details.
I'll try to explain it in an easy way.
Simply put, a tuple is an atomic slice of data in a dimension and a set is a collection of tuples. For example, you can have a Books
dimension with tuples Sherlock Holmes
, Tom Sawyer
, CLR via C#
, Code Complete
and Quantum Physics for Dummies
.
After that, you can organize these tuples into named sets, like Programming
, Fiction
and Natural Sciences
.
[Books].&[Sherlock Holmes] -- Tuple
[Books].&[CLR via C#] -- Tuple
{ [Books].&[CLR via C#], [Books].&[Code Complete] } -- Set
There are certain functions in MDX that return sets or tuples, and it's often helpful to know how to convert a tuple to a set and vice versa. For example, the Item(...)
function takes a specific tuple from a set. Enclosing multiple tuples in { , , }
will create a set with these tuples.
The example I described is pretty partial and doesn't cover the whole theory, but it might give you a good basic understanding of how these concepts work.
回答4:
Here's the another good explanation from: http://www.onlineexpert.com/elearning/user/pdf/APPLICATIONDEVELOPMENT/SQL2KOLAP/Ch08.pdf.
It's similar to Preet Sangha's answer.
来源:https://stackoverflow.com/questions/9517520/difference-between-tuple-and-set-in-mdx