3333import java .time .LocalDate ;
3434import java .time .LocalDateTime ;
3535import java .time .OffsetDateTime ;
36+ import java .time .ZoneOffset ;
3637import java .util .ArrayList ;
3738import java .util .HashMap ;
3839import java .util .HashSet ;
4546
4647public class RandomRecordGenerator {
4748
49+ private static final LocalDate BASE_DATE = LocalDate .of (2026 , 1 , 1 );
50+ private static final LocalDateTime BASE_LOCAL_DATE_TIME =
51+ LocalDateTime .of (2026 , 1 , 1 , 12 , 0 , 0 , 123_456_000 );
52+ private static final OffsetDateTime BASE_OFFSET_DATE_TIME =
53+ OffsetDateTime .of (BASE_LOCAL_DATE_TIME , ZoneOffset .UTC );
54+
4855 private final Random random ;
4956
5057 private final Schema primary ;
@@ -120,7 +127,6 @@ public List<Record> scatter(int[] primaries) {
120127
121128 public Record randomRecord (int primaryValue ) {
122129 Record record = GenericRecord .create (schema );
123- Random random = new Random ();
124130 List <Types .NestedField > columns = schema .columns ();
125131 Map <Integer , Object > partitionValue = null ;
126132 if (partitionValues != null ) {
@@ -148,7 +154,6 @@ public Record randomRecord(int primaryValue) {
148154
149155 public Record randomRecord () {
150156 Record record = GenericRecord .create (schema );
151- Random random = new Random ();
152157 List <Types .NestedField > columns = schema .columns ();
153158 Map <Integer , Object > partitionValue = null ;
154159 if (partitionValues != null ) {
@@ -170,7 +175,7 @@ private Object generateObject(Type type) {
170175 case INTEGER :
171176 return random .nextInt ();
172177 case STRING :
173- return UUID . randomUUID ( ).toString ();
178+ return new UUID ( random . nextLong (), random . nextLong () ).toString ();
174179 case LONG :
175180 return random .nextLong ();
176181 case FLOAT :
@@ -180,13 +185,17 @@ private Object generateObject(Type type) {
180185 case BOOLEAN :
181186 return random .nextBoolean ();
182187 case DATE :
183- return LocalDate . now () .minusDays (random .nextInt (10000 ));
188+ return BASE_DATE .minusDays (random .nextInt (10000 ));
184189 case TIMESTAMP :
185190 Types .TimestampType timestampType = (Types .TimestampType ) type ;
186191 if (timestampType .shouldAdjustToUTC ()) {
187- return OffsetDateTime .now ().minusDays (random .nextInt (10000 ));
192+ return BASE_OFFSET_DATE_TIME
193+ .minusDays (random .nextInt (10000 ))
194+ .plusNanos (random .nextInt (1_000_000 ) * 1_000L );
188195 } else {
189- return LocalDateTime .now ().minusDays (random .nextInt (10000 ));
196+ return BASE_LOCAL_DATE_TIME
197+ .minusDays (random .nextInt (10000 ))
198+ .plusNanos (random .nextInt (1_000_000 ) * 1_000L );
190199 }
191200 case DECIMAL :
192201 Types .DecimalType decimalType = (Types .DecimalType ) type ;
0 commit comments