diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCount.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCount.java new file mode 100644 index 0000000..2aaa647 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCount.java @@ -0,0 +1,62 @@ +package com.dsinpractice.samples.hadoop.mapred.charcount; + +import java.io.IOException; +import java.util.Iterator; + +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.FileInputFormat; +import org.apache.hadoop.mapred.FileOutputFormat; +import org.apache.hadoop.mapred.JobClient; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.MapReduceBase; +import org.apache.hadoop.mapred.Mapper; +import org.apache.hadoop.mapred.OutputCollector; +import org.apache.hadoop.mapred.Reducer; +import org.apache.hadoop.mapred.Reporter; +import org.apache.hadoop.mapred.TextInputFormat; +import org.apache.hadoop.mapred.TextOutputFormat; + +public class CharCount { + + + + + //Write client which will run the job + public static void main(String[] args) { + + //1. create job conf + JobConf conf = new JobConf(CharCount.class); + conf.setJobName("CharCount"); + + //2. set the output key and value type + conf.setMapOutputKeyClass(Text.class); + conf.setMapOutputValueClass(IntWritable.class); + + //3. set the map and reduce class + conf.setMapperClass(CharCountMap.class); + conf.setReducerClass(CharCountReduce.class); + + //4. set the inoput output data format + conf.setInputFormat(TextInputFormat.class); + conf.setOutputFormat(TextOutputFormat.class); + + //5. set the input / output directories + //FileInputFormat.setInputPaths(conf, new Path("/hdfspath/data/wcinput/")); + //FileOutputFormat.setOutputPath(conf, new Path("/hdfspath/data/ccoutput")); + + //5. set the input and output file path + FileInputFormat.setInputPaths(conf, new Path(args[0])); + FileOutputFormat.setOutputPath(conf, new Path(args[1])); + + //6. run the job + try { + JobClient.runJob(conf); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCountMap.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCountMap.java new file mode 100644 index 0000000..63c8848 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCountMap.java @@ -0,0 +1,37 @@ +package com.dsinpractice.samples.hadoop.mapred.charcount; + +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.MapReduceBase; +import org.apache.hadoop.mapred.Mapper; +import org.apache.hadoop.mapred.OutputCollector; +import org.apache.hadoop.mapred.Reporter; + +import java.io.IOException; + +/** + * Created by admin on 10/23/14. + */ +// write Map class +public class CharCountMap extends MapReduceBase implements Mapper { + + + @Override + public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) + throws IOException { + // Logic to read line and count chars + + String line = value.toString(); + + if (line == null || line.equals("")) + return; + + for (int i = 0; i < line.length(); i++) { + value.set("" + line.charAt(i)); + output.collect(value, new IntWritable(1)); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCountReduce.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCountReduce.java new file mode 100644 index 0000000..b840cbf --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/charcount/CharCountReduce.java @@ -0,0 +1,31 @@ +package com.dsinpractice.samples.hadoop.mapred.charcount; + +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.*; + +import java.io.IOException; +import java.util.Iterator; + +/** + * Created by admin on 10/23/14. + */ +// write Map class +//Write Reduce class +public class CharCountReduce extends MapReduceBase implements Reducer { + + @Override + public void reduce(Text key, Iterator value, OutputCollector output, Reporter reporter) + throws IOException { + // Logic to collect and segregate the char counts per char + + int sum = 0; + + while(value.hasNext()){ + sum = sum + value.next().get(); + } + output.collect(key, new IntWritable(sum)); + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/CustomFormatClient.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/CustomFormatClient.java new file mode 100644 index 0000000..a848304 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/CustomFormatClient.java @@ -0,0 +1,46 @@ +package com.dsinpractice.samples.hadoop.mapred.customformat; + +import java.io.IOException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapreduce.Job; +import org.apache.hadoop.mapreduce.Mapper; +import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; +import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; + + +public class CustomFormatClient { + + + + public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { + + /*if (args-Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk.length != 2) { + System.err.println("Usage: "); + System.exit(-1); + }*/ + + Configuration conf = new Configuration(); + + + Job job = new Job(conf,"Custom Input Type"); + job.setJarByClass(CustomFormatClient.class); + job.setNumReduceTasks(0); + + job.setMapperClass(MyMapper.class); + job.setOutputKeyClass(MyKey.class); + job.setOutputValueClass(MyValue.class); + job.setInputFormatClass(MyInputFormat.class); + + FileInputFormat.addInputPath(job, new Path(args[0])); + FileOutputFormat.setOutputPath(job, new Path(args[1])); + + + + job.waitForCompletion(true); + } + + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyInputFormat.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyInputFormat.java new file mode 100644 index 0000000..5aced63 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyInputFormat.java @@ -0,0 +1,19 @@ +package com.dsinpractice.samples.hadoop.mapred.customformat; + +import java.io.IOException; + +import org.apache.hadoop.mapreduce.InputSplit; +import org.apache.hadoop.mapreduce.RecordReader; +import org.apache.hadoop.mapreduce.TaskAttemptContext; +import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; + + +public class MyInputFormat extends FileInputFormat{ + + @Override + public RecordReader createRecordReader(InputSplit split, + TaskAttemptContext context) throws IOException, InterruptedException { + return new MyRecordReader(); + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyKey.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyKey.java new file mode 100644 index 0000000..4c258c8 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyKey.java @@ -0,0 +1,62 @@ +package com.dsinpractice.samples.hadoop.mapred.customformat; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.WritableComparable; + +public class MyKey implements WritableComparable { + + private Text imei, deviceModel; + + public MyKey() { + setImei(new Text()); + setDeviceModel(new Text()); + } + + public MyKey(Text _imei, Text _deviceModel) { + setImei(_imei); + setDeviceModel(_deviceModel); + } + + @Override + public void readFields(DataInput in) throws IOException { + getImei().readFields(in); + getDeviceModel().readFields(in); + } + + @Override + public void write(DataOutput out) throws IOException { + getImei().write(out); + getDeviceModel().write(out); + } + + @Override + public int compareTo(Object obj) { + MyKey argKey = (MyKey) obj; + int result = this.getImei().compareTo(argKey.getImei()); + if(result != 0){ + return result; + } + return this.getDeviceModel().compareTo(argKey.getDeviceModel()); + } + + public Text getImei() { + return imei; + } + + public void setImei(Text imei) { + this.imei = imei; + } + + public Text getDeviceModel() { + return deviceModel; + } + + public void setDeviceModel(Text deviceModel) { + this.deviceModel = deviceModel; + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyMapper.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyMapper.java new file mode 100644 index 0000000..3fa87d3 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyMapper.java @@ -0,0 +1,26 @@ +package com.dsinpractice.samples.hadoop.mapred.customformat; + +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapreduce.Mapper; + + + +/** + * Created by admin on 10/23/14. + */ +public class MyMapper extends Mapper { + + + public void map(MyKey key, MyValue value, Context context) throws java.io.IOException ,InterruptedException { + String imei = key.getImei().toString(); + String model = key.getDeviceModel().toString(); + if(imei.startsWith("9765")){ + String status = value.getStatus().toString(); + String country = value.getCountry().toString(); + String basePhone = value.getBasePhone().toString(); + String advPhone = value.getAdvPhone().toString(); + context.write(new Text(imei),new Text(country)); + } + + } +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyRecordReader.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyRecordReader.java new file mode 100644 index 0000000..e5d3734 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyRecordReader.java @@ -0,0 +1,74 @@ +package com.dsinpractice.samples.hadoop.mapred.customformat; + +import java.io.IOException; + +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapreduce.InputSplit; +import org.apache.hadoop.mapreduce.RecordReader; +import org.apache.hadoop.mapreduce.TaskAttemptContext; +import org.apache.hadoop.mapreduce.lib.input.LineRecordReader; + +public class MyRecordReader extends RecordReader { + + private MyKey myKey; + private MyValue myValue; + private LineRecordReader reader = new LineRecordReader(); + + @Override + public void close() throws IOException { + // TODO Auto-generated method stub + reader.close(); + } + + @Override + public MyKey getCurrentKey() throws IOException, InterruptedException { + // TODO Auto-generated method stub + return myKey; + } + + @Override + public MyValue getCurrentValue() throws IOException, InterruptedException { + // TODO Auto-generated method stub + return myValue; + } + + @Override + public float getProgress() throws IOException, InterruptedException { + // TODO Auto-generated method stub + return reader.getProgress(); + } + + @Override + public void initialize(InputSplit split, TaskAttemptContext context) + throws IOException, InterruptedException { + // TODO Auto-generated method stub + reader.initialize(split, context); + } + + @Override + public boolean nextKeyValue() throws IOException, InterruptedException { + boolean isNextValue = reader.nextKeyValue(); + if (isNextValue) { + if (myKey == null) { + myKey = new MyKey(); + } + if (myValue == null) { + myValue = new MyValue(); + } + Text line = reader.getCurrentValue(); + String[] tokens = line.toString().split(","); + myKey.setImei(new Text(tokens[0])); + myKey.setDeviceModel(new Text(tokens[1])); + myValue.setStatus(new Text(tokens[2])); + myValue.setCountry(new Text(tokens[3])); + myValue.setBasePhone(new Text(tokens[4])); + myValue.setAdvPhone(new Text(tokens[5])); + + } else { + myKey = null; + myValue = null; + } + return isNextValue; + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyValue.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyValue.java new file mode 100644 index 0000000..7b7e41f --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/customformat/MyValue.java @@ -0,0 +1,95 @@ +package com.dsinpractice.samples.hadoop.mapred.customformat; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.WritableComparable; + +public class MyValue implements WritableComparable { + + private Text status, country, basePhone, advPhone; + + public MyValue() { + this.setStatus(new Text()); + this.setCountry(new Text()); + this.setBasePhone(new Text()); + this.setAdvPhone(new Text()); + } + + public MyValue(Text _status, Text _country, Text _basePhone, Text _advPhone) { + this.setStatus(_status); + this.setCountry(_country); + this.setBasePhone(_basePhone); + this.setAdvPhone(_advPhone); + } + + @Override + public void readFields(DataInput in) throws IOException { + this.getStatus().readFields(in); + this.getCountry().readFields(in); + this.getBasePhone().readFields(in); + this.getAdvPhone().readFields(in); + } + + @Override + public void write(DataOutput out) throws IOException { + this.getStatus().write(out); + this.getCountry().write(out); + this.getBasePhone().write(out); + this.getAdvPhone().write(out); + + } + + @Override + public int compareTo(Object obj) { + MyValue argVal = (MyValue) obj; + int compare = this.getStatus().compareTo(argVal.getStatus()); + if (compare != 0) { + return compare; + } + compare = this.getCountry().compareTo(argVal.getCountry()); + if (compare != 0) { + return compare; + } + compare = this.getBasePhone().compareTo(argVal.getBasePhone()); + if (compare != 0) { + return compare; + } + return this.getAdvPhone().compareTo(argVal.getAdvPhone()); + } + + public Text getStatus() { + return status; + } + + public void setStatus(Text status) { + this.status = status; + } + + public Text getCountry() { + return country; + } + + public void setCountry(Text country) { + this.country = country; + } + + public Text getBasePhone() { + return basePhone; + } + + public void setBasePhone(Text basePhone) { + this.basePhone = basePhone; + } + + public Text getAdvPhone() { + return advPhone; + } + + public void setAdvPhone(Text advPhone) { + this.advPhone = advPhone; + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Map.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Map.java new file mode 100644 index 0000000..ee72abf --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Map.java @@ -0,0 +1,36 @@ +package com.dsinpractice.samples.hadoop.mapred.simplewc; + +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.MapReduceBase; +import org.apache.hadoop.mapred.Mapper; +import org.apache.hadoop.mapred.OutputCollector; +import org.apache.hadoop.mapred.Reporter; + +import java.io.IOException; +import java.util.StringTokenizer; + +/** + * Created by admin on 10/23/14. + */ +//Write a map class +public class Map extends MapReduceBase implements Mapper { + + @Override + public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) + throws IOException { + String line = value.toString(); + StringTokenizer tokenizer = new StringTokenizer(line); + + while (tokenizer.hasMoreTokens()){ + String token = tokenizer.nextToken(); + if(token.endsWith(".") || token.endsWith(",")){ + token = token.substring(0,token.length() - 1); + } + value.set(token.toLowerCase()); + output.collect(value, new IntWritable(1)); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Partition.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Partition.java new file mode 100644 index 0000000..e219599 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Partition.java @@ -0,0 +1,33 @@ +package com.dsinpractice.samples.hadoop.mapred.simplewc; + +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.JobConf; + +/** + * Created by admin on 10/23/14. + */ +public class Partition implements org.apache.hadoop.mapred.Partitioner{ + + @Override + public void configure(JobConf arg0) { + // TODO Auto-generated method stub + + } + + @Override + public int getPartition(Text key, IntWritable value, int numOfPartition) { + String keyVal = key.toString().toLowerCase(); + if(keyVal.equals("papa")){ + // if "papa", the put it to partition 1. + return 0; + } else if (keyVal.equals("yes") || keyVal.equals("no")){ + // if "no" or "yes", the put it to partition 2. + return 1; + } else { + // For rest of the cases, put it to partition 0. + return 2; + } + } + +} diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Reduce.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Reduce.java new file mode 100644 index 0000000..7b65ee8 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/Reduce.java @@ -0,0 +1,35 @@ +package com.dsinpractice.samples.hadoop.mapred.simplewc; + +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.MapReduceBase; +import org.apache.hadoop.mapred.OutputCollector; +import org.apache.hadoop.mapred.Reducer; +import org.apache.hadoop.mapred.Reporter; + +import java.io.IOException; +import java.util.Iterator; + +/** + * Created by admin on 10/23/14. + */ + + +// Write a Reduce class +public class Reduce extends MapReduceBase implements Reducer { + + @Override + public void reduce(Text key, Iterator value, OutputCollector output, Reporter reporter) + throws IOException { + + int sum = 0; + while(value.hasNext()){ + System.out.println(value.next()); + sum ++; + } + + output.collect(key, new IntWritable(sum)); + } + +} + diff --git a/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/WordCount.java b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/WordCount.java new file mode 100644 index 0000000..95c30e1 --- /dev/null +++ b/src/main/java/com/dsinpractice/samples/hadoop/mapred/simplewc/WordCount.java @@ -0,0 +1,66 @@ +package com.dsinpractice.samples.hadoop.mapred.simplewc; + +import java.io.IOException; +import java.util.Iterator; +import java.util.StringTokenizer; + +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.FileInputFormat; +import org.apache.hadoop.mapred.FileOutputFormat; +import org.apache.hadoop.mapred.JobClient; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.MapReduceBase; +import org.apache.hadoop.mapred.Mapper; +import org.apache.hadoop.mapred.OutputCollector; +import org.apache.hadoop.mapred.Reducer; +import org.apache.hadoop.mapred.Reporter; +import org.apache.hadoop.mapred.TextInputFormat; +import org.apache.hadoop.mapred.TextOutputFormat; + +public class WordCount { + + + // Write a client which does map reduce + public static void main(String[] args) { + + //1. Create Job Config + JobConf conf = new JobConf(WordCount.class); + conf.setJobName("WordCount"); + + // [Optional] if you want to set number of reducer job you want to run + conf.setNumReduceTasks(3); + + //3. set the map class and reduce class + conf.setMapperClass(Map.class); + conf.setCombinerClass(Reduce.class); + conf.setReducerClass(Reduce.class); + conf.setPartitionerClass(Partition.class); + + //2. Set output key and value + conf.setOutputKeyClass(Text.class); + conf.setOutputValueClass(IntWritable.class); + + //4. Set the type of input and output formate. In this case it will be text input and text output + conf.setInputFormat(TextInputFormat.class); + conf.setOutputFormat(TextOutputFormat.class); + + //5. set the input and output file path + FileInputFormat.setInputPaths(conf, new Path(args[0])); + FileOutputFormat.setOutputPath(conf, new Path(args[1])); + + //For the hardcorded paths use the following and comment the previous lines + //FileInputFormat.setInputPaths(conf, new Path("/path/wcinput/")); + //FileOutputFormat.setOutputPath(conf, new Path("/path/wcoutput/")); + + //6. run the job + try { + JobClient.runJob(conf); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/thoughtworks/samples/hadoop/avro/User.java b/src/main/java/com/thoughtworks/samples/hadoop/avro/User.java new file mode 100644 index 0000000..92a9a76 --- /dev/null +++ b/src/main/java/com/thoughtworks/samples/hadoop/avro/User.java @@ -0,0 +1,250 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.thoughtworks.samples.hadoop.avro; +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"com.thoughtworks.samples.hadoop.avro\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\":[\"int\",\"null\"]},{\"name\":\"favorite_color\",\"type\":[\"string\",\"null\"]}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + @Deprecated public java.lang.CharSequence name; + @Deprecated public java.lang.Integer favorite_number; + @Deprecated public java.lang.CharSequence favorite_color; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public User() {} + + /** + * All-args constructor. + */ + public User(java.lang.CharSequence name, java.lang.Integer favorite_number, java.lang.CharSequence favorite_color) { + this.name = name; + this.favorite_number = favorite_number; + this.favorite_color = favorite_color; + } + + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return name; + case 1: return favorite_number; + case 2: return favorite_color; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: name = (java.lang.CharSequence)value$; break; + case 1: favorite_number = (java.lang.Integer)value$; break; + case 2: favorite_color = (java.lang.CharSequence)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'name' field. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. + * @param value the value to set. + */ + public void setName(java.lang.CharSequence value) { + this.name = value; + } + + /** + * Gets the value of the 'favorite_number' field. + */ + public java.lang.Integer getFavoriteNumber() { + return favorite_number; + } + + /** + * Sets the value of the 'favorite_number' field. + * @param value the value to set. + */ + public void setFavoriteNumber(java.lang.Integer value) { + this.favorite_number = value; + } + + /** + * Gets the value of the 'favorite_color' field. + */ + public java.lang.CharSequence getFavoriteColor() { + return favorite_color; + } + + /** + * Sets the value of the 'favorite_color' field. + * @param value the value to set. + */ + public void setFavoriteColor(java.lang.CharSequence value) { + this.favorite_color = value; + } + + /** Creates a new User RecordBuilder */ + public static com.thoughtworks.samples.hadoop.avro.User.Builder newBuilder() { + return new com.thoughtworks.samples.hadoop.avro.User.Builder(); + } + + /** Creates a new User RecordBuilder by copying an existing Builder */ + public static com.thoughtworks.samples.hadoop.avro.User.Builder newBuilder(com.thoughtworks.samples.hadoop.avro.User.Builder other) { + return new com.thoughtworks.samples.hadoop.avro.User.Builder(other); + } + + /** Creates a new User RecordBuilder by copying an existing User instance */ + public static com.thoughtworks.samples.hadoop.avro.User.Builder newBuilder(com.thoughtworks.samples.hadoop.avro.User other) { + return new com.thoughtworks.samples.hadoop.avro.User.Builder(other); + } + + /** + * RecordBuilder for User instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.CharSequence name; + private java.lang.Integer favorite_number; + private java.lang.CharSequence favorite_color; + + /** Creates a new Builder */ + private Builder() { + super(com.thoughtworks.samples.hadoop.avro.User.SCHEMA$); + } + + /** Creates a Builder by copying an existing Builder */ + private Builder(com.thoughtworks.samples.hadoop.avro.User.Builder other) { + super(other); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.favorite_number)) { + this.favorite_number = data().deepCopy(fields()[1].schema(), other.favorite_number); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.favorite_color)) { + this.favorite_color = data().deepCopy(fields()[2].schema(), other.favorite_color); + fieldSetFlags()[2] = true; + } + } + + /** Creates a Builder by copying an existing User instance */ + private Builder(com.thoughtworks.samples.hadoop.avro.User other) { + super(com.thoughtworks.samples.hadoop.avro.User.SCHEMA$); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.favorite_number)) { + this.favorite_number = data().deepCopy(fields()[1].schema(), other.favorite_number); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.favorite_color)) { + this.favorite_color = data().deepCopy(fields()[2].schema(), other.favorite_color); + fieldSetFlags()[2] = true; + } + } + + /** Gets the value of the 'name' field */ + public java.lang.CharSequence getName() { + return name; + } + + /** Sets the value of the 'name' field */ + public com.thoughtworks.samples.hadoop.avro.User.Builder setName(java.lang.CharSequence value) { + validate(fields()[0], value); + this.name = value; + fieldSetFlags()[0] = true; + return this; + } + + /** Checks whether the 'name' field has been set */ + public boolean hasName() { + return fieldSetFlags()[0]; + } + + /** Clears the value of the 'name' field */ + public com.thoughtworks.samples.hadoop.avro.User.Builder clearName() { + name = null; + fieldSetFlags()[0] = false; + return this; + } + + /** Gets the value of the 'favorite_number' field */ + public java.lang.Integer getFavoriteNumber() { + return favorite_number; + } + + /** Sets the value of the 'favorite_number' field */ + public com.thoughtworks.samples.hadoop.avro.User.Builder setFavoriteNumber(java.lang.Integer value) { + validate(fields()[1], value); + this.favorite_number = value; + fieldSetFlags()[1] = true; + return this; + } + + /** Checks whether the 'favorite_number' field has been set */ + public boolean hasFavoriteNumber() { + return fieldSetFlags()[1]; + } + + /** Clears the value of the 'favorite_number' field */ + public com.thoughtworks.samples.hadoop.avro.User.Builder clearFavoriteNumber() { + favorite_number = null; + fieldSetFlags()[1] = false; + return this; + } + + /** Gets the value of the 'favorite_color' field */ + public java.lang.CharSequence getFavoriteColor() { + return favorite_color; + } + + /** Sets the value of the 'favorite_color' field */ + public com.thoughtworks.samples.hadoop.avro.User.Builder setFavoriteColor(java.lang.CharSequence value) { + validate(fields()[2], value); + this.favorite_color = value; + fieldSetFlags()[2] = true; + return this; + } + + /** Checks whether the 'favorite_color' field has been set */ + public boolean hasFavoriteColor() { + return fieldSetFlags()[2]; + } + + /** Clears the value of the 'favorite_color' field */ + public com.thoughtworks.samples.hadoop.avro.User.Builder clearFavoriteColor() { + favorite_color = null; + fieldSetFlags()[2] = false; + return this; + } + + @Override + public User build() { + try { + User record = new User(); + record.name = fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]); + record.favorite_number = fieldSetFlags()[1] ? this.favorite_number : (java.lang.Integer) defaultValue(fields()[1]); + record.favorite_color = fieldSetFlags()[2] ? this.favorite_color : (java.lang.CharSequence) defaultValue(fields()[2]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } +}