@@ -35,164 +35,75 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
35
35
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
36
36
package ldbc .snb .datagen .serializer .snb .csv .staticserializer ;
37
37
38
+ import com .google .common .collect .ImmutableList ;
38
39
import ldbc .snb .datagen .dictionary .Dictionaries ;
39
40
import ldbc .snb .datagen .entities .statictype .Organisation ;
41
+ import ldbc .snb .datagen .entities .statictype .TagClass ;
40
42
import ldbc .snb .datagen .entities .statictype .place .Place ;
41
43
import ldbc .snb .datagen .entities .statictype .tag .Tag ;
42
- import ldbc .snb .datagen .entities .statictype .TagClass ;
43
- import ldbc .snb .datagen .hadoop .writer .HDFSCSVWriter ;
44
44
import ldbc .snb .datagen .serializer .StaticSerializer ;
45
45
import ldbc .snb .datagen .serializer .snb .csv .FileName ;
46
46
import ldbc .snb .datagen .vocabulary .DBP ;
47
47
import ldbc .snb .datagen .vocabulary .DBPOWL ;
48
- import org .apache .hadoop .conf .Configuration ;
49
48
50
- import java .io .IOException ;
51
- import java .util .ArrayList ;
52
49
import java .util .List ;
53
50
51
+ import static ldbc .snb .datagen .serializer .snb .csv .FileName .*;
52
+
54
53
/**
55
54
* Created by aprat on 17/02/15.
56
55
*/
57
56
public class CSVMergeForeignStaticSerializer extends StaticSerializer {
58
57
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
-
78
58
@ Override
79
59
public List <FileName > getFileNames () {
80
- return null ;
60
+ return ImmutableList . of ( TAG , TAGCLASS , PLACE , ORGANIZATION ) ;
81
61
}
82
62
83
63
@ Override
84
64
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" ));
137
69
}
138
70
139
71
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
+ ));
155
79
}
156
80
157
81
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
+ ) );
165
89
}
166
90
167
91
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
+ ));
183
98
}
184
99
185
100
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
+ ));
196
107
}
197
108
198
109
}
0 commit comments