|
| 1 | +/* |
| 2 | + * Copyright (c) 2013 LDBC |
| 3 | + * Linked Data Benchmark Council (http://ldbc.eu) |
| 4 | + * |
| 5 | + * This file is part of ldbc_socialnet_dbgen. |
| 6 | + * |
| 7 | + * ldbc_socialnet_dbgen is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * ldbc_socialnet_dbgen is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with ldbc_socialnet_dbgen. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + * |
| 20 | + * Copyright (C) 2011 OpenLink Software <[email protected]> |
| 21 | + * All Rights Reserved. |
| 22 | + * |
| 23 | + * This program is free software; you can redistribute it and/or modify |
| 24 | + * it under the terms of the GNU General Public License as published by |
| 25 | + * the Free Software Foundation; only Version 2 of the License dated |
| 26 | + * June 1991. |
| 27 | + * |
| 28 | + * This program is distributed in the hope that it will be useful, |
| 29 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 | + * GNU General Public License for more details. |
| 32 | + * |
| 33 | + * You should have received a copy of the GNU General Public License |
| 34 | + * along with this program; if not, write to the Free Software |
| 35 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 36 | + */ |
| 37 | + |
| 38 | + |
| 39 | +package ldbc.snb.datagen.serializer.graphalytics; |
| 40 | + |
| 41 | +import ldbc.snb.datagen.objects.Knows; |
| 42 | +import ldbc.snb.datagen.objects.Person; |
| 43 | +import ldbc.snb.datagen.objects.StudyAt; |
| 44 | +import ldbc.snb.datagen.objects.WorkAt; |
| 45 | +import ldbc.snb.datagen.serializer.HDFSCSVWriter; |
| 46 | +import ldbc.snb.datagen.serializer.PersonSerializer; |
| 47 | +import org.apache.hadoop.conf.Configuration; |
| 48 | + |
| 49 | +import java.util.ArrayList; |
| 50 | + |
| 51 | +public class CSVPersonSerializer extends PersonSerializer { |
| 52 | + |
| 53 | + private HDFSCSVWriter [] writers; |
| 54 | + |
| 55 | + private enum FileNames { |
| 56 | + PERSON_KNOWS_PERSON("person_knows_person"); |
| 57 | + |
| 58 | + private final String name; |
| 59 | + |
| 60 | + private FileNames( String name ) { |
| 61 | + this.name = name; |
| 62 | + } |
| 63 | + public String toString() { |
| 64 | + return name; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public CSVPersonSerializer() { |
| 69 | + } |
| 70 | + |
| 71 | + public void initialize(Configuration conf, int reducerId) { |
| 72 | + int numFiles = FileNames.values().length; |
| 73 | + writers = new HDFSCSVWriter[numFiles]; |
| 74 | + for( int i = 0; i < numFiles; ++i) { |
| 75 | + writers[i] = new HDFSCSVWriter(conf.get("ldbc.snb.datagen.serializer.socialNetworkDir"), FileNames.values()[i].toString()+"_"+reducerId,conf.getInt("ldbc.snb.datagen.numPartitions",1),conf.getBoolean("ldbc.snb.datagen.serializer.compressed",false),"|"); |
| 76 | + } |
| 77 | + |
| 78 | + ArrayList<String> arguments = new ArrayList<String>(); |
| 79 | + arguments.clear(); |
| 80 | + arguments.add("Person.id"); |
| 81 | + arguments.add("Person.id"); |
| 82 | + arguments.add("Weight"); |
| 83 | + writers[FileNames.PERSON_KNOWS_PERSON.ordinal()].writeEntry(arguments); |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void close() { |
| 89 | + int numFiles = FileNames.values().length; |
| 90 | + for(int i = 0; i < numFiles; ++i) { |
| 91 | + writers[i].close(); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + protected void serialize(Person p) { |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + protected void serialize(StudyAt studyAt) { |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + protected void serialize(WorkAt workAt) { |
| 106 | + } |
| 107 | + |
| 108 | + protected void serialize(Person p, Knows knows) { |
| 109 | + ArrayList<String> arguments = new ArrayList<String>(); |
| 110 | + arguments.add(Long.toString(p.accountId())); |
| 111 | + arguments.add(Long.toString(knows.to().accountId())); |
| 112 | + arguments.add(Float.toString(knows.weight())); |
| 113 | + writers[FileNames.PERSON_KNOWS_PERSON.ordinal()].writeEntry(arguments); |
| 114 | + } |
| 115 | + |
| 116 | + public void reset() { |
| 117 | + |
| 118 | + } |
| 119 | +} |
0 commit comments