Skip to content

Commit 54a115a

Browse files
authored
Support for arrays in generated documents. (#35)
1 parent 7568d13 commit 54a115a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ Currently supported field types are:
142142
given list of `-` seperated words, the words are optional defaulting to
143143
`text1` `text2` and `text3`, min and max are optional, defaulting to `1`
144144
and `1`
145+
- `arr:[array_length_expression]:[single_element_format]` an array of entries
146+
with format specified by `single_element_format`. `array_length_expression`
147+
can be either a single number, or pair of numbers separated by `-` (i.e. 3-7),
148+
defining range of lengths from with random length will be picked for each array
149+
(Example `int_array:arr:1-5:int:1:250`)
150+
145151
146152
## Todo
147153

Diff for: es_test_data.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,21 @@ def get_data_for_format(format):
9292

9393
return_val = ''
9494

95-
if field_type == "bool":
95+
if field_type == 'arr':
96+
return_val = []
97+
array_len_expr = split_f[2]
98+
if '-' in array_len_expr:
99+
(min,max) = array_len_expr.split('-')
100+
array_len = generate_count(int(min), int(max))
101+
else:
102+
array_len = int(array_len_expr)
103+
104+
single_elem_format = field_name + ':' + format[len(field_name) + len(field_type) + len(array_len_expr) + 3 : ]
105+
for i in range(array_len):
106+
x = get_data_for_format(single_elem_format)
107+
return_val.append(x[1])
108+
109+
elif field_type == "bool":
96110
return_val = random.choice([True, False])
97111

98112
elif field_type == "str":

0 commit comments

Comments
 (0)