liyubin117 commented on code in PR #23810:
URL: https://github.com/apache/flink/pull/23810#discussion_r1410156944


##########
flink-table/flink-table-api-java-bridge/src/main/java/org/apache/flink/connector/datagen/table/RandomGeneratorVisitor.java:
##########
@@ -503,10 +524,14 @@ private static RandomGenerator<byte[]> 
getRandomBytesGenerator(int length) {
         return new RandomGenerator<byte[]>() {
             @Override
             public byte[] next() {
-                byte[] arr = new byte[length];
+                byte[] arr = new byte[getVariableLengthFieldRealLen(length, 
varLen)];
                 random.getRandomGenerator().nextBytes(arr);
                 return arr;
             }
         };
     }
+
+    private static int getVariableLengthFieldRealLen(int length, boolean 
varLen) {
+        return varLen ? (new Random().nextInt(length)) + 1 : length;

Review Comment:
   What about using static ThreadLocalRandom.current() provided by java instead 
of per-call new instance? I found that DecimalDataRandomGenerator#next also 
uses such method to generate random data.
   ```
       public DecimalData next() {
           if (nullRate == 0f || ThreadLocalRandom.current().nextFloat() > 
nullRate) {
               BigDecimal decimal =
                       new BigDecimal(
                               ThreadLocalRandom.current().nextDouble(min, max),
                               new MathContext(precision, RoundingMode.DOWN));
               return DecimalData.fromBigDecimal(decimal, precision, scale);
           }
           return null;
       }
   ```



-- 
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-unsubscr...@flink.apache.org

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

Reply via email to