lincoln-lil commented on code in PR #23810:
URL: https://github.com/apache/flink/pull/23810#discussion_r1410076944


##########
flink-table/flink-table-api-java-bridge/src/main/java/org/apache/flink/connector/datagen/table/DataGenConnectorOptionsUtil.java:
##########
@@ -34,6 +34,8 @@ public class DataGenConnectorOptionsUtil {
     public static final String MAX = "max";
     public static final String MAX_PAST = "max-past";
     public static final String LENGTH = "length";
+

Review Comment:
   nit: unnecessary new line here?



##########
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) {

Review Comment:
   nit:  getVariableLengthFieldRealLen -> generateLength(int maxLen, boolean 
varLen) ?



##########
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:
   we can avoid per-call new instance here by using a lazy initialized 
`RandomGenerator` member variable(and it also support lower bound so that `+ 1` 
can be omitted)



-- 
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