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