Skip to content

Commit 5a70277

Browse files
committed
Moved email, gender and language builders to DynamicPersonSerializer
1 parent b6d65f4 commit 5a70277

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

src/main/java/ldbc/snb/datagen/serializer/DynamicPersonSerializer.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4242
import ldbc.snb.datagen.entities.dynamic.relations.WorkAt;
4343
import org.apache.hadoop.conf.Configuration;
4444
import java.io.IOException;
45+
import java.util.ArrayList;
4546
import java.util.Iterator;
47+
import java.util.TreeSet;
4648

4749
/**
4850
* Created by aprat on 10/15/14.
@@ -78,6 +80,36 @@ public void export(final Person p, final Knows k) {
7880
serialize(p, k);
7981
}
8082

83+
public String getGender(int gender) {
84+
if (gender == 1) {
85+
return "male";
86+
} else {
87+
return "female";
88+
}
89+
}
90+
public String buildLanguages(ArrayList<Integer> languages) {
91+
StringBuilder languagesBuilder = new StringBuilder();
92+
for (int i = 0; i < languages.size()-1; i++) {
93+
languagesBuilder.append(Dictionaries.languages.getLanguageName(languages.get(i))+";");
94+
}
95+
if(languages.size() > 0) {
96+
languagesBuilder.append(Dictionaries.languages.getLanguageName(languages.get(languages.size()-1)));
97+
}
98+
return languagesBuilder.toString();
99+
}
100+
101+
public String buildEmail(TreeSet<String> emails) {
102+
StringBuilder emailsBuilder = new StringBuilder();
103+
Iterator<String> itString = emails.iterator();
104+
for (int i = 0; i < emails.size()-1; i++) {
105+
emailsBuilder.append(itString.next()+";");
106+
}
107+
if(itString.hasNext()) {
108+
emailsBuilder.append(itString.next());
109+
}
110+
return emailsBuilder.toString();
111+
}
112+
81113
abstract protected void serialize(final Person p);
82114

83115
abstract protected void serialize(final StudyAt studyAt);

src/main/java/ldbc/snb/datagen/serializer/snb/csv/dynamicserializer/person/CSVCompositeDynamicPersonSerializer.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,11 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4343
import ldbc.snb.datagen.entities.dynamic.person.Person;
4444
import ldbc.snb.datagen.entities.dynamic.relations.StudyAt;
4545
import ldbc.snb.datagen.entities.dynamic.relations.WorkAt;
46-
import ldbc.snb.datagen.hadoop.writer.HDFSCSVWriter;
4746
import ldbc.snb.datagen.serializer.DynamicPersonSerializer;
4847
import ldbc.snb.datagen.serializer.snb.csv.FileName;
49-
import org.apache.hadoop.conf.Configuration;
48+
5049
import static ldbc.snb.datagen.serializer.snb.csv.FileName.*;
51-
import ldbc.snb.datagen.serializer.snb.csv.FileName;
52-
import java.io.IOException;
53-
import java.util.ArrayList;
50+
5451
import java.util.Arrays;
5552
import java.util.Iterator;
5653
import java.util.List;
@@ -78,34 +75,18 @@ public void writeFileHeaders() {
7875

7976
@Override
8077
protected void serialize(final Person p) {
81-
String gender = "";
82-
if (p.gender() == 1) {
83-
gender ="male";
84-
} else {
85-
gender = "female";
86-
}
87-
ArrayList<Integer> languages = p.languages();
88-
StringBuilder languagesBuilder = new StringBuilder();
89-
for (int i = 0; i < languages.size()-1; i++) {
90-
languagesBuilder.append(Dictionaries.languages.getLanguageName(languages.get(i))+";");
91-
}
92-
if(languages.size() > 0) {
93-
languagesBuilder.append(Dictionaries.languages.getLanguageName(languages.get(languages.size()-1)));
94-
}
95-
StringBuilder emailsBuilder = new StringBuilder();
96-
Iterator<String> itString = p.emails().iterator();
97-
for (int i = 0; i < p.emails().size()-1; i++) {
98-
emailsBuilder.append(itString.next()+";");
99-
}
100-
if(itString.hasNext()) {
101-
emailsBuilder.append(itString.next());
102-
}
103-
104-
writers.get(PERSON).writeEntry(ImmutableList.of(Long.toString(p.accountId()),p.firstName(),p.lastName(),
105-
gender,Dictionaries.dates.formatDate(p.birthday()),Dictionaries.dates.formatDateTime(p.creationDate()),
106-
p.ipAddress().toString(),Dictionaries.browsers.getName(p.browserId()),languagesBuilder.toString(),
107-
emailsBuilder.toString()));
10878

79+
writers.get(PERSON).writeEntry(ImmutableList.of(
80+
Long.toString(p.accountId()),
81+
p.firstName(),
82+
p.lastName(),
83+
getGender(p.gender()),
84+
Dictionaries.dates.formatDate(p.birthday()),
85+
Dictionaries.dates.formatDateTime(p.creationDate()),
86+
p.ipAddress().toString(),
87+
Dictionaries.browsers.getName(p.browserId()),
88+
buildLanguages(p.languages()),
89+
buildEmail(p.emails())));
10990

11091
writers.get(PERSON_LOCATED_IN_PLACE).writeEntry(ImmutableList.of(Long.toString(p.accountId()),Integer.toString(p.cityId())));
11192

src/main/java/ldbc/snb/datagen/serializer/snb/csv/dynamicserializer/person/CSVMergeForeignDynamicPersonSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected void serialize(final Person p) {
8181
Long.toString(p.accountId()),
8282
p.firstName(),
8383
p.lastName(),
84-
p.gender() == 1 ? "male" : "female",
84+
getGender(p.gender()),
8585
Dictionaries.dates.formatDate(p.birthday()),
8686
Dictionaries.dates.formatDateTime(p.creationDate()),
8787
p.ipAddress().toString(),

0 commit comments

Comments
 (0)