Wiki source code of 10 Constraints

Version 14.1 by Helena on 2025/05/16 00:20

Show last authors
1 {{box title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 == 10.1 Introduction ==
6
7 A Constraint is a Maintainable Artefact that can be associated to one or more of:
8
9 * Data Structure Definition
10 * Metadata Structure Definition
11 * Dataflow
12 * Metadataflow
13 * Provision Agreement
14 * Metadata Provision Agreement
15 * Data Provider or Metadata Provider (this is restricted to a Release Calendar Constraint)
16 * Simple or Queryable Data Sources
17 * Dataset
18 * Metadataset
19
20 Note that regardless of the Artefact to which the Constraint is associated, it is constraining the contents of code lists in the DSD to which the constrained object is related. This does not apply, of course, to a Metadata/Data Provider as the latter can be associated, via the (Metadata) Provision Agreement, to many MSDs/DSDs. Hence the reason for the restriction on the type of Constraint that can be attached to a Metadata/Data Provider.
21
22 == 10.2 Types of Constraint ==
23
24 The Constraint can be of one of two types:
25
26 * Data constraint
27 * Metadata constraint
28
29 The Data Constraint may serve two different perspectives, depending on the way the latter is retrieved. These are:
30
31 * Allowed constraint
32 * Actual constraint
33
34 The former (allowed – also valid for Metadata Constraint) is specified by a data or metadata provider or consumer for sharing the allowed data and metadata in the context of their DSD or MSD exchanges, e.g., only Monthly data for a specific Dataflow. The latter (actual) is a dynamic Constraint in response to an availability request (only possible for data).
35
36 For Actual Data Constraints, there a few characteristics that are worth noting:
37
38 * They can only be retrieved by the availability requests (as specified in the REST API).
39 * They depend on the data available in an SDMX Web Service and thus they can only be dynamically generated according to that data.
40 * Although they are Maintainable Artefacts, they cannot change independently of data; thus, they cannot be versioned (they are non-versioned, as explained in section 14).
41 * Their identifier may also be dynamically generated and thus there is no REST resource based on their identification.
42
43 == 10.3 Rules for a Constraint ==
44
45 === 10.3.1 Scope of a Constraint ===
46
47 A Constraint is used specify the content of a data or metadata source in terms of the component values or the keys.
48
49 In terms of data the components are:
50
51 * Dimension
52 * Time Dimension
53 * Data Attribute
54 * Measure
55 * Metadata Attribute
56 * DataKeySets: the keys are the content of the KeyDescriptor – i.e., the series keys composed, for each key, by a value for each Dimension.
57
58 In terms of reference metadata the components are:
59
60 * Metadata Attribute
61
62 For a Constraint based on a DSD the Constraint can reference one or more of:
63
64 * Data Structure Definition
65 * Dataflow
66 * Provision Agreement
67 * Data Provider
68
69 For a Constraint based on an MSD the Constraint can reference one or more of:
70
71 * Metadata Structure Definition
72 * Metadataflow
73 * Metadata Provision Agreement
74 * Metadata Provider
75 * Metadata Set
76
77 Furthermore, there can be more than one Constraint specified for a specific object e.g., more than one Constraint for a specific DSD.
78
79 In view of the flexibility of constraints attachment, clear rules on their usage are required. These are elaborated below.
80
81 === 10.3.2 Multiple Constraints ===
82
83 There can be many Constraints for any Constrainable Artefact (e.g., DSD), subject to the following restrictions:
84
85 ==== 10.3.2.1 Cube Region ====
86
87 A Constraint can contain multiple Member Selections (e.g., Dimensions).
88
89 * A specific Member Selection (e.g., Dimension FREQ) can only be contained in one Cube Region for any one attached object (e.g., a specific DSD or specific Dataflow).
90 * Component values within a Member Selection may define a validity period. Otherwise, the value is valid for the whole validity of the Cube Region.
91 * For partial reference resolution purposes (as per the SDMX REST API), the latest non-draft Constraint must be considered.
92 * A Member Selection may include wildcarding of values (using character ‘%’ to represent zero or more occurrences of any character), as well as cascading through hierarchic structures (e.g., parents in Codelist), or localised values (e.g., text for English only). Lack of locale means any language may match. Cascading values are mutual exclusive to localised values, as the former refer to coded values, while the latter refer to uncoded values.
93 * Any values included in a Member Selection for Components with an array data type (i.e., Measures, Attributes or Metadata Attributes), will be applied as single values and will not be assessed combined with other values to match all possible array values. For example, including the Code ‘A’ for an Attribute will allow any instance of the Attribute that includes ‘A’, like [‘A’, ‘B’] or [‘A’, ‘C’, ‘D’]. Similarly, if Code ‘A’ was excluded, all those arrays of values would also be excluded.
94
95 ==== 10.3.2.2 Key Set ====
96
97 Key Sets will be processed in the order they appear in the Constraint and wildcards can be used (e.g., any key position not reference explicitly is deemed to be "all values").
98
99 As the Key Sets can be "included" or "excluded" it is recommended that Key Sets with wildcards are declared before KeySets with specific series keys. This will minimize the risk that keys are inadvertently included or excluded.
100
101 In addition, Attribute, Measure and Metadata Attribute constraints may accompany KeySets, in order to specify the allowed values per Key. Those are expressed following the rules for Cube Regions, as explained above.
102
103 Finally, a validity period may be specified per Key.
104
105 === 10.3.3 Inheritance of a Constraint ===
106
107 ==== 10.3.3.1 Attachment levels of a Constraint ====
108
109 There are three levels of constraint attachment for which these inheritance rules apply:
110
111 • DSD/MSD – top level o Dataflow/Metadataflow – second level
112
113 ▪ Provision Agreement – third level
114
115 Note that these rules do not apply to the Simple Datasource or Queryable Datasource; the Constraint(s) attached to these artefacts are resolved for this artefact only and do not take into account Constraints attached to other artefacts (e.g., Provision Agreement, Dataflow, DSD).
116
117 It is not necessary for a Constraint to be attached to a higher level artefact. e.g., it is valid to have a Constraint for a Provision Agreement where there are no constraints attached the relevant dataflow or DSD.
118
119 ==== 10.3.3.2 Cascade rules for processing Constraints ====
120
121 The processing of the constraints on either Dataflow/Metadataflow or Provision Agreement must take into account the constraints declared at higher levels. The rules for the lower-level constraints (attached to Dataflow/ Metadataflow and Provision Agreement) are detailed below.
122
123 Note that there can be a situation where a constraint is specified at a lower level before a constraint is specified at a higher level. Therefore, it is possible that a higher-level constraint makes a lower-level constraint invalid. SDMX makes no rules on how such a conflict should be handled when processing the constraint for attachment. However, the cascade rules on evaluating constraints for usage are clear – the higher-level constraint takes precedence in any conflicts that result in a less restrictive specification at the lower level.
124
125 ==== 10.3.3.3 Cube Region ====
126
127 It is not necessary to have a Constraint on the higher-level artefact (e.g., DSD referenced by the Dataflow), but if there is such a Constraint at the higher level(s) then:
128
129 * The lower-level Constraint cannot be less restrictive than the Constraint specified for the same Member Selection (e.g. Dimension) at the next higher level, which constrains that Member Selection. For example, if the Dimension FREQ is constrained to A, Q in a DSD, then the Constraint at the Dataflow or Provision Agreement cannot be A, Q, M or even just M – it can only further constrain A, Q.
130 * The Constraint at the lower level for any one Member Selection further constrains the content for the same Member Selection at the higher level(s).
131 * Any Member Selection, which is not referenced in a Constraint, is deemed to be constrained according to the Constraint specified at the next higher level which constraints that Member Selection.
132 * If there is a conflict when resolving the Constraint in terms of a lower-level Constraint being less restrictive than a higher-level Constraint, then the Constraint at the higher-level is used.
133
134 Note that it is possible for a Constraint at a higher level to constrain, say, four Dimensions in a single Constraint, and a Constraint at a lower level to constrain the same four in two, three, or four Constraints.
135
136 ==== 10.3.3.4 Key Set ====
137
138 It is not necessary to have a Constraint on the higher-level artefact (e.g., DSD referenced by the Dataflow), but if there is such a Constraint at the higher level(s) then:
139
140 * The lower-level Constraint cannot be less restrictive than the Constraint specified at the higher level.
141 * The Constraint at the lower level for any one Member Selection further constrains the keys specified at the higher level(s).
142 * Any Member Selection, which is not referenced in a Constraint, is deemed to be constrained according to the Constraint specified at the next higher level which constraints that Member Selection.
143 * If there is a conflict when resolving the keys in the Constraint at two levels, in terms of a lower-level constraint being less restrictive than a higher-level Constraint, then the offending keys specified at the lower level are not deemed part of the Constraint.
144
145 Note that a Key in a Key Set can have wildcarded Components. For instance, the Constraint may simply constrain the Dimension FREQ to "A", and all keys where the FREQ="A" are therefore valid.
146
147 The following logic explains how the inheritance mechanism works. Note that this is conceptual logic and actual systems may differ in the way this is implemented.
148
149 *
150 *1. Determine all possible keys that are valid at the higher level.
151 *1. These keys are deemed to be inherited by the lower-level constrained object, subject to the Constraints specified at the lower level.
152 *1. Determine all possible keys that are possible using the Constraints specified at the lower level.
153 *1. At the lower level inherit all keys that match with the higher-level Constraint.
154 *1. If there are keys in the lower-level Constraint that are not inherited then the key is invalid (i.e., it is less restrictive).
155
156 === 10.3.4 Constraints Examples ===
157
158 ==== 10.3.4.1 Data Constraint and Cascading ====
159
160 The following scenario is used.
161
162 A DSD contains the following Dimensions:
163
164 * GEO – Geography
165 * SEX – Sex
166 * AGE – Age
167 * CAS – Current Activity Status
168
169 In the DSD, common code lists are used and the requirement is to restrict these at various levels to specify the actual code that are valid for the object to which the Constraint is attached.
170
171 [[image:SDMX 3-0-0 SECTION 6 FINAL-1.0_en_77bea5e.png||height="344" width="554"]]
172
173 **Figure 20: Example Scenario for Constraints **
174
175 Constraints are declared as follows:
176
177 [[image:SDMX 3-0-0 SECTION 6 FINAL-1.0_en_7c36c475.png||height="356" width="541"]]
178
179 **Figure 21: Example Constraints**
180
181 Notes:
182
183 AGE is constrained for the DSD and is further restricted for the Dataflow CENSUS_CUBE1.
184
185 * The same Constraint applies to both Provision Agreements.
186
187 The cascade rules elaborated above result as follows:
188
189 DSD
190
191 * Constrained by eliminating code 001 from the code list for the AGE Dimension.
192
193 Dataflow CENSUS_CUBE1
194
195 * Constrained by restricting the code list for the AGE Dimension to codes 002 and 003 (note that this is a more restrictive constraint than that declared for the DSD which specifies all codes except code 001).
196 ** Restricts the CAS codes to 003 and 004.
197
198 Dataflow CENSUS_CUBE2
199
200 * Restricts the code list for the CAS Dimension to codes TOT and NAP.
201 ** Inherits the AGE constraint applied at the level of the DSD.
202
203 Provision Agreement CENSUS_CUBE1_IT
204
205 * Restricts the codes for the GEO Dimension to IT and its children.
206 ** Inherits the constraints from Dataflow CENSUS_CUBE1 for the AGE and CAS Dimensions.
207
208 Provision Agreement CENSUS_CUBE2_IT
209
210 * Restricts the codes for the GEO Dimension to IT and its children.
211 ** Inherits the constraints from Dataflow CENSUS_CUBE2 for the CAS Dimension.
212 ** Inherits the AGE constraint applied at the level of the DSD.
213
214 The Constraints are defined as follows:
215
216 DSD Constraint
217
218 **<str:DataConstraint agencyID="SDMX" id="DATA_CONSTRAINT" version="1.0.0draft" type="Allowed">**
219
220 **<com:Name xml:lang="en">SDMX 3.0 Data Constraint sample</com:Name>**
221
222 **<str:ConstraintAttachment>**
223
224 **<str:DataStructure>urn:sdmx:org.sdmx.infomodel.datastructure.**
225
226 **DataStructure=CENSUSHUB:CENSUS(1.0.0)</str:DataStructure>**
227
228 **</str:ConstraintAttachment>**
229
230 **<str:CubeRegion include="true">**
231
232 **<!~-~- the ability to exclude values is illustrated – i.e., all values valid except this one ~-~->**
233
234 **<com:KeyValue id="AGE" include="false">**
235
236 **<com:Value>001</com:Value>**
237
238 **</com:KeyValue>**
239
240 **</str:CubeRegion>**
241
242 **</str:DataConstraint>**
243
244 Dataflow Constraints
245
246 **<str:DataConstraint agencyID="SDMX" id="DATA_CONSTRAINT_2" version="1.0.0draft" type="Allowed">**
247
248 **<com:Name xml:lang="en">SDMX 3.0 Data Constraint sample</com:Name>**
249
250 **<str:ConstraintAttachment>**
251
252 **<str:Dataflow>urn:sdmx:org.sdmx.infomodel.datastructure.Dataflow=**
253
254 **CENSUSHUB:CENSUS_CUBE1(1.0.0)</str:Dataflow>**
255
256 **</str:ConstraintAttachment>**
257
258 **<str:CubeRegion include="true">**
259
260 **<com:KeyValue id="AGE" include="true">**
261
262 **<com:Value>002</com:Value>**
263
264 **<com:Value>003</com:Value>**
265
266 **</com:KeyValue>**
267
268 **<com:KeyValue id="CAS">**
269
270 **<com:Value>003</com:Value>**
271
272 **<com:Value>004</com:Value>**
273
274 **</com:KeyValue>**
275
276 **</str:CubeRegion>**
277
278 **</str:DataConstraint>**
279
280 **<str:DataConstraint agencyID="SDMX" id="DATA_CONSTRAINT_3" version="1.0.0draft" type="Allowed">**
281
282 **<com:Name xml:lang="en">SDMX 3.0 Data Constraint sample</com:Name>**
283
284 **<str:ConstraintAttachment>**
285
286 **<str:Dataflow>urn:sdmx:org.sdmx.infomodel.datastructure.Dataflow=**
287
288 **CENSUSHUB:CENSUS_CUBE2(1.0.0)</str:Dataflow>**
289
290 **</str:ConstraintAttachment>**
291
292 **<str:CubeRegion include="true">**
293
294 **<com:KeyValue id="CAS" include="true">**
295
296 **<com:Value>TOT</com:Value>**
297
298 **<com:Value>NAP</com:Value>**
299
300 **</com:KeyValue>**
301
302 **</str:CubeRegion>**
303
304 **</str:DataConstraint>**
305
306 Provision Agreement Constraint
307
308 **<str:DataConstraint agencyID="SDMX" id="DATA_CONSTRAINT_4" version="1.0.0draft" type="Allowed">**
309
310 **<com:Name xml:lang="en">SDMX 3.0 Data Constraint sample</com:Name>**
311
312 **<str:ConstraintAttachment>**
313
314 **<str:ProvisionAgreement>urn:sdmx:org.sdmx.infomodel.registry.**
315
316 **ProvisionAgreement=CENSUSHUB:CENSUS_CUBE1_IT(1.0.0)**
317
318 **</str:ProvisionAgreement>**
319
320 **<str:ProvisionAgreement>urn:sdmx:org.sdmx.infomodel.registry.**
321
322 **ProvisionAgreement=CENSUSHUB:CENSUS_CUBE2_IT(1.0.0)**
323
324 **</str:ProvisionAgreement>**
325
326 **</str:ConstraintAttachment>**
327
328 **<str:CubeRegion include="true">**
329
330 **<com:KeyValue id="GEO" include="true">**
331
332 **<com:Value cascadeValues="true">IT</com:Value>**
333
334 **</com:KeyValue>**
335
336 **</str:CubeRegion>**
337
338 **</str:DataConstraint**
339
340 ==== 10.3.4.2 Combination of Constraints ====
341
342 The possible combination of constraining terms are explained in this section, following a few examples.
343
344 Let’s assume a DSD with the following Components:
345
346 |Dimension|FREQ
347 |Dimension|JD_TYPE
348 |Dimension|JD_CATEGORY
349 |Dimension|VIS_CTY
350 |TimeDimension|TIME_PERIOD
351 |Attribute|OBS_STATUS
352 |Attribute|UNIT
353 |Attribute|COMMENT
354 |MetadataAttribute|CONTACT
355 |Measure|MULTISELECT
356 |Measure|CHOICE
357
358 On the above, let’s assume the following use cases with their constraining requirements:
359
360 ===== 10.3.4.2.1 Use Case 1: A Constraint on allowed values for some Dimensions =====
361
362 R1: Allow monthly and quarterly data
363
364 R2: Allow Mexico for vis-à-vis country
365
366 This is expressed with the following CubeRegion:
367
368 |FREQ|M, Q
369 |VIS_CTY|MX
370
371 ===== 10.3.4.2.2 Use Case 2: A Constraint on allowed combinations for some Dimensions =====
372
373 R1: Allow monthly data for Germany
374
375 R2: Allow quarterly data for Mexico
376
377 This is expressed with the following DataKeySet:
378
379 |(% rowspan="2" %)Key1|FREQ|M
380 |VIS_CTY|DE
381 |(% rowspan="2" %)Key2|FREQ|Q
382 |VIS_CTY|MX
383
384 ===== 10.3.4.2.3 Use Case 3: A Constraint on allowed values for some Dimensions combined with allowed values for some Attributes =====
385
386 R1: Allow monthly and quarterly data
387
388 R2: Allow Mexico for vis-à-vis country
389
390 R3: Allow present for status
391
392 This may be expressed with the following CubeRegion:
393
394 |FREQ|M, Q
395 |VIS_CTY|MX
396 |OBS_STATUS|A
397
398 ===== 10.3.4.2.4 Use Case 4: A Constraint on allowed combinations for some =====
399
400 //**Dimensions combined with specific Attribute values**//
401
402 R1: Allow monthly data, for Germany, with unit euro
403
404 R2: Allow quarterly data, for Mexico, with unit usd
405
406 This is may be expressed with the following DataKeySet:
407
408 |(% rowspan="3" style="width:87px" %)Key1|(% style="width:1327px" %)FREQ|M
409 |(% style="width:1327px" %)VIS_CTY|DE
410 |(% style="width:1327px" %)UNIT|EUR
411 |(% rowspan="3" style="width:87px" %)Key2|(% style="width:1327px" %)FREQ|Q
412 |(% style="width:1327px" %)VIS_CTY|MX
413 |(% style="width:1327px" %)UNIT|USD
414
415 ===== 10.3.4.2.5 Use Case 5: A Constraint on allowed values for some Dimensions together with some combination of Dimension values =====
416
417 R1: For annually and quarterly data, for Mexico and Germany, only A status is allowed
418
419 R2: For monthly data, for Mexico and Germany, only F status is allowed
420
421 Considering the above examples, the following CubeRegions would be created:
422
423 |(% rowspan="3" %)CubeRegion1|FREQ|Q, A
424 |VIS_CTY|MX, DE
425 |OBS_STATUS|A
426 |(% rowspan="3" %)CubeRegion2|FREQ|M
427 |VIS_CTY|MX, DE
428 |OBS_STATUS|F
429
430 The problem with this approach is that according to the business rule for Constraints, only one should be specified per Component. Thus, if a software would perform some conflict resolution would end up with empty sets for FREQ and OBS_STATUS (as they do not share any values).
431
432 Nevertheless, there is a much easier approach to that; this is the cascading mechanism of Constraints (as shown in 10.3.4.1). Hence, these rules would be expressed into two levels of Constraints, e.g., DSD and Dataflows:
433
434 DSD CubeRegion:
435
436 |FREQ|M, Q, A
437 |VIS_CTY|MX, DE
438 |OBS_STATUS|A, F
439
440 Dataflow1 CubeRegion:
441
442 |FREQ|Q, A
443 |VIS_CTY|MX, DE
444 |OBS_STATUS|F
445
446 Dataflow2 CubeRegion:
447
448 |FREQ|M
449 |VIS_CTY|MX, DE
450 |OBS_STATUS|A
451
452 ===== 10.3.4.2.6 Use case 6: A Constraint on allowed values for some Dimensions combined with allowed values for Measures =====
453
454 R1: Allow monthly data, for Germany, with unit euro, and measure choice is 'A'
455
456 R2: Allow quarterly data, for Mexico, with unit usd, and measure choice is 'B' This is may be expressed with the following DataKeySet:
457
458 |(% rowspan="4" %)Key1|FREQ|M
459 |VIS_CTY|DE
460 |UNIT|EUR
461 |CHOICE|A
462 |(% rowspan="4" %)Key2|FREQ|Q
463 |VIS_CTY|MX
464 |UNIT|USD
465 |CHOICE|B
466
467 ===== 10.3.4.2.7 Use Case 7: A Constraint with wildcards for Codes and removePrefix property =====
468
469 For this example, we assume that the VIS_CTY representation has been prefixed with prefix ‘AREA_’. In this Constraint, we need to remove the prefix.
470
471 R1: Allow monthly and quarterly data
472
473 R2: Allow vis-à-vis countries that start with M
474
475 R3: Remove the prefix ‘AREA_’
476
477 This may be expressed with the following CubeRegion:
478
479 |FREQ|M, Q
480 |VIS_CTY (removePrefix=’AREA_’)|M%
481
482 ===== 10.3.4.2.8 Use Case 8: A Constraint with multilingual support on Attributes =====
483
484 R1: Allow monthly and quarterly data
485
486 R2: Allow Mexico for vis-à-vis country
487
488 R3: Allow a comment, in English, which includes the term adjusted for status
489
490 This may be expressed with the following CubeRegion:
491
492 |FREQ|M, Q
493 |VIS_CTY|MX
494 |COMMENT (lang=’en’)|%adjusted%
495
496 ===== 10.3.4.2.9 Use Case 9: A Constraint on allowed values for Dimensions combined with allowed values for Metadata Attributes =====
497
498 R1: Allow monthly and quarterly data
499
500 R2: Allow Mexico for vis-à-vis country
501
502 R3: Allow John Doe for contact
503
504 This may be expressed with the following CubeRegion:
505
506 |FREQ|M, Q
507 |VIS_CTY|MX
508 |CONTACT|John Doe
509
510 ==== 10.3.4.3 Other constraining terms ====
511
512 Beyond the cube regions and keysets, there is one more constraining term, i.e., the ReleaseCalendar.
513
514 The ReleaseCalendar is the only term that does not apply on Components; it specifies the schedule of publication or reporting of the dataset or metadataset.
515
516 For example, the ReleaseCalendar for Provider BIS, is specified in the three following terms:
517
518 * Periodicity: how often data should be reported, e.g., monthly
519 * Offset: the number of days between the 1^^st^^ of January and the first release of data, e.g., 10 days
520 * Tolerance: the maximum allowed of days that data may be considered, without being considered as late, e.g., 5 days
521
522 With the above terms, BIS would need to report data between the 10^^th^^ and 15^^th^^ of every month.
523
524 NOTE: The SDMX 2.1 constraining term ReferencePeriod has been deprecated in SDMX 3.0; thus, the TimeDimension and any Dimension with a time Representation can be constrained within a CubeRegion or MetadataTargetRegion, using the TimeRangeValue.