@@ -35,194 +35,103 @@ 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 .dynamicserializer .person ;
37
37
38
+ import com .google .common .collect .ImmutableList ;
38
39
import ldbc .snb .datagen .dictionary .Dictionaries ;
39
- import ldbc .snb .datagen .entities .dynamic .relations .Knows ;
40
40
import ldbc .snb .datagen .entities .dynamic .person .Person ;
41
+ import ldbc .snb .datagen .entities .dynamic .relations .Knows ;
41
42
import ldbc .snb .datagen .entities .dynamic .relations .StudyAt ;
42
43
import ldbc .snb .datagen .entities .dynamic .relations .WorkAt ;
43
44
import ldbc .snb .datagen .hadoop .writer .HDFSCSVWriter ;
44
45
import ldbc .snb .datagen .serializer .DynamicPersonSerializer ;
46
+ import ldbc .snb .datagen .serializer .snb .csv .FileName ;
45
47
import org .apache .hadoop .conf .Configuration ;
46
48
49
+ import static ldbc .snb .datagen .serializer .snb .csv .FileName .*;
50
+
47
51
import java .io .IOException ;
48
52
import java .util .ArrayList ;
49
53
import java .util .Iterator ;
54
+ import java .util .List ;
50
55
51
56
/**
52
57
* Created by aprat on 17/02/15.
53
58
*/
54
59
public class CSVMergeForeignDynamicPersonSerializer extends DynamicPersonSerializer {
55
60
56
- private HDFSCSVWriter [] writers ;
57
-
58
- private enum FileNames {
59
- PERSON ("person" ),
60
- PERSON_SPEAKS_LANGUAGE ("person_speaks_language" ),
61
- PERSON_HAS_EMAIL ("person_email_emailaddress" ),
62
- PERSON_HAS_INTEREST_TAG ("person_hasInterest_tag" ),
63
- PERSON_WORK_AT ("person_workAt_organisation" ),
64
- PERSON_STUDY_AT ("person_studyAt_organisation" ),
65
- PERSON_KNOWS_PERSON ("person_knows_person" );
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
- public void initialize (Configuration conf , int reducerId ) throws IOException {
79
- int numFiles = FileNames .values ().length ;
80
- writers = new HDFSCSVWriter [numFiles ];
81
- for (int i = 0 ; i < numFiles ; ++i ) {
82
- writers [i ] = new HDFSCSVWriter (conf .get ("ldbc.snb.datagen.serializer.socialNetworkDir" )+"/dynamic/" , FileNames
83
- .values ()[i ].toString () + "_" + reducerId , conf .getInt ("ldbc.snb.datagen.numPartitions" , 1 ), conf
84
- .getBoolean ("ldbc.snb.datagen.serializer.compressed" , false ), "|" , conf
85
- .getBoolean ("ldbc.snb.datagen.serializer.endlineSeparator" , false ));
86
- }
87
-
88
- ArrayList <String > arguments = new ArrayList <String >();
89
- arguments .add ("id" );
90
- arguments .add ("firstName" );
91
- arguments .add ("lastName" );
92
- arguments .add ("gender" );
93
- arguments .add ("birthday" );
94
- arguments .add ("creationDate" );
95
- arguments .add ("locationIP" );
96
- arguments .add ("browserUsed" );
97
- arguments .add ("place" );
98
- writers [FileNames .PERSON .ordinal ()].writeHeader (arguments );
99
-
100
- arguments .clear ();
101
- arguments .add ("Person.id" );
102
- arguments .add ("language" );
103
- writers [FileNames .PERSON_SPEAKS_LANGUAGE .ordinal ()].writeHeader (arguments );
104
-
105
- arguments .clear ();
106
- arguments .add ("Person.id" );
107
- arguments .add ("email" );
108
- writers [FileNames .PERSON_HAS_EMAIL .ordinal ()].writeHeader (arguments );
109
-
110
- arguments .clear ();
111
- arguments .add ("Person.id" );
112
- arguments .add ("Tag.id" );
113
- writers [FileNames .PERSON_HAS_INTEREST_TAG .ordinal ()].writeHeader (arguments );
114
-
115
- arguments .clear ();
116
- arguments .add ("Person.id" );
117
- arguments .add ("Organisation.id" );
118
- arguments .add ("workFrom" );
119
- writers [FileNames .PERSON_WORK_AT .ordinal ()].writeHeader (arguments );
120
-
121
- arguments .clear ();
122
- arguments .add ("Person.id" );
123
- arguments .add ("Organisation.id" );
124
- arguments .add ("classYear" );
125
- writers [FileNames .PERSON_STUDY_AT .ordinal ()].writeHeader (arguments );
126
-
127
- arguments .clear ();
128
- arguments .add ("Person.id" );
129
- arguments .add ("Person.id" );
130
- arguments .add ("creationDate" );
131
- writers [FileNames .PERSON_KNOWS_PERSON .ordinal ()].writeHeader (arguments );
132
-
61
+ @ Override
62
+ public List <FileName > getFileNames () {
63
+ return ImmutableList .of (PERSON , PERSON_SPEAKS_LANGUAGE , PERSON_HAS_EMAIL , PERSON_HAS_INTEREST_TAG ,
64
+ PERSON_WORK_AT , PERSON_STUDY_AT , PERSON_KNOWS_PERSON );
133
65
}
134
66
135
67
@ Override
136
- public void close () {
137
- int numFiles = FileNames .values ().length ;
138
- for (int i = 0 ; i < numFiles ; ++i ) {
139
- writers [i ].close ();
140
- }
68
+ public void writeFileHeaders () {
69
+ writers .get (PERSON ).writeHeader (ImmutableList .of ("id" , "firstName" , "lastName" , "gender" , "birthday" , "creationDate" , "locationIP" , "browserUsed" , "place" ));
70
+ writers .get (PERSON_SPEAKS_LANGUAGE ).writeHeader (ImmutableList .of ("Person.id" , "language" ));
71
+ writers .get (PERSON_HAS_EMAIL ).writeHeader (ImmutableList .of ("Person.id" , "email" ));
72
+ writers .get (PERSON_HAS_INTEREST_TAG ).writeHeader (ImmutableList .of ("Person.id" , "Tag.id" ));
73
+ writers .get (PERSON_WORK_AT ).writeHeader (ImmutableList .of ("Person.id" , "Organisation.id" , "workFrom" ));
74
+ writers .get (PERSON_STUDY_AT ).writeHeader (ImmutableList .of ("Person.id" , "Organisation.id" , "classYear" ));
75
+ writers .get (PERSON_KNOWS_PERSON ).writeHeader (ImmutableList .of ("Person.id" , "Person.id" , "creationDate" ));
141
76
}
142
77
143
78
@ Override
144
79
protected void serialize (final Person p ) {
145
-
146
- ArrayList <String > arguments = new ArrayList <String >();
147
-
148
- arguments .add (Long .toString (p .accountId ()));
149
- arguments .add (p .firstName ());
150
- arguments .add (p .lastName ());
151
- if (p .gender () == 1 ) {
152
- arguments .add ("male" );
153
- } else {
154
- arguments .add ("female" );
155
- }
156
-
157
- String dateString = Dictionaries .dates .formatDate (p .birthday ());
158
- arguments .add (dateString );
159
-
160
- dateString = Dictionaries .dates .formatDateTime (p .creationDate ());
161
- arguments .add (dateString );
162
- arguments .add (p .ipAddress ().toString ());
163
- arguments .add (Dictionaries .browsers .getName (p .browserId ()));
164
- arguments .add (Integer .toString (p .cityId ()));
165
- writers [FileNames .PERSON .ordinal ()].writeEntry (arguments );
166
-
167
- ArrayList <Integer > languages = p .languages ();
80
+ writers .get (PERSON ).writeEntry (ImmutableList .of (
81
+ Long .toString (p .accountId ()),
82
+ p .firstName (),
83
+ p .lastName (),
84
+ p .gender () == 1 ? "male" : "female" ,
85
+ Dictionaries .dates .formatDate (p .birthday ()),
86
+ Dictionaries .dates .formatDateTime (p .creationDate ()),
87
+ p .ipAddress ().toString (),
88
+ Dictionaries .browsers .getName (p .browserId ()),
89
+ Integer .toString (p .cityId ())
90
+ ));
91
+
92
+ List <Integer > languages = p .languages ();
168
93
for (int i = 0 ; i < languages .size (); i ++) {
169
- arguments .clear ();
170
- arguments .add (Long .toString (p .accountId ()));
171
- arguments .add (Dictionaries .languages .getLanguageName (languages .get (i )));
172
- writers [FileNames .PERSON_SPEAKS_LANGUAGE .ordinal ()].writeEntry (arguments );
94
+ writers .get (PERSON_SPEAKS_LANGUAGE ).writeEntry (ImmutableList .of (
95
+ Long .toString (p .accountId ()), Dictionaries .languages .getLanguageName (languages .get (i ))
96
+ ));
173
97
}
174
98
175
- Iterator <String > itString = p .emails ().iterator ();
176
- while (itString .hasNext ()) {
177
- arguments .clear ();
178
- String email = itString .next ();
179
- arguments .add (Long .toString (p .accountId ()));
180
- arguments .add (email );
181
- writers [FileNames .PERSON_HAS_EMAIL .ordinal ()].writeEntry (arguments );
99
+ Iterator <String > emails = p .emails ().iterator ();
100
+ while (emails .hasNext ()) {
101
+ writers .get (PERSON_HAS_EMAIL ).writeEntry (ImmutableList .of (
102
+ Long .toString (p .accountId ()), emails .next ()
103
+ ));
182
104
}
183
105
184
- Iterator <Integer > itInteger = p .interests ().iterator ();
185
- while (itInteger .hasNext ()) {
186
- arguments .clear ();
187
- Integer interestIdx = itInteger .next ();
188
- arguments .add (Long .toString (p .accountId ()));
189
- arguments .add (Integer .toString (interestIdx ));
190
- writers [FileNames .PERSON_HAS_INTEREST_TAG .ordinal ()].writeEntry (arguments );
106
+ Iterator <Integer > interests = p .interests ().iterator ();
107
+ while (interests .hasNext ()) {
108
+ writers .get (PERSON_HAS_INTEREST_TAG ).writeEntry (ImmutableList .of (
109
+ Long .toString (p .accountId ()), Integer .toString (interests .next ())
110
+ ));
191
111
}
192
112
}
193
113
194
114
@ Override
195
115
protected void serialize (final StudyAt studyAt ) {
196
- ArrayList <String > arguments = new ArrayList <String >();
197
- String dateString = Dictionaries .dates .formatYear (studyAt .year );
198
- arguments .add (Long .toString (studyAt .user ));
199
- arguments .add (Long .toString (studyAt .university ));
200
- arguments .add (dateString );
201
- writers [FileNames .PERSON_STUDY_AT .ordinal ()].writeEntry (arguments );
116
+ writers .get (PERSON_STUDY_AT ).writeEntry (ImmutableList .of (
117
+ Long .toString (studyAt .user ), Long .toString (studyAt .university ), Dictionaries .dates .formatYear (studyAt .year )
118
+ ));
202
119
}
203
120
204
121
@ Override
205
122
protected void serialize (final WorkAt workAt ) {
206
- ArrayList <String > arguments = new ArrayList <String >();
207
- String dateString = Dictionaries .dates .formatYear (workAt .year );
208
- arguments .add (Long .toString (workAt .user ));
209
- arguments .add (Long .toString (workAt .company ));
210
- arguments .add (dateString );
211
- writers [FileNames .PERSON_WORK_AT .ordinal ()].writeEntry (arguments );
123
+ writers .get (PERSON_WORK_AT ).writeEntry (ImmutableList .of (
124
+ Long .toString (workAt .user ), Long .toString (workAt .company ), Dictionaries .dates .formatYear (workAt .year )
125
+ ));
212
126
}
213
127
214
128
@ Override
215
129
protected void serialize (final Person p , Knows knows ) {
216
- ArrayList <String > arguments = new ArrayList <String >();
217
- String dateString = Dictionaries .dates .formatDateTime (knows .creationDate ());
218
- arguments .add (Long .toString (p .accountId ()));
219
- arguments .add (Long .toString (knows .to ().accountId ()));
220
- arguments .add (dateString );
221
- writers [FileNames .PERSON_KNOWS_PERSON .ordinal ()].writeEntry (arguments );
130
+ writers .get (PERSON_KNOWS_PERSON ).writeEntry (ImmutableList .of (
131
+ Long .toString (p .accountId ()),
132
+ Long .toString (knows .to ().accountId ()),
133
+ Dictionaries .dates .formatDateTime (knows .creationDate ())
134
+ ));
222
135
}
223
136
224
- @ Override
225
- public void reset () {
226
- // Intentionally left empty
227
- }
228
137
}
0 commit comments