You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/09/20 13:31:48 UTC

[GitHub] [avro] clesaec commented on a diff in pull request #1867: AVRO-3611: fix generator

clesaec commented on code in PR #1867:
URL: https://github.com/apache/avro/pull/1867#discussion_r975369045


##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
 
   private static final Charset UTF8 = StandardCharsets.UTF_8;
 
+  private int randomInt(Random random, LogicalType type) {
+    if (type instanceof LogicalTypes.TimeMillis) {
+      return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);

Review Comment:
   constant added & use



##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
 
   private static final Charset UTF8 = StandardCharsets.UTF_8;
 
+  private int randomInt(Random random, LogicalType type) {
+    if (type instanceof LogicalTypes.TimeMillis) {
+      return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);
+    }
+    // LogicalTypes.Date LocalDate.MAX.toEpochDay() > Integer.MAX;
+    return random.nextInt();
+  }
+
+  private long randomLong(Random random, LogicalType type) {
+    if (type instanceof LogicalTypes.TimeMicros) {
+      return ThreadLocalRandom.current().nextLong(Duration.ofDays(1).toMillis() * 1000L);

Review Comment:
   constant reused



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org