-
-
Save felixgao/bad532ca171a31a3e527 to your computer and use it in GitHub Desktop.
scalding avro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Autogenerated by Avro | |
* | |
* DO NOT EDIT DIRECTLY | |
*/ | |
package com.bluekai.analytics.jobs; | |
@SuppressWarnings("all") | |
@org.apache.avro.specific.AvroGenerated | |
public class SiteCatNsTuple 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\":\"SiteCatNsTuple\",\"namespace\":\"com.bluekai.analytics.jobs\",\"fields\":[{\"name\":\"site\",\"type\":\"int\"},{\"name\":\"ns\",\"type\":\"int\"},{\"name\":\"cat\",\"type\":\"int\"}]}"); | |
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } | |
@Deprecated public int site; | |
@Deprecated public int ns; | |
@Deprecated public int cat; | |
/** | |
* Default constructor. Note that this does not initialize fields | |
* to their default values from the schema. If that is desired then | |
* one should use <code>newBuilder()</code>. | |
*/ | |
public SiteCatNsTuple() {} | |
/** | |
* All-args constructor. | |
*/ | |
public SiteCatNsTuple(java.lang.Integer site, java.lang.Integer ns, java.lang.Integer cat) { | |
this.site = site; | |
this.ns = ns; | |
this.cat = cat; | |
} | |
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 site; | |
case 1: return ns; | |
case 2: return cat; | |
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: site = (java.lang.Integer)value$; break; | |
case 1: ns = (java.lang.Integer)value$; break; | |
case 2: cat = (java.lang.Integer)value$; break; | |
default: throw new org.apache.avro.AvroRuntimeException("Bad index"); | |
} | |
} | |
/** | |
* Gets the value of the 'site' field. | |
*/ | |
public java.lang.Integer getSite() { | |
return site; | |
} | |
/** | |
* Sets the value of the 'site' field. | |
* @param value the value to set. | |
*/ | |
public void setSite(java.lang.Integer value) { | |
this.site = value; | |
} | |
/** | |
* Gets the value of the 'ns' field. | |
*/ | |
public java.lang.Integer getNs() { | |
return ns; | |
} | |
/** | |
* Sets the value of the 'ns' field. | |
* @param value the value to set. | |
*/ | |
public void setNs(java.lang.Integer value) { | |
this.ns = value; | |
} | |
/** | |
* Gets the value of the 'cat' field. | |
*/ | |
public java.lang.Integer getCat() { | |
return cat; | |
} | |
/** | |
* Sets the value of the 'cat' field. | |
* @param value the value to set. | |
*/ | |
public void setCat(java.lang.Integer value) { | |
this.cat = value; | |
} | |
/** Creates a new SiteCatNsTuple RecordBuilder */ | |
public static com.bluekai.analytics.jobs.SiteCatNsTuple.Builder newBuilder() { | |
return new com.bluekai.analytics.jobs.SiteCatNsTuple.Builder(); | |
} | |
/** Creates a new SiteCatNsTuple RecordBuilder by copying an existing Builder */ | |
public static com.bluekai.analytics.jobs.SiteCatNsTuple.Builder newBuilder(com.bluekai.analytics.jobs.SiteCatNsTuple.Builder other) { | |
return new com.bluekai.analytics.jobs.SiteCatNsTuple.Builder(other); | |
} | |
/** Creates a new SiteCatNsTuple RecordBuilder by copying an existing SiteCatNsTuple instance */ | |
public static com.bluekai.analytics.jobs.SiteCatNsTuple.Builder newBuilder(com.bluekai.analytics.jobs.SiteCatNsTuple other) { | |
return new com.bluekai.analytics.jobs.SiteCatNsTuple.Builder(other); | |
} | |
/** | |
* RecordBuilder for SiteCatNsTuple instances. | |
*/ | |
public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<SiteCatNsTuple> | |
implements org.apache.avro.data.RecordBuilder<SiteCatNsTuple> { | |
private int site; | |
private int ns; | |
private int cat; | |
/** Creates a new Builder */ | |
private Builder() { | |
super(SCHEMA$); | |
} | |
/** Creates a Builder by copying an existing Builder */ | |
private Builder(com.bluekai.analytics.jobs.SiteCatNsTuple.Builder other) { | |
super(other); | |
if (isValidValue(fields()[0], other.site)) { | |
this.site = data().deepCopy(fields()[0].schema(), other.site); | |
fieldSetFlags()[0] = true; | |
} | |
if (isValidValue(fields()[1], other.ns)) { | |
this.ns = data().deepCopy(fields()[1].schema(), other.ns); | |
fieldSetFlags()[1] = true; | |
} | |
if (isValidValue(fields()[2], other.cat)) { | |
this.cat = data().deepCopy(fields()[2].schema(), other.cat); | |
fieldSetFlags()[2] = true; | |
} | |
} | |
/** Creates a Builder by copying an existing SiteCatNsTuple instance */ | |
private Builder(com.bluekai.analytics.jobs.SiteCatNsTuple other) { | |
super(SCHEMA$); | |
if (isValidValue(fields()[0], other.site)) { | |
this.site = data().deepCopy(fields()[0].schema(), other.site); | |
fieldSetFlags()[0] = true; | |
} | |
if (isValidValue(fields()[1], other.ns)) { | |
this.ns = data().deepCopy(fields()[1].schema(), other.ns); | |
fieldSetFlags()[1] = true; | |
} | |
if (isValidValue(fields()[2], other.cat)) { | |
this.cat = data().deepCopy(fields()[2].schema(), other.cat); | |
fieldSetFlags()[2] = true; | |
} | |
} | |
/** Gets the value of the 'site' field */ | |
public java.lang.Integer getSite() { | |
return site; | |
} | |
/** Sets the value of the 'site' field */ | |
public com.bluekai.analytics.jobs.SiteCatNsTuple.Builder setSite(int value) { | |
validate(fields()[0], value); | |
this.site = value; | |
fieldSetFlags()[0] = true; | |
return this; | |
} | |
/** Checks whether the 'site' field has been set */ | |
public boolean hasSite() { | |
return fieldSetFlags()[0]; | |
} | |
/** Clears the value of the 'site' field */ | |
public com.bluekai.analytics.jobs.SiteCatNsTuple.Builder clearSite() { | |
fieldSetFlags()[0] = false; | |
return this; | |
} | |
/** Gets the value of the 'ns' field */ | |
public java.lang.Integer getNs() { | |
return ns; | |
} | |
/** Sets the value of the 'ns' field */ | |
public com.bluekai.analytics.jobs.SiteCatNsTuple.Builder setNs(int value) { | |
validate(fields()[1], value); | |
this.ns = value; | |
fieldSetFlags()[1] = true; | |
return this; | |
} | |
/** Checks whether the 'ns' field has been set */ | |
public boolean hasNs() { | |
return fieldSetFlags()[1]; | |
} | |
/** Clears the value of the 'ns' field */ | |
public com.bluekai.analytics.jobs.SiteCatNsTuple.Builder clearNs() { | |
fieldSetFlags()[1] = false; | |
return this; | |
} | |
/** Gets the value of the 'cat' field */ | |
public java.lang.Integer getCat() { | |
return cat; | |
} | |
/** Sets the value of the 'cat' field */ | |
public com.bluekai.analytics.jobs.SiteCatNsTuple.Builder setCat(int value) { | |
validate(fields()[2], value); | |
this.cat = value; | |
fieldSetFlags()[2] = true; | |
return this; | |
} | |
/** Checks whether the 'cat' field has been set */ | |
public boolean hasCat() { | |
return fieldSetFlags()[2]; | |
} | |
/** Clears the value of the 'cat' field */ | |
public com.bluekai.analytics.jobs.SiteCatNsTuple.Builder clearCat() { | |
fieldSetFlags()[2] = false; | |
return this; | |
} | |
@Override | |
public SiteCatNsTuple build() { | |
try { | |
SiteCatNsTuple record = new SiteCatNsTuple(); | |
record.site = fieldSetFlags()[0] ? this.site : (java.lang.Integer) defaultValue(fields()[0]); | |
record.ns = fieldSetFlags()[1] ? this.ns : (java.lang.Integer) defaultValue(fields()[1]); | |
record.cat = fieldSetFlags()[2] ? this.cat : (java.lang.Integer) defaultValue(fields()[2]); | |
return record; | |
} catch (Exception e) { | |
throw new org.apache.avro.AvroRuntimeException(e); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bluekai.ds | |
import com.twitter.scalding._ | |
import scala.collection.JavaConverters._ | |
import com.twitter.scalding.avro._ | |
import com.bluekai.analytics.jobs.{UserProfileFlatAggregate} | |
class Test(args: Args) extends Job(args) { | |
override def config: Map[AnyRef, AnyRef] = { | |
super.config ++ Map("cascading.app.appjar.class" -> classOf[Test]) | |
} | |
val input = args("input") | |
val avro = PackedAvroSource[UserProfileFlatAggregate](args("input")).read | |
.flatMapTo('UserProfileFlatAggregate -> ('uuid, 'cat)) { | |
userProfile: UserProfileFlatAggregate => | |
val uuid = userProfile.getUuid.toString | |
val tuples = userProfile.getProfile.asScala | |
for (t <- tuples) yield (uuid, t.getCat) | |
}.debug | |
.write(Tsv("/temp/output.tsv")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Autogenerated by Avro | |
* | |
* DO NOT EDIT DIRECTLY | |
*/ | |
package com.bluekai.analytics.jobs; | |
@SuppressWarnings("all") | |
@org.apache.avro.specific.AvroGenerated | |
public class UserProfileFlatAggregate 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\":\"UserProfileFlatAggregate\",\"namespace\":\"com.bluekai.analytics.jobs\",\"fields\":[{\"name\":\"uuid\",\"type\":\"string\"},{\"name\":\"profile\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"SiteCatNsTuple\",\"fields\":[{\"name\":\"site\",\"type\":\"int\"},{\"name\":\"ns\",\"type\":\"int\"},{\"name\":\"cat\",\"type\":\"int\"}]}},\"aliases\":[\"bag\"]}]}"); | |
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } | |
@Deprecated public java.lang.CharSequence uuid; | |
@Deprecated public java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> profile; | |
/** | |
* Default constructor. Note that this does not initialize fields | |
* to their default values from the schema. If that is desired then | |
* one should use <code>newBuilder()</code>. | |
*/ | |
public UserProfileFlatAggregate() {} | |
/** | |
* All-args constructor. | |
*/ | |
public UserProfileFlatAggregate(java.lang.CharSequence uuid, java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> profile) { | |
this.uuid = uuid; | |
this.profile = profile; | |
} | |
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 uuid; | |
case 1: return profile; | |
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: uuid = (java.lang.CharSequence)value$; break; | |
case 1: profile = (java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple>)value$; break; | |
default: throw new org.apache.avro.AvroRuntimeException("Bad index"); | |
} | |
} | |
/** | |
* Gets the value of the 'uuid' field. | |
*/ | |
public java.lang.CharSequence getUuid() { | |
return uuid; | |
} | |
/** | |
* Sets the value of the 'uuid' field. | |
* @param value the value to set. | |
*/ | |
public void setUuid(java.lang.CharSequence value) { | |
this.uuid = value; | |
} | |
/** | |
* Gets the value of the 'profile' field. | |
*/ | |
public java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> getProfile() { | |
return profile; | |
} | |
/** | |
* Sets the value of the 'profile' field. | |
* @param value the value to set. | |
*/ | |
public void setProfile(java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> value) { | |
this.profile = value; | |
} | |
/** Creates a new UserProfileFlatAggregate RecordBuilder */ | |
public static com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder newBuilder() { | |
return new com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder(); | |
} | |
/** Creates a new UserProfileFlatAggregate RecordBuilder by copying an existing Builder */ | |
public static com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder newBuilder(com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder other) { | |
return new com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder(other); | |
} | |
/** Creates a new UserProfileFlatAggregate RecordBuilder by copying an existing UserProfileFlatAggregate instance */ | |
public static com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder newBuilder(com.bluekai.analytics.jobs.UserProfileFlatAggregate other) { | |
return new com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder(other); | |
} | |
/** | |
* RecordBuilder for UserProfileFlatAggregate instances. | |
*/ | |
public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<UserProfileFlatAggregate> | |
implements org.apache.avro.data.RecordBuilder<UserProfileFlatAggregate> { | |
private java.lang.CharSequence uuid; | |
private java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> profile; | |
/** Creates a new Builder */ | |
private Builder() { | |
super(SCHEMA$); | |
} | |
/** Creates a Builder by copying an existing Builder */ | |
private Builder(com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder other) { | |
super(other); | |
if (isValidValue(fields()[0], other.uuid)) { | |
this.uuid = data().deepCopy(fields()[0].schema(), other.uuid); | |
fieldSetFlags()[0] = true; | |
} | |
if (isValidValue(fields()[1], other.profile)) { | |
this.profile = data().deepCopy(fields()[1].schema(), other.profile); | |
fieldSetFlags()[1] = true; | |
} | |
} | |
/** Creates a Builder by copying an existing UserProfileFlatAggregate instance */ | |
private Builder(com.bluekai.analytics.jobs.UserProfileFlatAggregate other) { | |
super(SCHEMA$); | |
if (isValidValue(fields()[0], other.uuid)) { | |
this.uuid = data().deepCopy(fields()[0].schema(), other.uuid); | |
fieldSetFlags()[0] = true; | |
} | |
if (isValidValue(fields()[1], other.profile)) { | |
this.profile = data().deepCopy(fields()[1].schema(), other.profile); | |
fieldSetFlags()[1] = true; | |
} | |
} | |
/** Gets the value of the 'uuid' field */ | |
public java.lang.CharSequence getUuid() { | |
return uuid; | |
} | |
/** Sets the value of the 'uuid' field */ | |
public com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder setUuid(java.lang.CharSequence value) { | |
validate(fields()[0], value); | |
this.uuid = value; | |
fieldSetFlags()[0] = true; | |
return this; | |
} | |
/** Checks whether the 'uuid' field has been set */ | |
public boolean hasUuid() { | |
return fieldSetFlags()[0]; | |
} | |
/** Clears the value of the 'uuid' field */ | |
public com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder clearUuid() { | |
uuid = null; | |
fieldSetFlags()[0] = false; | |
return this; | |
} | |
/** Gets the value of the 'profile' field */ | |
public java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> getProfile() { | |
return profile; | |
} | |
/** Sets the value of the 'profile' field */ | |
public com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder setProfile(java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple> value) { | |
validate(fields()[1], value); | |
this.profile = value; | |
fieldSetFlags()[1] = true; | |
return this; | |
} | |
/** Checks whether the 'profile' field has been set */ | |
public boolean hasProfile() { | |
return fieldSetFlags()[1]; | |
} | |
/** Clears the value of the 'profile' field */ | |
public com.bluekai.analytics.jobs.UserProfileFlatAggregate.Builder clearProfile() { | |
profile = null; | |
fieldSetFlags()[1] = false; | |
return this; | |
} | |
@Override | |
public UserProfileFlatAggregate build() { | |
try { | |
UserProfileFlatAggregate record = new UserProfileFlatAggregate(); | |
record.uuid = fieldSetFlags()[0] ? this.uuid : (java.lang.CharSequence) defaultValue(fields()[0]); | |
record.profile = fieldSetFlags()[1] ? this.profile : (java.util.List<com.bluekai.analytics.jobs.SiteCatNsTuple>) defaultValue(fields()[1]); | |
return record; | |
} catch (Exception e) { | |
throw new org.apache.avro.AvroRuntimeException(e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment