[SERVER-68385] Implement random generator of arrays Created: 28/Jul/22  Updated: 29/Oct/23  Resolved: 16/Aug/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.1.0-rc0

Type: Task Priority: Major - P3
Reporter: Alexander Ignatyev Assignee: Ruoxin Xu
Resolution: Fixed Votes: 0
Labels: M3
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: QO 2022-08-22
Participants:

 Description   

It should support recursive generation of arrays e.g. generates arrays of arrays. It should leverage existing infrastructure of random generators in Cost Model project defined in random_generator.py.

Possible design:

class ArrayRandomDistribution (RandomDistribution):
   def __init__(self, lengths_distr: RandomDistribution, value_distr: RandomDistribution):
       """ArrayRandomDistribution inherits RandomDistribution, therefore, it allows recursive arrays generation since value_distr can be ArrayRandomDistribution or DocumentRandomDistribution"""
       self.lengths_distr = lengths_distr
       self.value_distr = value_distr
 
   def generate(self, size: int):
      arrays = []
      lengths = self.lengths_distr.generate(size)
      for length in lengths:
         values = self.value_distr.generate(length)
         arrays.append(values)
      return arrays

Example of generating arrays of arrays of strings:

internal_length_distribution = RandomDistribution.normal(RangeGenerator(DataType.INT, 10, 25))
internal_values_distribution = RandomDistribution.uniform(RangeGenerator(DataType.STRING, "abc", "zzzz"))
 
internal_array_distribution = ArrayRandomDistribution(internal_length_distribution, internal_values_distribution)
 
length_distribution = RandomDistribution.choice(values=[10, 20], weights=[50, 50])
array_distribution = RandomDistribution.array(length_distribution , internal_array_distribution)


Generated at Thu Feb 08 06:10:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.