Skip to content

Commit 70ab40e

Browse files
committed
Refactored the static serializer, fixed compile errors in the empty and turtle serializers
1 parent 33da13f commit 70ab40e

File tree

6 files changed

+77
-285
lines changed

6 files changed

+77
-285
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4949
*/
5050
abstract public class StaticSerializer extends LDBCSerializer {
5151

52-
abstract public void reset();
53-
5452
public void export(final TagClass tagclass) {
5553
serialize(tagclass);
5654
}
@@ -67,15 +65,12 @@ public void export(final Tag tag) {
6765
serialize(tag);
6866
}
6967

70-
abstract public void initialize(Configuration conf, int reducerId) throws IOException;
71-
72-
abstract public void close();
73-
7468
abstract protected void serialize(final Place place);
7569

7670
abstract protected void serialize(final Organisation organisation);
7771

7872
abstract protected void serialize(final TagClass tagClass);
7973

8074
abstract protected void serialize(final Tag tag);
75+
8176
}

src/main/java/ldbc/snb/datagen/serializer/empty/EmptyStaticSerializer.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ public void writeFileHeaders() {
6060

6161
}
6262

63-
@Override
64-
public void initialize(Configuration conf, int reducerId) {
65-
//Intentionally left empty
66-
}
67-
68-
@Override
69-
public void close() {
70-
//Intentionally left empty
71-
72-
}
73-
7463
@Override
7564
protected void serialize(final Place place) {
7665
//Intentionally left empty
@@ -95,9 +84,4 @@ protected void serialize(final Tag tag) {
9584

9685
}
9786

98-
@Override
99-
public void reset() {
100-
//Intentionally left empty
101-
102-
}
10387
}

src/main/java/ldbc/snb/datagen/serializer/snb/csv/dynamicserializer/activity/CSVCompositeDynamicActivitySerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
3838
/**
3939
* @author aprat
4040
*/
41-
public class CSVCompositeDynamicActivitySerializer extends CSVDynamicActivitySerializer { }
41+
public class CSVCompositeDynamicActivitySerializer extends CSVDynamicActivitySerializer { }

src/main/java/ldbc/snb/datagen/serializer/snb/csv/staticserializer/CSVMergeForeignStaticSerializer.java

Lines changed: 35 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -35,164 +35,75 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
3535
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
3636
package ldbc.snb.datagen.serializer.snb.csv.staticserializer;
3737

38+
import com.google.common.collect.ImmutableList;
3839
import ldbc.snb.datagen.dictionary.Dictionaries;
3940
import ldbc.snb.datagen.entities.statictype.Organisation;
41+
import ldbc.snb.datagen.entities.statictype.TagClass;
4042
import ldbc.snb.datagen.entities.statictype.place.Place;
4143
import ldbc.snb.datagen.entities.statictype.tag.Tag;
42-
import ldbc.snb.datagen.entities.statictype.TagClass;
43-
import ldbc.snb.datagen.hadoop.writer.HDFSCSVWriter;
4444
import ldbc.snb.datagen.serializer.StaticSerializer;
4545
import ldbc.snb.datagen.serializer.snb.csv.FileName;
4646
import ldbc.snb.datagen.vocabulary.DBP;
4747
import ldbc.snb.datagen.vocabulary.DBPOWL;
48-
import org.apache.hadoop.conf.Configuration;
4948

50-
import java.io.IOException;
51-
import java.util.ArrayList;
5249
import java.util.List;
5350

51+
import static ldbc.snb.datagen.serializer.snb.csv.FileName.*;
52+
5453
/**
5554
* Created by aprat on 17/02/15.
5655
*/
5756
public class CSVMergeForeignStaticSerializer extends StaticSerializer {
5857

59-
private HDFSCSVWriter[] writers;
60-
61-
private enum FileNames {
62-
TAG("tag"),
63-
TAGCLASS("tagclass"),
64-
PLACE("place"),
65-
ORGANIZATION("organisation");
66-
67-
private final String name;
68-
69-
private FileNames(String name) {
70-
this.name = name;
71-
}
72-
73-
public String toString() {
74-
return name;
75-
}
76-
}
77-
7858
@Override
7959
public List<FileName> getFileNames() {
80-
return null;
60+
return ImmutableList.of(TAG, TAGCLASS, PLACE, ORGANIZATION);
8161
}
8262

8363
@Override
8464
public void writeFileHeaders() {
85-
86-
}
87-
88-
@Override
89-
public void initialize(Configuration conf, int reducerId) throws IOException {
90-
int numFiles = FileNames.values().length;
91-
writers = new HDFSCSVWriter[numFiles];
92-
for (int i = 0; i < numFiles; ++i) {
93-
writers[i] = new HDFSCSVWriter(conf.get("ldbc.snb.datagen.serializer.socialNetworkDir")+"/static", FileNames
94-
.values()[i].toString() + "_" + reducerId, conf.getInt("ldbc.snb.datagen.numPartitions", 1), conf
95-
.getBoolean("ldbc.snb.datagen.serializer.compressed", false), "|", conf
96-
.getBoolean("ldbc.snb.datagen.serializer.endlineSeparator", false));
97-
}
98-
99-
ArrayList<String> arguments = new ArrayList<String>();
100-
arguments.add("id");
101-
arguments.add("name");
102-
arguments.add("url");
103-
arguments.add("hasType");
104-
writers[FileNames.TAG.ordinal()].writeHeader(arguments);
105-
106-
arguments.clear();
107-
arguments.add("id");
108-
arguments.add("name");
109-
arguments.add("url");
110-
arguments.add("isSubclassOf");
111-
writers[FileNames.TAGCLASS.ordinal()].writeHeader(arguments);
112-
113-
arguments.clear();
114-
arguments.add("id");
115-
arguments.add("name");
116-
arguments.add("url");
117-
arguments.add("type");
118-
arguments.add("isPartOf");
119-
writers[FileNames.PLACE.ordinal()].writeHeader(arguments);
120-
121-
122-
arguments.clear();
123-
arguments.add("id");
124-
arguments.add("type");
125-
arguments.add("name");
126-
arguments.add("url");
127-
arguments.add("place");
128-
writers[FileNames.ORGANIZATION.ordinal()].writeHeader(arguments);
129-
130-
}
131-
132-
public void close() {
133-
int numFiles = FileNames.values().length;
134-
for (int i = 0; i < numFiles; ++i) {
135-
writers[i].close();
136-
}
65+
writers.get(TAG).writeHeader(ImmutableList.of("id", "name", "url", "hasType"));
66+
writers.get(TAGCLASS).writeHeader(ImmutableList.of("id", "name", "url", "isSubclassOf"));
67+
writers.get(PLACE).writeHeader(ImmutableList.of("id", "name", "url", "type", "isPartOf"));
68+
writers.get(ORGANIZATION).writeHeader(ImmutableList.of("id", "type", "name", "url", "place"));
13769
}
13870

13971
protected void serialize(final Place place) {
140-
ArrayList<String> arguments = new ArrayList<String>();
141-
arguments.add(Integer.toString(place.getId()));
142-
arguments.add(place.getName());
143-
arguments.add(DBP.getUrl(place.getName()));
144-
arguments.add(place.getType());
145-
146-
if (place.getType() == Place.CITY ||
147-
place.getType() == Place.COUNTRY) {
148-
arguments.add(Integer.toString(Dictionaries.places.belongsTo(place.getId())));
149-
} else {
150-
arguments.add("");
151-
}
152-
writers[FileNames.PLACE.ordinal()].writeEntry(arguments);
153-
154-
72+
writers.get(PLACE).writeEntry(ImmutableList.of(
73+
Integer.toString(place.getId()),
74+
place.getName(),
75+
DBP.getUrl(place.getName()),
76+
place.getType(),
77+
place.getType() == Place.CITY || place.getType() == Place.COUNTRY ? Integer.toString(Dictionaries.places.belongsTo(place.getId())) : ""
78+
));
15579
}
15680

15781
protected void serialize(final Organisation organisation) {
158-
ArrayList<String> arguments = new ArrayList<String>();
159-
arguments.add(Long.toString(organisation.id));
160-
arguments.add(organisation.type.toString());
161-
arguments.add(organisation.name);
162-
arguments.add(DBP.getUrl(organisation.name));
163-
arguments.add(Integer.toString(organisation.location));
164-
writers[FileNames.ORGANIZATION.ordinal()].writeEntry(arguments);
82+
writers.get(ORGANIZATION).writeEntry(ImmutableList.of(
83+
Long.toString(organisation.id),
84+
organisation.type.toString(),
85+
organisation.name,
86+
DBP.getUrl(organisation.name),
87+
Integer.toString(organisation.location)
88+
));
16589
}
16690

16791
protected void serialize(final TagClass tagClass) {
168-
ArrayList<String> arguments = new ArrayList<String>();
169-
arguments.add(Integer.toString(tagClass.id));
170-
arguments.add(tagClass.name);
171-
if (tagClass.name.equals("Thing")) {
172-
arguments.add("http://www.w3.org/2002/07/owl#Thing");
173-
} else {
174-
arguments.add(DBPOWL.getUrl(tagClass.name));
175-
}
176-
if (tagClass.parent != -1) {
177-
arguments.add(Integer.toString(tagClass.parent));
178-
} else {
179-
arguments.add("");
180-
}
181-
writers[FileNames.TAGCLASS.ordinal()].writeEntry(arguments);
182-
92+
writers.get(TAGCLASS).writeEntry(ImmutableList.of(
93+
Integer.toString(tagClass.id),
94+
tagClass.name,
95+
tagClass.name.equals("Thing") ? "http://www.w3.org/2002/07/owl#Thing" : DBPOWL.getUrl(tagClass.name),
96+
tagClass.parent != -1 ? Integer.toString(tagClass.parent) : ""
97+
));
18398
}
18499

185100
protected void serialize(final Tag tag) {
186-
ArrayList<String> arguments = new ArrayList<String>();
187-
arguments.add(Integer.toString(tag.id));
188-
arguments.add(tag.name);
189-
arguments.add(DBP.getUrl(tag.name));
190-
arguments.add(Integer.toString(tag.tagClass));
191-
writers[FileNames.TAG.ordinal()].writeEntry(arguments);
192-
}
193-
194-
public void reset() {
195-
// Intentionally left empty
101+
writers.get(TAG).writeEntry(ImmutableList.of(
102+
Integer.toString(tag.id),
103+
tag.name,
104+
DBP.getUrl(tag.name),
105+
Integer.toString(tag.tagClass)
106+
));
196107
}
197108

198109
}

0 commit comments

Comments
 (0)