forked from pentaho/mondrian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.html
3629 lines (3246 loc) · 197 KB
/
schema.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<!--
== This software is subject to the terms of the Eclipse Public License v1.0
== Agreement, available at the following URL:
== http://www.eclipse.org/legal/epl-v10.html.
== You must accept the terms of that agreement to use this software.
==
== Copyright (C) 2001-2005 Julian Hyde
== Copyright (C) 2005-2012 Pentaho
== All Rights Reserved.
==
== jhyde, 24 September, 2002
-->
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<title>Pentaho Analysis Services: How to Design a Mondrian Schema</title>
</head>
<body>
<!-- doc2web start -->
<!-- page title -->
<div class="contentheading">How to Design a Mondrian Schema</div>
<!-- end page title -->
<!--
########################
## Contents #####
######################## -->
<ol>
<li><a href="#What_is_a_schema">What is a schema?</a></li>
<li><a href="#Schema_files">Schema files</a>
<ol>
<li><a href="#Annotation">Annotation</a></li>
</ol>
</li>
<li><a href="#Cubes_and_dimensions">Logical model</a>
<ol>
<li><a href="#Cube">Cube</a></li>
<li><a href="#Measures">Measures</a></li>
<li><a href="#Dimensions,_Hierarchies,_Levels">Dimensions, Hierarchies, Levels</a></li>
<ol>
<li><a href="#Mapping_Hierarchies">Mapping dimensions and hierarchies onto tables</a></li>
<li><a href="#The_all_member">The 'All' member</a></li>
<li><a href="#Time_dimensions">Time dimensions</a></li>
<li><a href="#Level_Order_and_Display">Order and Display of Levels</a></li>
<li><a href="#Multiple_hierarchies">Multiple hierarchies</a></li>
<li><a href="#Degenerate_dimensions">Degenerate dimensions</a></li>
<li><a href="#Inline_tables">Inline tables</a></li>
<li><a href="#Member_properties_and_formatters">Member properties and formatters</a></li>
<li><a href="#Approximate_level_cardinality">Approximate level cardinality</a></li>
<li><a href="#Default_Measure_Attribute">Default Measure Attribute</a></li>
<li><a href="#Functional_dependency_optimizations">Functional Dependency Optimizations</a></li>
<li><a href="#Table_hints">Table Hints</a></li>
</ol>
</ol>
</li>
<li><a href="#Star_schemas">Star and snowflake schemas</a>
<ol>
<li><a href="#Shared_dimensions">Shared dimensions</a></li>
<li><a href="#Join_optimization">Join optimization</a></li>
</ol>
</li>
<li><a href="#Advanced_logical_constructs">Advanced logical constructs</a>
<ol>
<li><a href="#Virtual_cubes">Virtual cubes</a></li>
<li><a href="#Parent_child_hierarchies">Parent-child hierarchies</a><ol>
<li><a href="#Tuning_parent-child_hierarchies">Tuning parent-child
hierarchies</a></li>
<li><a href="#Closure_tables">Closure tables</a></li>
<li><a href="#Populating_closure_tables">Populating closure tables</a></li>
</ol>
</li>
<li><a href="#Member_properties">Member properties</a></li>
<li><a href="#Calculated_members">Calculated members</a></li>
<li><a href="#Named_sets">Named sets</a></li>
</ol>
</li>
<li><a href="#Plugins">Plug-ins</a>
<ol>
<li><a href="#User-defined_function">User-defined function</a></li>
<li><a href="#Member_reader">Member reader</a></li>
<li><a href="#Cell_reader">Cell reader</a></li>
<li><a href="#Cell_formatter">Cell formatter</a></li>
<li><a href="#Member_formatter">Member formatter</a></li>
<li><a href="#Property_formatter">Property formatter</a></li>
<li><a href="#Schema_processor">Schema processor</a></li>
<li><a href="#DataSource_change_listener">Data source change listener</a></li>
<li><a href="#Dynamic_datasource_xmla_servlet">Dynamic datasource xmla servlet</a></li>
</ol>
</li>
<li><a href="#I18n">Internationalization</a></li>
<li><a href="#Aggregate_tables">Aggregate tables</a></li>
<li><a href="#Access_control">Access-control</a>
<ol>
<li><a href="#Defining_roles">Defining a role</a></li>
<li><a href="#Rollup_policy">Rollup policy</a></li>
<li><a href="#Union_roles">Union roles</a></li>
<li><a href="#Setting_a_connections_role">Setting a connection's role</a></li>
</ol>
</li>
<li><a href="#Appendix_A_XML_elements">Appendix A: XML elements</a></li>
</ol>
<!--
#############################
## 1. What is a Schema #####
############################# -->
<h3>1. What is a schema?<a name="What_is_a_schema"> </a></h3>
<p>A schema defines a multi-dimensional database. It contains a logical model, consisting of cubes, hierarchies, and members, and a mapping of this model onto a physical model.</p>
<p>The logical model consists of the constructs used to write queries in MDX language: cubes, dimensions, hierarchies, levels, and members.</p>
<p>The physical model is the source of the data which is presented through the logical model. It is typically a star schema, which is a set of tables in a relational database; later, we shall see examples of other kinds of mappings.</p>
<!--
###########################
## 2. overview start #####
########################### -->
<h3>2. Schema files<a name="Schema_files"> </a></h3>
<p>Mondrian schemas are represented in an XML file. An example schema, containing almost all of the
constructs we discuss here, is supplied as <code>demo/FoodMart.xml</code> in the Mondrian distribution.
The dataset to populate this schema is <a href="install.html#2_Set_up_test_data">also in the distribution</a>.</p>
<p>Currently, the only way to create a schema is to edit a schema XML file in a text editor. The XML
syntax is not too complicated, so this is not as difficult as it sounds, particularly if you use the FoodMart
schema as a guiding example.</p>
<p>The structure of the XML document is as follows:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px"><<a href="#XML_Schema">Schema</a>></div>
<div style="padding-left:40px;"><<a href="#XML_Cube">Cube</a>></div>
<div style="padding-left:60px;"><<a href="#XML_Table">Table</a>></div>
<div style="padding-left:80px;"><<a href="#XML_AggName">AggName</a>></div>
<div style="padding-left:100px;">aggElements</div>
<div style="padding-left:80px;"><<a href="#XML_AggPattern">AggPattern</a>></div>
<div style="padding-left:100px;">aggElements</div>
<div style="padding-left:60px;"><<a href="#XML_Dimension">Dimension</a>></div>
<div style="padding-left:80px;"><<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:100px;">relation</div>
<div style="padding-left:100px;"><<a href="#XML_Closure">Closure</a>/></div>
<div style="padding-left:100px;"><<a href="#XML_Level">Level</a>></div>
<div style="padding-left:120px;"><<a href="#XML_KeyExpression">KeyExpression</a>></div>
<div style="padding-left:140px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:120px;"><<a href="#XML_NameExpression">NameExpression</a>></div>
<div style="padding-left:140px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:120px;"><<a href="#XML_CaptionExpression">CaptionExpression</a>></div>
<div style="padding-left:140px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:120px;"><<a href="#XML_OrdinalExpression">OrdinalExpression</a>></div>
<div style="padding-left:140px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:120px;"><<a href="#XML_ParentExpression">ParentExpression</a>></div>
<div style="padding-left:140px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:120px;"><<a href="#XML_Property">Property</a>></div>
<div style="padding-left:140px;"><<a href="#XML_PropertyExpression">PropertyExpression</a>></div>
<div style="padding-left:160px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:60px;"><<a href="#XML_DimensionUsage">DimensionUsage</a>></div>
<div style="padding-left:60px;"><<a href="#XML_Measure">Measure</a>></div>
<div style="padding-left:80px;"><<a href="#XML_MeasureExpression">MeasureExpression</a>></div>
<div style="padding-left:100px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:80px;"><<a href="#XML_MemberProperty">CalculatedMemberProperty</a>/></div>
<div style="padding-left:60px;"><<a href="#XML_CalculatedMember">CalculatedMember</a>></div>
<div style="padding-left:80px;"><<a href="#XML_Formula">Formula</a>/></div>
<div style="padding-left:80px;"><<a href="#XML_MemberProperty">CalculatedMemberProperty</a>/></div>
<div style="padding-left:60px;"><<a href="#XML_NamedSet">NamedSet</a>></div>
<div style="padding-left:80px;"><<a href="#XML_Formula">Formula</a>/></div>
<div style="padding-left:40px;"><<a href="#XML_VirtualCube">VirtualCube</a>></div>
<div style="padding-left:60px;"><<a href="#XML_CubeUsages">CubeUsages</a>></div>
<div style="padding-left:80px;"><<a href="#XML_CubeUsage">CubeUsage</a>></div>
<div style="padding-left:60px;"><<a href="#XML_VirtualCubeDimension">VirtualCubeDimension</a>></div>
<div style="padding-left:60px;"><<a href="#XML_VirtualCubeMeasure">VirtualCubeMeasure</a>></div>
<div style="padding-left:40px;"><<a href="#XML_Role">Role</a>></div>
<div style="padding-left:60px;"><<a href="#XML_SchemaGrant">SchemaGrant</a>></div>
<div style="padding-left:80px;"><<a href="#XML_CubeGrant">CubeGrant</a>></div>
<div style="padding-left:100px;"><<a href="#XML_DimensionGrant">DimensionGrant</a>></div>
<div style="padding-left:100px;"><<a href="#XML_HierarchyGrant">HierarchyGrant</a>></div>
<div style="padding-left:120px;"><<a href="#XML_MemberGrant">MemberGrant</a>/></div>
<div style="padding-left:60px;"><<a href="#XML_Union">Union</a>></div>
<div style="padding-left:80px;"><<a href="#XML_RoleUsage">RoleUsage</a>/></div>
<div style="padding-left:40px;"><<a href="#XML_UserDefinedFunction">UserDefinedFunction</a>/></div>
<div style="padding-left:40px;"><<a href="#XML_Parameter">Parameter</a>/></div>
<br/>
relation ::=<br/>
<div style="padding-left:40px;"><<a href="#XML_Table">Table</a>></div>
<div style="padding-left:60px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:40px;"><<a href="#XML_View">View</a>></div>
<div style="padding-left:60px;"><<a href="#XML_SQL">SQL</a>/></div>
<div style="padding-left:40px;"><<a href="#XML_InlineTable">InlineTable</a>></div>
<div style="padding-left:60px;"><<a href="#XML_ColumnDefs">ColumnDefs</a>></div>
<div style="padding-left:80px;"><<a href="#XML_ColumnDef">ColumnDef</a>></div>
<div style="padding-left:60px;"><<a href="#XML_Rows">Rows</a>></div>
<div style="padding-left:80px;"><<a href="#XML_Row">Row</a>></div>
<div style="padding-left:100px;"><<a href="#XML_Value">Value</a>></div>
<div style="padding-left:40px;"><<a href="#XML_Join">Join</a>></div>
<div style="padding-left:60px;">relation</div>
<br/>
aggElement ::=<br/>
<div style="padding-left:40px;"><<a href="#XML_AggExclude">AggExclude</a>></div>
<div style="padding-left:40px;"><<a href="#XML_AggFactCount">AggFactCount</a>></div>
<div style="padding-left:40px;"><<a href="#XML_AggIgnoreColumn">AggIgnoreColumn</a>></div>
<div style="padding-left:40px;"><<a href="#XML_AggForeignKey">AggForeignKey</a>></div>
<div style="padding-left:40px;"><<a href="#XML_AggMeasure">AggMeasure</a>></div>
<div style="padding-left:40px;"><<a href="#XML_AggLevel">AggLevel</a>></div>
</code>
</blockquote>
<p><b>NOTE</b>: The order of XML elements is important. For example, the
<code><a href="#XML_UserDefinedFunction"><UserDefinedFunction></a></code>
element has to occur inside the <code><a href="#XML_Schema"><Schema></a></code>
element after all collections of <code><a href="#XML_Cube"><Cube></a></code>,
<code><a href="#XML_VirtualCube"><VirtualCube></a></code>,
<code><a href="#XML_NamedSet"><NamedSet></a></code>
and <code><a href="#XML_Role"><Role></a></code> elements. If you include it before the first
<code><a href="#XML_Cube"><Cube></a></code> element,
the rest of the schema will be ignored.</p>
<p>The content of each XML element is described in
<a href="#Appendix_A_XML_elements">Appendix A</a> and in the <a href="xml_schema.html">XML schema</a>.</p>
<!--
##########################
## 2.1 Annotations #####
########################## -->
<h1>2.1 Annotation<a name="Annotation"> </a></h1>
<p>The major element types (schema, cube, virtual cube, shared dimension,
dimension, hierarchy, level, measure, calculated member) support annotations. An
annotation is a way of associating a user-defined property with a metadata
element, and in particular, allows tools to add metadata without extending the
official Mondrian schema.</p>
<p>Create an
<code><a href="#XML_Annotations"><Annotations></a></code> element as a child of the element you wish to
annotate (generally it is the first child element, but check the schema
definition for details), then include a number of
<code><a href="#XML_Annotation"><Annotation></a></code> elements.
<code><a href="#XML_Annotation"><Annotation></a></code>
elements' names must be unique within their element. If you are adding
annotations to support a particular tool that you maintain, choose annotation
names carefully, to ensure that they do not clash with annotations used by other
tools.</p>
<p>The following example shows "Author" and "Date" annotations attached to a <code><a href="#XML_Schema"><Schema></a></code> object.</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Schema">Schema</a> name="Rock Sales"></div>
<div style="padding-left:40px;;"><<a href="#XML_Annotations">Annotations</a>></div>
<div style="padding-left:60px;;"><<a href="#XML_Annotation">Annotation</a> name="Author">Fred Flintstone</<a href="#XML_Annotation">Annotation</a>></div>
<div style="padding-left:60px;;"><<a href="#XML_Annotation">Annotation</a> name="Date">10,000 BC</<a href="#XML_Annotation">Annotation</a>></div>
<div style="padding-left:40px;;"></<a href="#XML_Annotations">Annotations</a>></div>
<div style="padding-left:40px;;"><<a href="#XML_Cube">Cube</a> name="Sales"></div>
<div style="padding-left:60px;;">...</div>
</code>
</blockquote>
<!--
###########################
## 3. Logical model #####
########################### -->
<h3>3. Logical model<a name="Cubes_and_dimensions"> </a></h3>
<p>The most important components of a schema are cubes, measures, and dimensions:</p>
<ul>
<li>A <dfn>cube</dfn> is a collection of dimensions and measures in a particular subject area. </li>
<li>A <dfn>measure</dfn> is a quantity that you are interested in measuring, for example, unit sales of a
product, or cost price of inventory items.</li>
<li>A <dfn>dimension</dfn> is an attribute, or set of attributes, by which you can divide measures into
sub-categories. For example, you might wish to break down product sales by their color, the gender of the
customer, and the store in which the product was sold; color, gender, and store are all dimensions.</li>
</ul>
<p>Let's look at the XML definition of a simple schema.</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Schema">Schema</a>></div>
<div style="padding-left:40px;;"><<a href="#XML_Cube">Cube</a> name="Sales"></div>
<div style="padding-left:60px;"><<a href="#XML_Table">Table</a> name="sales_fact_1997"/></div>
<div style="padding-left:60px;"><<a href="#XML_Dimension">Dimension</a> name="Gender" foreignKey="customer_id"></div>
<div style="padding-left:80px;"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true" allMemberName="All Genders" primaryKey="customer_id"></div>
<div style="padding-left:100px;"><<a href="#XML_Table">Table</a> name="customer"/></div>
<div style="padding-left:100px;"><<a href="#XML_Level">Level</a> name="Gender" column="gender" uniqueMembers="true"/></div>
<div style="padding-left:80px;"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:60px;"></<a href="#XML_Dimension">Dimension</a>></div>
<div style="padding-left:60px;"><<a href="#XML_Dimension">Dimension</a> name="Time" foreignKey="time_id"></div>
<div style="padding-left:80px;"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="false" primaryKey="time_id"></div>
<div style="padding-left:100px;"><<a href="#XML_Table">Table</a> name="time_by_day"/></div>
<div style="padding-left:100px;"><<a href="#XML_Level">Level</a> name="Year" column="the_year" type="Numeric" uniqueMembers="true"/></div>
<div style="padding-left:100px;"><<a href="#XML_Level">Level</a> name="Quarter" column="quarter" uniqueMembers="false"/></div>
<div style="padding-left:100px;"><<a href="#XML_Level">Level</a> name="Month" column="month_of_year" type="Numeric" uniqueMembers="false"/></div>
<div style="padding-left:80px;"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:60px;"></<a href="#XML_Dimension">Dimension</a>></div>
<div style="padding-left:60px;"><<a href="#XML_Measure">Measure</a> name="Unit Sales" column="unit_sales" aggregator="sum" formatString="#,###"/></div>
<div style="padding-left:60px;"><<a href="#XML_Measure">Measure</a> name="Store Sales" column="store_sales" aggregator="sum" formatString="#,###.##"/></div>
<div style="padding-left:60px;"><<a href="#XML_Measure">Measure</a> name="Store Cost" column="store_cost" aggregator="sum" formatString="#,###.00"/></div>
<div style="padding-left:60px;"><<a href="#XML_CalculatedMember">CalculatedMember</a> name="Profit" dimension="Measures" formula="[Measures].[Store Sales] - [Measures].[Store Cost]"></div>
<div style="padding-left:80px;"><<a href="#XML_CalculatedMemberProperty">CalculatedMemberProperty</a> name="FORMAT_STRING" value="$#,##0.00"/></div>
<div style="padding-left:60px;"></<a href="#XML_CalculatedMember">CalculatedMember</a>></div>
<div style="padding-left:40px;"></<a href="#XML_Cube">Cube</a>></div>
<div style="padding-left:20px"></<a href="#XML_Schema">Schema</a>></div>
</code>
</blockquote>
<p>This schema contains a single cube, called "Sales". The Sales cube has two dimensions,
"Time", and "Gender", and four measures, "Unit Sales", "Store Sales", "Store Cost", and "Profit".</p>
<p>We can write an MDX query on this schema:</p>
<blockquote style="text-indent: -20px">
<code>
SELECT {[Measures].[Unit Sales], [Measures].[Store Sales]} ON COLUMNS,<br/>
{descendants([Time].[1997].[Q1])} ON ROWS<br/>
FROM [Sales]<br/>
WHERE [Gender].[F]
</code>
</blockquote>
<p>This query refers to the Sales cube (<code>[Sales]</code>), each of the dimensions
<code>[Measures]</code>, <code>[Time]</code>, <code>[Gender</code>], and various members
of those dimensions. The results are as follows:</p>
<blockquote>
<table class="grayTable" id="AutoNumber1" >
<tr>
<td align="left"><code>[Time]</code></td>
<td><code>[Measures].[Unit Sales]</code></td>
<td><code>[Measures].[Store Sales]</code></td>
</tr>
<tr>
<td align="left"><code>[1997].[Q1]</code></td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td align="left"><code>[1997].[Q1].[Jan]</code></td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td align="left"><code>[1997].[Q1].[Feb]</code></td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td align="left"><code>[1997].[Q1].[Mar]</code></td>
<td>0</td>
<td>0</td>
</tr>
</table>
</blockquote>
<p>Now let's look at the schema definition in more detail.</p>
<!--
########################
## 3.1 Cube #####
######################## -->
<h1>3.1 Cube<a name="Cube"> </a></h1>
<p>A cube (see <code><a href="#XML_Cube"><Cube></a></code>) is a named collection of measures
and dimensions. The one thing the measures and dimensions have in common is the fact table, here
<code>"sales_fact_1997"</code>. As we shall see, the fact table holds the columns
from which measures are calculated, and contains references to the tables which hold the dimensions.</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Cube">Cube</a> name="Sales"></div>
<div style="padding-left:40px;"><<a href="#XML_Table">Table</a> name="sales_fact_1997"/></div>
<div style="padding-left:40px;">...</div>
<div style="padding-left:20px"></<a href="#XML_Cube">Cube</a>></div>
</code>
</blockquote>
<p>The fact table is defined using the <code><a href="#XML_Table"><Table></a></code> element. If the fact table is not in
the default schema, you can provide an explicit schema using the "schema" attribute, for example</p>
<blockquote>
<code>
<div style="padding-left:20px;"><<a href="#XML_Table">Table</a> schema=" dmart" name="sales_fact_1997"/></div>
</code>
</blockquote>
<p>You can also use the <code><a href="#XML_View"><View></a></code>
construct to build more complicated SQL statements. The
<code><a href="#XML_Join"><Join></a></code> construct is not supported for fact tables.</p>
<!--
########################
## 3.2 Measures #####
######################## -->
<h1>3.2 Measures<a name="Measures"> </a></h1>
<p>The Sales cube defines several measures, including "Unit Sales" and "Store Sales".</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Measure">Measure</a> name="Unit Sales" column="unit_sales" aggregator="sum" datatype="Integer" formatString="#,###"/></div>
<div style="padding-left:20px;"><<a href="#XML_Measure">Measure</a> name="Store Sales" column="store_sales" aggregator="sum" datatype="Numeric" formatString="#,###.00"/></div>
</code>
</blockquote>
<p>Each measure (see <code><a href="#XML_Measure"><Measure></a></code>) has a name, a column in the fact table, and an
<code>aggregator</code>. The aggregator is usually "sum", but "count", "min", "max", "avg", and
"distinct-count" are also allowed; "distinct-count" has some limitations if your cube contains a
<a href="#Parent_child_hierarchies">parent-child hierarchy</a>.</p>
<p>The optional <code>datatype</code> attribute specifies how cell values are represented in Mondrian's
cache, and how they are returned via XML for Analysis. The <code>datatype</code> attribute can have
values "<code>String</code>", "<code>Integer</code>", "<code>Numeric</code>", "<code>Boolean</code>",
"<code>Date</code>", "<code>Time</code>", and "<code>Timestamp</code>".
The default is "<code>Numeric</code>", except for "<code>count</code>" and
"<code>distinct-count</code>" measures, which are "<code>Integer</code>".</p>
<p>An optional <code>formatString</code> attribute specifies how the value is to be printed.
Here, we have chosen to output unit sales with no decimal places (since it is an integer), and store sales
with two decimal places (since it is a currency value). The ',' and '.' symbols are locale-sensitive, so if
you were running in Italian, store sales might appear as "48.123,45". You can achieve even more wild effects
using <a href="mdx.html#Format_strings">advanced format strings</a>.</p>
<p>A measure can have a caption attribute to be returned by the
<code><a href="http://sourceforge.net/api/mondrian/olap/Member.html#getCaption%28%29">Member.getCaption()</a></code>
method instead of the name. Defining a specific caption does make sense if special letters (e.g. Σ or Π)
are to be displayed:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Measure">Measure</a> name="Sum X" column="sum_x" aggregator="sum" caption="&#931; X"/></div>
</code>
</blockquote>
<p>Rather than coming from a column, a measure can use a <a href="#Cell_reader">cell reader</a>,
or a measure can use a SQL expression to calculate its value. The measure "Promotion Sales" is
an example of this.</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px"><<a href="#XML_Measure">Measure</a> name="Promotion Sales" aggregator="sum" formatString="#,###.00"></div>
<div style="padding-left:40px;"><<a href="#XML_MeasureExpression">MeasureExpression</a>></div>
<div style="padding-left:60px;"><<a href="#XML_SQL">SQL</a> dialect="generic"></div>
<div style="padding-left:80px;">(case when sales_fact_1997.promotion_id = </div>
<div style="padding-left:80px;">0 then 0 else sales_fact_1997.store_sales end)</div>
<div style="padding-left:60px;"></<a href="#XML_SQL">SQL</a>></div>
<div style="padding-left:40px;"></<a href="#XML_MeasureExpression">MeasureExpression</a>></div>
<div style="padding-left:20px"></<a href="#XML_Measure">Measure</a>></div>
</code>
</blockquote>
<p>In this case, sales are only included in the summation if they correspond to a promotion sale.
Arbitrary SQL expressions can be used, including subqueries. However, the underlying database
must be able to support that SQL expression in the context of an aggregate. Variations in syntax
between different databases is handled by specifying the dialect in the SQL tag.</p>
<p>In order to provide a specific formatting of the cell values, a measure can use a
<a href="#Cell_formatter">cell formatter</a>.</p>
<!--
#############################################
## 3.3 Dimensions, Hierarchies, Levels #####
############################################# -->
<h1>3.3 Dimensions, Hierarchies, Levels<a name="Dimensions,_Hierarchies,_Levels"> </a></h1>
<p>Some more definitions:</p>
<ul>
<li>A <dfn>member</dfn> is a point within a dimension determined by a particular set of attribute
values. The gender hierarchy has the two members 'M' and 'F'. 'San Francisco', 'California' and
'USA' are all members of the store hierarchy.</li>
<li>A <dfn>hierarchy</dfn> is a set of members organized into a structure for convenient analysis.
For example, the store hierarchy consists of the store name, city, state, and nation. The
hierarchy allows you to form intermediate sub-totals: the sub-total for a state is the sum of the
sub-totals of all of the cities in that state, each of which is the sum of the sub-totals of
the stores in that city.</li>
<li>A <dfn>level</dfn> is a collection of members which have the
same distance from the root of the hierarchy.</li>
<li>A <dfn>dimension</dfn> is a collection of hierarchies which discriminate on the same fact table attribute (say, the day that a sale occurred).</li>
</ul>
<p>For reasons of uniformity, measures are treated as members of a special dimension, called 'Measures'.</p>
<!--
########################
## An example #####
######################## -->
<h1>An example</h1>
<p>Let's look at a simple dimension. </p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px"><<a href="#XML_Dimension">Dimension</a> name="Gender" foreignKey="customer_id"></div>
<div style="padding-left:40px;"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true" primaryKey="customer_id"></div>
<div style="padding-left:60px;"><<a href="#XML_Table">Table</a> name="customer"/></div>
<div style="padding-left:60px;"><<a href="#XML_Level">Level</a> name="Gender" column="gender" uniqueMembers="true"/></div>
<div style="padding-left:40px;"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:20px"></<a href="#XML_Dimension">Dimension</a>></div>
</code>
</blockquote>
<p>This dimension consists of a single hierarchy, which consists of a single level called <code>Gender</code>.
(As we shall see <a href="#The_all_member">later</a>, there is also a special level called
<code>[(All)]</code> containing a grand total.)</p>
<p>The values for the dimension come from the <code>gender</code> column in the <code>customer</code>
table. The "gender" column contains two values, 'F' and 'M', so the Gender dimension contains the members
<code>[Gender].[F]</code> and <code>[Gender].[M]</code>.</p>
<p>For any given sale, the gender dimension is the gender of the customer who made that purchase. This is expressed by
joining from the fact table "sales_fact_1997.customer_id" to the dimension table "customer.customer_id".</p>
<!--
##############################################################
## 3.3.1 Mapping dimensions and hierarchies onto tables #####
############################################################## -->
<h1>3.3.1 Mapping dimensions and hierarchies onto tables<a name="Mapping_Hierarchies"> </a></h1>
<p>A dimension is joined to a cube by means of a pair of columns, one in the fact table, the other in the dimension table.
The <code><Dimension></code> element has a <code>foreignKey</code> attribute,
which is the name of a column in the fact table; the <code><Hierarchy></code> element has
a <code>primaryKey</code> attribute.</p>
<p>If the hierarchy has more than one table, you can disambiguate using the <code>primaryKeyTable</code>
attribute. </p>
<p>The <code>column</code> attribute defines the key of the level. It must be
the name of a column in the level's table. If the key is an expression, you can
instead use the <code><KeyExpression></code> element inside the Level. The following is
equivalent to the above example:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px"><<a href="#XML_Dimension">Dimension</a> name="Gender" foreignKey="customer_id"></div>
<div style="padding-left:40px"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true" primaryKey="customer_id"></div>
<div style="padding-left:60px"><<a href="#XML_Table">Table</a> name="customer"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Gender" column="gender" uniqueMembers="true"></div>
<div style="padding-left:80px;"><<a href="#XML_KeyExpression">KeyExpression</a>></div>
<div style="padding-left:100px;"><<a href="#XML_SQL">SQL</a> dialect="generic">customer.gender</<a href="#XML_SQL">SQL</a>></div>
<div style="padding-left:80px;"></<a href="#XML_KeyExpression">KeyExpression</a>></div>
<div style="padding-left:60px;"></<a href="#XML_Level">Level</a>></div>
<div style="padding-left:40px;"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:20px"></<a href="#XML_Dimension">Dimension</a>></div>
</code>
</blockquote>
<p>Other attributes of <code><Level></code>, <code><Measure></code>
and <code><Property></code> have corresponding nested elements:</p>
<table class="grayTable" id="table11" width="500">
<tr>
<td><b>Parent element</b></td>
<td><b>Attribute</b></td>
<td><b>Equivalent nested element</b></td>
<td><b>Description</b></td>
</tr>
<tr>
<td><code><<a href="#XML_Level">Level</a>></code></td>
<td><code>column</code></td>
<td><code><<a href="#XML_KeyExpression">KeyExpression</a>></code></td>
<td>Key of level.</td>
</tr>
<tr>
<td><code><<a href="#XML_Level">Level</a>></code></td>
<td><code>nameColumn</code></td>
<td><code><<a href="#XML_NameExpression">NameExpression</a>></code></td>
<td>Expression which defines the name of members of this level. If
not specified, the level key is used.</td>
</tr>
<tr>
<td><code><<a href="#XML_Level">Level</a>></code></td>
<td><code>ordinalColumn</code></td>
<td><code><<a href="#XML_OrdinalExpression">OrdinalExpression</a>></code></td>
<td>Expression which defines the order of members. If not specified,
the level key is used.</td>
</tr>
<tr>
<td><code><<a href="#XML_Level">Level</a>></code></td>
<td><code>captionColumn</code></td>
<td><code><<a href="#XML_CaptionExpression">CaptionExpression</a>></code></td>
<td>Expression which forms the caption of members. If not specified,
the level name is used.</td>
</tr>
<tr>
<td><code><<a href="#XML_Level">Level</a>></code></td>
<td><code>parentColumn</code></td>
<td><code><<a href="#XML_ParentExpression">ParentExpression</a>></code></td>
<td>Expression by which child members reference their parent member
in a parent-child hierarchy. Not specified in a regular hierarchy.</td>
</tr>
<tr>
<td><code><<a href="#XML_Measure">Measure</a>></code></td>
<td><code>column</code></td>
<td><code><<a href="#XML_MeasureExpression">MeasureExpression</a>></code></td>
<td>SQL expression to calculate the value of the measure (the
argument to the SQL aggregate function).</td>
</tr>
<tr>
<td><code><<a href="#XML_Property">Property</a>></code></td>
<td><code>column</code></td>
<td><code><<a href="#XML_PropertyExpression">PropertyExpression</a>></code></td>
<td>SQL expression to calculate the value of the property.</td>
</tr>
</table>
<p>The <code>uniqueMembers</code> attribute is used to optimize SQL generation. If you know that the
values of a given level column in the dimension table are unique across all the other values in that column across
the parent levels, then set <code>uniqueMembers="true"</code>, otherwise, set to
<code>"false"</code>. For example, a time dimension like <code>[Year].[Month]</code>
will have <code>uniqueMembers="false"</code> at the Month level, as the same month appears in different
years. On the other hand, if you had a <code>[Product Class].[Product Name]</code> hierarchy, and you
were sure that <code>[Product Name]</code> was unique, then you can set
<code>uniqueMembers="true"</code>. If you are not sure, then always set
<code>uniqueMembers="false"</code>. At the top level, this will always be
<code>uniqueMembers="true"</code>, as there is no parent level.</p>
<p>The <code>highCardinality</code> attribute is used to notify Mondrian
there are undefined and very high number of elements for this dimension.
Acceptable values are <code>true</code> or <code>false</code> (last one
is default value). Actions performed over the whole set of dimension elements
cannot be performed when using <code>highCardinality="true"</code>.
</p>
<!--
################################
## 3.3.2 The 'all' member #####
################################ -->
<h1>3.3.2 The 'all' member<a name="The_all_member"> </a></h1>
<p>By default, every hierarchy contains a top level called '<code>(All)</code>', which contains a single
member called '<code>(All {<i>hierarchyName</i>})</code>'. This member is parent of all other members
of the hierarchy, and thus represents a grand total. It is also the default member of the hierarchy; that is, the member
which is used for calculating cell values when the hierarchy is not included on an axis or in the slicer. The
<code>allMemberName</code> and <code>allLevelName</code> attributes override the default
names of the all level and all member.</p>
<p>If the <code><Hierarchy></code> element has <code> hasAll="false"</code>, the 'all'
level is suppressed. The default member of that dimension will now be the first member of the first level; for example,
in a Time hierarchy, it will be the first year in the hierarchy. Changing the default member can be confusing, so you
should generally use <code> hasAll="true"</code>.</p>
<p>The <code><Hierarchy></code> element also has a <code>defaultMember</code>
attribute, to override the default member of the hierarchy:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Dimension">Dimension</a> name="Time" type="TimeDimension" foreignKey="time_id"></div>
<div style="padding-left:40px;"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="false" primaryKey="time_id" defaultMember="[Time].[1997].[Q1].[1]"/></div>
<div style="padding-left:60px;">...</div>
</code>
</blockquote>
<!--
###############################
## 3.3.3 Time dimensions #####
############################### -->
<h1>3.3.3 Time dimensions<a name="Time_dimensions"> </a></h1>
<p>Time dimensions based on year/month/week/day are coded differently in the Mondrian schema
due to the MDX time related functions such as:</p>
<ul>
<li><code>ParallelPeriod([level[, index[, member]]])</code></li>
<li><code>PeriodsToDate([level[, member]])</code></li>
<li><code>WTD([member])</code></li>
<li><code>MTD([member])</code></li>
<li><code>QTD([member])</code></li>
<li><code>YTD([member])</code></li>
<li><code>LastPeriod(index[, member])</code></li>
</ul>
<p>Time dimensions have <code>type="TimeDimension"</code>. The role of a level in a time dimension is
indicated by the level's <code>levelType</code> attribute, whose allowable values are as follows:</p>
<table class="grayTable" >
<tr>
<td><code>levelType</code> value</td>
<td><b>Meaning</b></td>
</tr>
<tr>
<td>TimeYears</td>
<td>Level is a year</td>
</tr>
<tr>
<td>TimeQuarters</td>
<td>Level is a quarter</td>
</tr>
<tr>
<td>TimeMonths</td>
<td>Level is a month</td>
</tr>
<tr>
<td>TimeWeeks</td>
<td>Level is a week</td>
</tr>
<tr>
<td>TimeDays</td>
<td>Level represents days</td>
</tr>
</table>
<p>Here is an example of a time dimension:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Dimension">Dimension</a> name="Time" type="TimeDimension"></div>
<div style="padding-left:40px;"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true" allMemberName="All Periods" primaryKey="dateid"></div>
<div style="padding-left:60px;"><<a href="#XML_Table">Table</a> name="datehierarchy"/></div>
<div style="padding-left:60px;"><<a href="#XML_Level">Level</a> name="Year" column="year" uniqueMembers="true" levelType="TimeYears" type="Numeric"/></div>
<div style="padding-left:60px;"><<a href="#XML_Level">Level</a> name="Quarter" column="quarter" uniqueMembers="false" levelType="TimeQuarters"/></div>
<div style="padding-left:60px;"><<a href="#XML_Level">Level</a> name="Month" column="month" uniqueMembers="false" ordinalColumn="month" nameColumn="month_name" levelType="TimeMonths" type="Numeric"/></div>
<div style="padding-left:60px;"><<a href="#XML_Level">Level</a> name="Week" column="week_in_month" uniqueMembers="false" levelType="TimeWeeks"/></div>
<div style="padding-left:60px;"><<a href="#XML_Level">Level</a> name="Day" column="day_in_month" uniqueMembers="false" ordinalColumn="day_in_month" nameColumn="day_name" levelType="TimeDays" type="Numeric"/></div>
<div style="padding-left:40px;"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:20px;"></<a href="#XML_Dimension">Dimension</a>></div>
</code>
</blockquote>
<!--
##########################################
## 3.3.4 Order and display of levels #####
########################################## -->
<h1>3.3.4 Order and display of levels<a name="Level_Order_and_Display"> </a></h1>
<p>Notice in the time hierarchy example above the <code>ordinalColumn</code> and
<code>nameColumn</code> attributes on the <code><Level></code> element. These
affect how levels are displayed in a result. The <code>ordinalColumn</code> attribute specifies a
column in the Hierarchy table that provides the order of the members in a given level, while the
<code>nameColumn</code> specifies a column that will be displayed.</p>
<p>For example, in the Month level above, the <code>datehierarchy</code> table has month (1 .. 12)
and month_name (January, February, ...) columns. The column value that will be used internally within MDX is the
month column, so valid member specifications will be of the form:
<code>[Time].[2005].[Q1].[<b><i>1</i></b>]</code>. Members of the <code>[Month]</code>
level will be displayed in the order January, February, etc.</p>
<p>In a parent-child hierarchy, members are always sorted in hierarchical
order. The <code>ordinalColumn</code> attribute controls the order that
siblings appear within their parent.</p>
<p>Ordinal columns may be of any datatype which can legally be used in
an ORDER BY clause. Scope of ordering is per-parent, so in the
example above, the day_in_month column should cycle for each month.
Values returned by the JDBC driver should be non-null instances of <a
href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html">
java.lang.Comparable</a>
which yield the desired ordering when their
<code>Comparable.compareTo</code> method is called.</p>
<p>Levels contain a <code>type</code> attribute, which can have values "<code>String</code>", "<code>Integer</code>", "<code>Numeric</code>", "<code>Boolean</code>",
"<code>Date</code>", "<code>Time</code>", and "<code>Timestamp</code>".
The default value is <code>"Numeric"</code> because key columns generally have a numeric type. If it is a
different type, Mondrian needs to know this so it can generate SQL statements
correctly; for example, string values will be generated enclosed in single
quotes:</p>
<blockquote>
<p><code>WHERE productSku = '123-455-AA'</code></p>
</blockquote>
<!--
####################################
## 3.3.5 Multiple hierarchies #####
#################################### -->
<h1>3.3.5 Multiple hierarchies<a name="Multiple_hierarchies"> </a></h1>
<p>A dimension can contain more than one hierarchy:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Dimension">Dimension</a> name="Time" foreignKey="time_id"></div>
<div style="padding-left:40px;"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="false" primaryKey="time_id"></div>
<div style="padding-left:60px;"><<a href="#XML_Table">Table</a> name="time_by_day"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Year" column="the_year" type="Numeric" uniqueMembers="true"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Quarter" column="quarter" uniqueMembers="false"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Month" column="month_of_year" type="Numeric" uniqueMembers="false"/></div>
<div style="padding-left:40px"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:40px"><<a href="#XML_Hierarchy">Hierarchy</a> name="Time Weekly" hasAll="false" primaryKey="time_id"></div>
<div style="padding-left:60px"><<a href="#XML_Table">Table</a> name="time_by_week"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Year" column="the_year" type="Numeric" uniqueMembers="true"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Week" column="week" uniqueMembers="false"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Day" column="day_of_week" type="String" uniqueMembers="false"/></div>
<div style="padding-left:40px"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:20px;"></<a href="#XML_Dimension">Dimension</a>></div>
</code>
</blockquote>
<p>Notice that the first hierarchy doesn't have a name. By default, a hierarchy has the
same name as its dimension, so the first hierarchy is called "Time".</p>
<p>These hierarchies don't have much in common -- they don't even have the same table! -- except
that they are joined from the same column in the fact table, <code>"time_id"</code>.
The main reason to put two hierarchies in the same dimension is because it makes more sense to
the end-user: end-users know that it makes no sense to have the "Time" hierarchy on one axis
and the "Time Weekly" hierarchy on another axis. If two hierarchies are the same dimension, the
MDX language enforces common sense, and does not allow you to use them both in the same query.</p>
<!--
#####################################
## 3.3.6 Degenerate dimensions #####
##################################### -->
<h1>3.3.6 Degenerate dimensions<a name="Degenerate_dimensions"> </a></h1>
<p>A <dfn>degenerate dimension</dfn> is a dimension which is so simple that it isn't worth
creating its own dimension table. For example, consider following the fact table:</p>
<table id="table5" class="grayTable" >
<tr>
<td><b>product_id</b></td>
<td><b>time_id</b></td>
<td><b>payment_method</b></td>
<td><b>customer_id</b></td>
<td><b>store_id</b></td>
<td><b>item_count</b></td>
<td><b>dollars</b></td>
</tr>
<tr>
<td align="right">55</td>
<td align="right">20040106</td>
<td>Credit</td>
<td align="right">123</td>
<td align="right">22</td>
<td align="right">3</td>
<td align="right">$3.54</td>
</tr>
<tr>
<td align="right">78</td>
<td align="right">20040106</td>
<td>Cash</td>
<td align="right">89</td>
<td align="right">22</td>
<td align="right">1</td>
<td align="right">$20.00</td>
</tr>
<tr>
<td align="right">199</td>
<td align="right">20040107</td>
<td>ATM</td>
<td align="right">3</td>
<td align="right">22</td>
<td align="right">2</td>
<td align="right">$2.99</td>
</tr>
<tr>
<td align="right">55</td>
<td align="right">20040106</td>
<td>Cash</td>
<td align="right">122</td>
<td align="right">22</td>
<td align="right">1</td>
<td align="right">$1.18</td>
</tr>
</table>
<p>and suppose we created a dimension table for the values in the <code>payment_method</code> column:</p>
<table id="table6" class="grayTable" >
<tr>
<td><b>payment_method</b></td>
</tr>
<tr>
<td>Credit</td>
</tr>
<tr>
<td>Cash</td>
</tr>
<tr>
<td>ATM</td>
</tr>
</table>
<p>This dimension table is fairly pointless. It only has 3 values, adds no additional information,
and incurs the cost of an extra join.</p>
<p>Instead, you can create a degenerate dimension. To do this, declare a dimension without a
table, and Mondrian will assume that the columns come from the fact table.</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px;"><<a href="#XML_Cube">Cube</a> name="Checkout"></div>
<div style="padding-left:40px"><!-- The fact table is always necessary. --></div>
<div style="padding-left:40px"><<a href="#XML_Table">Table</a> name="checkout"></div>
<div style="padding-left:40px"><<a href="#XML_Dimension">Dimension</a> name="Payment method"></div>
<div style="padding-left:60px"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true"></div>
<div style="padding-left:80px"><!-- No table element here. Fact table is assumed. --></div>
<div style="padding-left:80px"><<a href="#XML_Level">Level</a> name="Payment method" column="payment_method" uniqueMembers="true"/></div>
<div style="padding-left:60px"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:40px"></<a href="#XML_Dimension">Dimension</a>></div>
<div style="padding-left:40px"><!-- other dimensions and measures --></div>
<div style="padding-left:20px;"></<a href="#XML_Cube">Cube</a>></div>
</code>
</blockquote>
<p>Note that because there is no join, the <code>foreignKey</code> attribute of
<code>Dimension</code> is not necessary, and the <code>Hierarchy</code>
element has no <code><Table></code> child element or
<code>primaryKey</code> attribute.</p>
<!--
#############################
## 3.3.7 Inline tables #####
############################# -->
<h1>3.3.7 Inline tables<a name="Inline_tables"> </a></h1>
<p>The <code><<a href="#XML_InlineTable">InlineTable</a>></code> construct allows
you to define a dataset in the schema file. You must declare the names of the columns, the column types
("String" or "Numeric"), and a set of rows. As for
<code><<a href="#XML_Table">Table</a>></code> and
<code><<a href="#XML_View">View</a>></code>, you must provide a unique alias with which
to refer to the dataset.</p>
<p>Here is an example:</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px"><<a href="#XML_Dimension">Dimension</a> name="Severity"></div>
<div style="padding-left:40px"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true" primaryKey="severity_id"></div>
<div style="padding-left:60px"><<a href="#XML_InlineTable">InlineTable</a> alias="severity"></div>
<div style="padding-left:80px"><<a href="#XML_ColumnDefs">ColumnDefs</a>></div>
<div style="padding-left:100px"><<a href="#XML_ColumnDef">ColumnDef</a> name="id" type="Numeric"/></div>
<div style="padding-left:100px"><<a href="#XML_ColumnDef">ColumnDef</a> name="desc" type="String"/></div>
<div style="padding-left:80px"></<a href="#XML_ColumnDefs">ColumnDefs</a>></div>
<div style="padding-left:80px"><<a href="#XML_Rows">Rows</a>></div>
<div style="padding-left:100px"><<a href="#XML_Row">Row</a>></div>
<div style="padding-left:120px"><<a href="#XML_Value">Value</a> column="id">1</<a href="#XML_Value">Value</a>></div>
<div style="padding-left:120px"><<a href="#XML_Value">Value</a> column="desc">High</<a href="#XML_Value">Value</a>></div>
<div style="padding-left:100px"></<a href="#XML_Row">Row</a>></div>
<div style="padding-left:100px"><<a href="#XML_Row">Row</a>></div>
<div style="padding-left:120px"><<a href="#XML_Value">Value</a> column="id">2</<a href="#XML_Value">Value</a>></div>
<div style="padding-left:120px"><<a href="#XML_Value">Value</a> column="desc">Medium</<a href="#XML_Value">Value</a>></div>
<div style="padding-left:100px"></<a href="#XML_Row">Row</a>></div>
<div style="padding-left:100px"><<a href="#XML_Row">Row</a>></div>
<div style="padding-left:120px"><<a href="#XML_Value">Value</a> column="id">3</<a href="#XML_Value">Value</a>></div>
<div style="padding-left:120px"><<a href="#XML_Value">Value</a> column="desc">Low</<a href="#XML_Value">Value</a>></div>
<div style="padding-left:100px"></<a href="#XML_Row">Row</a>></div>
<div style="padding-left:80px"></<a href="#XML_Rows">Rows</a>></div>
<div style="padding-left:60px"></<a href="#XML_InlineTable">InlineTable</a>></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Severity" column="id" nameColumn="desc" uniqueMembers="true"/></div>
<div style="padding-left:40px"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:20px"></<a href="#XML_Dimension">Dimension</a>></div>
</code>
</blockquote>
<p>This has the same effect as if you had a table called 'severity' in your database:</p>
<table id="table7" class="grayTable">
<tr>
<td><b>id</b></td>
<td><b>desc</b></td>
</tr>
<tr>
<td>1</td>
<td>High</td>
</tr>
<tr>
<td>2</td>
<td>Medium</td>
</tr>
<tr>
<td>3</td>
<td>Low</td>
</tr>
</table>
<p>and the declaration</p>
<blockquote style="text-indent: -20px">
<code>
<div style="padding-left:20px"><<a href="#XML_Dimension">Dimension</a> name="Severity"></div>
<div style="padding-left:40px"><<a href="#XML_Hierarchy">Hierarchy</a> hasAll="true" primaryKey="severity_id"></div>
<div style="padding-left:60px"><<a href="#XML_InlineTable">Table</a> name="severity"/></div>
<div style="padding-left:60px"><<a href="#XML_Level">Level</a> name="Severity" column="id" nameColumn="desc" uniqueMembers="true"/></div>
<div style="padding-left:40px"></<a href="#XML_Hierarchy">Hierarchy</a>></div>
<div style="padding-left:20px"></<a href="#XML_Dimension">Dimension</a>></div>
</code>
</blockquote>
<p>To specify a NULL value for a column, omit the <code><Value></code>
for that column, and the column's value will default to NULL.</p>
<!--
################################################
## 3.3.8 Member properties and formatters #####
################################################ -->
<h1>3.3.8 Member properties and formatters<a name="Member_properties_and_formatters"> </a></h1>
<p>As we shall see later, a level definition can also define <a href="#Member_properties">member properties</a>
and a <a href="#Member_formatter">member formatter</a>.</p>
<!--
################################################
## 3.3.9 Approximate level cardinality #####
################################################ -->
<h1>3.3.9 Approximate level cardinality<a name="Approximate_level_cardinality"> </a></h1>
<p>The <a
href="#XML_Level"><Level></a> element allows specifying the optional attribute "approxRowCount". Specifying
<code>approxRowCount</code> can improve performance by reducing the need to determine level, hierarchy, and dimension cardinality.
This can have a significant impact when connecting to Mondrian via XMLA.</p>
<!--
################################################
## 3.3.10 Default Measure Attribute #####
################################################ -->
<h1>3.3.10 Default Measure Attribute<a name="Default_Measure_Attribute"> </a></h1>
<p>The <a href="#XML_Cube"><Cube></a> and <a href="#XML_VirtualCube"><VirtualCube></a>
elements allow specifying the optional attribute "defaultMeasure".</p>
<p>Specifying <code>defaultMeasure</code> in <a href="#XML_Cube"><Cube></a> element allows users
to explicitly specify any base measure as a default Measure.</p>
<p>Specifying <code>defaultMeasure</code> in <a href="#XML_VirtualCube"><VirtualCube></a>
element allows users to explicitly specify any VirtualCube Measure as a default Measure.</p>
<p>Note that if a default measure is not specified it takes the first measure defined in the cube as the default measure. In the case of virtual cube,
it would pick up the first base measure of the first cube defined within it as the default.</p>
<p>Specifying the <code>defaultMeasure</code> explicitly would be useful in cases where you would want a calculated member to be picked up as the default measure.
To facilitate this, the calculated member could be defined in one of the base cubes and specified as the <code>defaultMeasure</code> in the virtual cube.</p>