You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@parquet.apache.org by fo...@apache.org on 2020/02/03 13:57:00 UTC

[parquet-mr] branch master updated: PARQUET-1737: Replace Test Class RandomStr with Apache Commons Lang (#725)

This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git


The following commit(s) were added to refs/heads/master by this push:
     new 1849650  PARQUET-1737: Replace Test Class RandomStr with Apache Commons Lang (#725)
1849650 is described below

commit 184965087fb320d4a5f5849d27b365420a3ef1a0
Author: belugabehr <12...@users.noreply.github.com>
AuthorDate: Mon Feb 3 05:56:51 2020 -0800

    PARQUET-1737: Replace Test Class RandomStr with Apache Commons Lang (#725)
---
 parquet-column/pom.xml                             |  6 +++
 .../apache/parquet/column/values/RandomStr.java    | 51 ----------------------
 .../org/apache/parquet/column/values/Utils.java    | 12 +++--
 3 files changed, 11 insertions(+), 58 deletions(-)

diff --git a/parquet-column/pom.xml b/parquet-column/pom.xml
index b2369b7..3bd3a59 100644
--- a/parquet-column/pom.xml
+++ b/parquet-column/pom.xml
@@ -89,6 +89,12 @@
       <version>${guava.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.9</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/parquet-column/src/test/java/org/apache/parquet/column/values/RandomStr.java b/parquet-column/src/test/java/org/apache/parquet/column/values/RandomStr.java
deleted file mode 100644
index aa3aec3..0000000
--- a/parquet-column/src/test/java/org/apache/parquet/column/values/RandomStr.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.parquet.column.values;
-
-import java.util.Random;
-
-public class RandomStr {
-  private final char[] alphanumeric=alphanumeric();
-  private final Random rand;
-
-  public RandomStr(){this(null);}
-
-  public RandomStr(Random rand){
-    this.rand=(rand!=null) ? rand : new Random();
-  }
-
-  public String get(int len){
-    StringBuffer out=new StringBuffer();
-
-    while(out.length() < len){
-      int idx=Math.abs(( rand.nextInt() % alphanumeric.length ));
-      out.append(alphanumeric[idx]);
-    }
-    return out.toString();
-  }
-
-  // create alphanumeric char array
-  private char[] alphanumeric(){
-    StringBuffer buf=new StringBuffer(128);
-    for(int i=48; i<= 57;i++)buf.append((char)i); // 0-9
-    for(int i=65; i<= 90;i++)buf.append((char)i); // A-Z
-    for(int i=97; i<=122;i++)buf.append((char)i); // a-z
-    return buf.toString().toCharArray();
-  }
-}
diff --git a/parquet-column/src/test/java/org/apache/parquet/column/values/Utils.java b/parquet-column/src/test/java/org/apache/parquet/column/values/Utils.java
index 68e8554..0543eba 100644
--- a/parquet-column/src/test/java/org/apache/parquet/column/values/Utils.java
+++ b/parquet-column/src/test/java/org/apache/parquet/column/values/Utils.java
@@ -21,6 +21,7 @@ package org.apache.parquet.column.values;
 import java.io.IOException;
 import java.util.Random;
 
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.parquet.bytes.ByteBufferInputStream;
 import org.apache.parquet.io.api.Binary;
 
@@ -29,16 +30,13 @@ import org.apache.parquet.io.api.Binary;
  */
 public class Utils {
   private static Random randomLen = new Random();
-  private static RandomStr randomStr = new RandomStr(randomLen);
-  
+
   public static String[] getRandomStringSamples(int numSamples, int maxLength) {
     String[] samples = new String[numSamples];
-    
-    for (int i=0; i < numSamples; i++) {
-      int len = randomLen.nextInt(maxLength);
-      samples[i] = randomStr.get(len);
+    for (int i = 0; i < numSamples; i++) {
+      int maxLen = randomLen.nextInt(maxLength);
+      samples[i] = RandomStringUtils.randomAlphanumeric(0, maxLen);
     }
-    
     return samples;
   }