Zum Inhalt

Element <array>

Zweck: Erzeugt ein wiederholtes Array aus einer literalen Wertemenge oder einer skriptbasierten Quelle.

Warum: Verwende dieses Element für eine homogene Sammlung skalarer Werte aus Literalen, einem Skript oder einer typisierten Anzahl.

Beispiel

1
<array name="items" type="string" count="1"/>

Entscheidungshilfe

Fachlicher Nutzen: Drückt eine homogene skalare Sammlung als ein Feld im Produktvertrag aus.

  • Verwenden, wenn

    • Wenn alle Einträge denselben skalaren Typ besitzen oder aus einem wiederholten Ausdruck stammen.
  • Anderen Ansatz wählen, wenn

    • Wenn Einträge unterschiedliche Strukturen besitzen oder verschachtelte fachliche Datensätze enthalten.
  • Voraussetzungen

    • Wähle eine literale, skriptbasierte oder gezählte Array-Strategie.
  • Alternativen

    • Verwende list für heterogene oder bedingte Einträge. (Siehe: <list>)
    • Verwende nestedKey für wiederholte strukturierte Datensätze. (Siehe: <nestedKey>)

Vollständige Beispiele

Verschachtelte Objekte, bedingte Listen, Arrays und Zweige zusammensetzen

Verwende diese Form, wenn ein deterministisches Produkt verschachtelte Datensätze, heterogene Listeneinträge, Literal-Arrays und exklusive Felder kombiniert.

structured-profile/datamimic.xml
 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
<setup rngSeed="42" numProcess="1">
    <generate name="profiles" count="3" target="LogExporter">
        <key name="id" generator="IncrementGenerator"/>
        <nestedKey name="address" type="dict">
            <key name="city" constant="Berlin"/>
            <key name="postal_code" constant="10115"/>
        </nestedKey>
        <list name="contacts" converter="RemoveNoneOrEmptyElement">
            <item>
                <key name="channel" constant="email"/>
                <key name="value" script="'customer-' + str(id) + '@example.test'"/>
            </item>
            <item condition="id % 2 == 0">
                <key name="channel" constant="sms"/>
                <key name="value" script="'+49-30-' + str(100000 + id)"/>
            </item>
        </list>
        <array name="roles" type="literal">
            <value constant="customer"/>
            <value constant="newsletter"/>
        </array>
        <condition>
            <if condition="id == 1">
                <key name="segment" constant="new"/>
            </if>
            <else-if condition="id == 2">
                <key name="segment" constant="active"/>
            </else-if>
            <else>
                <key name="segment" constant="loyal"/>
            </else>
        </condition>
    </generate>
</setup>

Regeln und ungültige Kombinationen

script darf nicht mit type oder count kombiniert werden.

Attribute: script, type, count

Warum: Das Skript liefert das vollständige Array; ein zusätzlicher Elementtyp oder Wiederholungszähler wäre mehrdeutig.

Gültige Kombination
1
<array name="scores" script="[10, 20, 30]"/>
Ungültige Kombination
1
<array name="scores" script="[10, 20, 30]" type="int"/>
Ein Array ohne script erfordert sowohl type als auch count.

Attribute: type, count, script

Warum: Ohne Skript benötigt DataMimic den skalaren Typ und die Anzahl der zu wiederholenden Kindwerte.

Gültige Kombination
1
<array name="scores" type="int" count="3"/>
Ungültige Kombination
1
<array name="scores" type="int"/>
type='literal' lehnt script und count ab.

Attribute: type, script, count

Warum: Ein literales Array erhält seinen stabilen Inhalt aus geordneten -Kindelementen.

Gültige Kombination
1
<array name="channels" type="literal"/>
Ungültige Kombination
1
<array name="channels" type="literal" count="2"/>
I611 — Parser Array Subelements Not Allowed

Element '{name}' does not accept sub-elements unless type is '{data_type}'

Warum: An error occurred during descriptor parsing.

Lösung: Review the configuration and retry.

Vollständige Regel

I612 — Parser Array Literal Empty

Literal array '{name}' must define at least one element

Warum: The configuration violates the requirement that Literal array '{name}' must define at least oneelement.

Lösung: Provide a non-empty configuration and retry.

Vollständige Regel

I613 — Parser Array Value Invalid

Failed while parsing attributes of element <{child_tag}> inside '{name}': {details}

Warum: The system failed while parsing attributes of element <{child_tag}> inside '{name}': {details}.

Lösung: Correct the configuration to a valid value or configuration.

Vollständige Regel

I804 — Task Array Script Element Type

Failed while evaluate script '{script}' of '{name}': expect array element datatypes in ({valid_types}), but got invalid datatype '{element_type}'

Warum: The system failed while evaluate script '{script}' of '{name}': expect array element datatypesin({valid_types}), but got invalid datatype '{element_type}'.

Lösung: Review the configuration and retry.

Vollständige Regel

I805 — Task Array Script Mixed Types

Failed while evaluate script '{script}' of '{name}': all elements in list must be the same data type

Warum: The system failed while evaluate script '{script}' of '{name}': all elements in list must be thesamedata type.

Lösung: Review the configuration and retry.

Vollständige Regel

I806 — Task Array Script Not List

expect datatype list of evaluated script '{script}' of '{name}', but got invalid datatype '{value_type}'

Warum: A value expected to be a list was not a list in the task configuration.

Lösung: Provide a list value for the script.

Vollständige Regel

Erlaubte Elternelemente / Erlaubte Kindelemente

Erlaubte Elternelemente: else, else-if, generate, if, item, iterate, nestedKey, while

Erlaubte Kindelemente:

value

Attribute

Alle 4 Attribute anzeigen

count

Number of elements in the array.

optional; integer; Standardwert: null.

name

Name of the array.

erforderlich; string.

script

Script for generating array elements.

optional; string; Standardwert: null.

type

Data type of the array.

optional; string; Standardwert: null; Werte: string, int, float, bool, literal.