Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions src/main/java/generator/RowGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.hadoop.fs.Path;

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class RowGenerator extends Thread {
Expand All @@ -19,18 +20,27 @@ public class RowGenerator extends Thread {
private CreateTable createTableStat;
private String partitionInfo;
private Properties columnProperties = new Properties();
private double distinctProportion = 0.2;
private HashMap<String,Integer> repeateMap;
private ArrayList<String> repeateList;
private Random rd = new Random();

ColumnGenerator partitionGenerator = new ColumnGenerator();
private Properties props = new Properties();
public String targetPath;
public String filesystemHost;
public String createTableSql;
// public double distinctProportion = 0.05;


public RowGenerator(String sql, String path) throws Exception {
this(sql);
this.targetPath = path;
}

public RowGenerator(String sql) throws Exception {
repeateMap = new HashMap<String, Integer>();
repeateList = new ArrayList<String>();
createTableSql = sql;

if (sql.toLowerCase().indexOf("partitioned by") != -1) {
Expand Down Expand Up @@ -65,6 +75,8 @@ public RowGenerator(String sql) throws Exception {

getColumnProperties();

distinctProportion = Double.valueOf(columnProperties.getProperty("user_num.distinct.proportion"));
System.out.println(distinctProportion);
for (ColumnDefinition columnDefinition : createTableStat.getColumnDefinitions()) {
ColumnGenerator cg = new ColumnGenerator(columnDefinition);
String columnName = columnDefinition.getColumnName();
Expand Down Expand Up @@ -122,7 +134,8 @@ public void run() {
br.write(nextRow() + "\n");
}
br.close();
//hdfs.close();
hdfs.close();

} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -135,8 +148,13 @@ public void produceRow() throws Exception {
public String nextRow() {
String output = "";
for (ColumnGenerator cg : cgs) {
output += cg.nextValue();
output += "|";
if (cg.colDesc.getColumnName()=="user_num"){

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, we need all columns to support setting distinct proportion.

output += repeatebysettings(cg);
output += "|";
}else{
output += cg.nextValue();
output += "|";
}
}
return output;
}
Expand All @@ -148,4 +166,28 @@ public void getColumnProperties() throws IOException {
columnProperties.load(fis);
}

public String repeatebysettings(ColumnGenerator cg) {
String str;
if (Math.random() > distinctProportion){
if (repeateList.size() < 1000){
str = cg.nextValue();
repeateMap.put(str,new Double(Math.abs(rd.nextGaussian()*50)).intValue());
repeateList.add(str);
return str;
}else{
int i = rd.nextInt(1000);
str = repeateList.get(i);
if (repeateMap.get(str)==0){
repeateMap.remove(str);
repeateList.remove(i);
}else{
repeateMap.put(str,repeateMap.get(str)-1);
}
return str;
}
}else{
return cg.nextValue();
}
}

}