本文整理汇总了Java中com.twitter.data.proto.tutorial.thrift.AddressBook类的典型用法代码示例。如果您正苦于以下问题:Java AddressBook类的具体用法?Java AddressBook怎么用?Java AddressBook使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AddressBook类属于com.twitter.data.proto.tutorial.thrift包,在下文中一共展示了AddressBook类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testToMessageType
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testToMessageType() throws Exception {
String expected =
"message ParquetSchema {\n" +
" optional group persons (LIST) = 1 {\n" +
" repeated group persons_tuple {\n" +
" required group name = 1 {\n" +
" optional binary first_name (UTF8) = 1;\n" +
" optional binary last_name (UTF8) = 2;\n" +
" }\n" +
" optional int32 id = 2;\n" +
" optional binary email (UTF8) = 3;\n" +
" optional group phones (LIST) = 4 {\n" +
" repeated group phones_tuple {\n" +
" optional binary number (UTF8) = 1;\n" +
" optional binary type (ENUM) = 2;\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
ThriftSchemaConverter schemaConverter = new ThriftSchemaConverter();
final MessageType converted = schemaConverter.convert(AddressBook.class);
assertEquals(MessageTypeParser.parseMessageType(expected), converted);
}
示例2: testPullingInRequiredStructWithFilter
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testPullingInRequiredStructWithFilter() throws Exception {
final String projectionFilterDesc = "persons/{id};persons/email";
TBase toWrite = new AddressBook(
Arrays.asList(
new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
//Name is a required field, but is projected out. To make the thrift record pass validation, the name field is filled
//with empty string
TBase toRead = new AddressBook(
Arrays.asList(
new Person(
new Name("", ""),
0,
"[email protected]",
null)));
shouldDoProjectionWithThriftColumnFilter(projectionFilterDesc, toWrite, toRead, AddressBook.class);
}
示例3: testProjectOutOptionalFields
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testProjectOutOptionalFields() throws Exception {
final String projectionFilterDesc = "persons/name/*";
TBase toWrite = new AddressBook(
Arrays.asList(
new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
//emails and phones are optional fields that do not match the projection filter
TBase toRead = new AddressBook(
Arrays.asList(
new Person(
new Name("Bob", "Roberts"),
0,
null,
null))
);
shouldDoProjectionWithThriftColumnFilter(projectionFilterDesc, toWrite, toRead, AddressBook.class);
}
示例4: testWriteFile
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testWriteFile() throws IOException, InterruptedException, TException {
final AddressBook a = new AddressBook(
Arrays.asList(
new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
final Path fileToCreate = createFile(a);
ParquetReader<Group> reader = createRecordReader(fileToCreate);
Group g = null;
int i = 0;
while((g = reader.read()) != null) {
assertEquals(a.persons.size(), g.getFieldRepetitionCount("persons"));
assertEquals(a.persons.get(0).email, g.getGroup("persons", 0).getGroup(0, 0).getString("email", 0));
// just some sanity check, we're testing the various layers somewhere else
++i;
}
assertEquals("read 1 record", 1, i);
}
示例5: testRead
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testRead() throws Exception {
final PhoneNumber phoneNumber = new PhoneNumber("5555555555");
phoneNumber.type = MOBILE;
List<Person> persons = Arrays.asList(
new Person(
new Name("john", "johson"),
1,
"[email protected]",
Arrays.asList(phoneNumber)
),
new Person(
new Name("jack", "jackson"),
2,
"[email protected]",
Arrays.asList(new PhoneNumber("5555555556"))
)
);
AddressBook expected = new AddressBook(persons);
validate(expected);
}
示例6: testProtocolAddressBook
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testProtocolAddressBook() throws Exception {
ArrayList<Person> persons = new ArrayList<Person>();
final PhoneNumber phoneNumber = new PhoneNumber("555 999 9998");
phoneNumber.type = PhoneType.HOME;
persons.add(
new Person(
new Name("Bob", "Roberts"),
1,
"[email protected]",
Arrays.asList(new PhoneNumber("555 999 9999"), phoneNumber)));
persons.add(
new Person(
new Name("Dick", "Richardson"),
2,
"[email protected]",
Arrays.asList(new PhoneNumber("555 999 9997"), new PhoneNumber("555 999 9996"))));
AddressBook a = new AddressBook(persons);
validateSameTupleAsEB(a);
}
示例7: testThriftOptionalFieldsWithReadProjectionUsingParquetSchema
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testThriftOptionalFieldsWithReadProjectionUsingParquetSchema() throws Exception {
// test with projection
Configuration conf = new Configuration();
final String readProjectionSchema = "message AddressBook {\n" +
" optional group persons {\n" +
" repeated group persons_tuple {\n" +
" required group name {\n" +
" optional binary first_name;\n" +
" optional binary last_name;\n" +
" }\n" +
" optional int32 id;\n" +
" }\n" +
" }\n" +
"}";
conf.set(ReadSupport.PARQUET_READ_SCHEMA, readProjectionSchema);
TBase toWrite = new AddressBook(
Arrays.asList(
new Person(
new Name("Bob", "Roberts"),
0,
"[email protected]",
Arrays.asList(new PhoneNumber("1234567890")))));
TBase toRead = new AddressBook(
Arrays.asList(
new Person(
new Name("Bob", "Roberts"),
0,
null,
null)));
shouldDoProjection(conf, toWrite, toRead, AddressBook.class);
}
示例8: nextAddressbook
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
public static AddressBook nextAddressbook(int i) {
final ArrayList<Person> persons = new ArrayList<Person>();
for (int j = 0; j < i % 3; j++) {
final ArrayList<PhoneNumber> phones = new ArrayList<PhoneNumber>();
for (int k = 0; k < i%4; k++) {
phones.add(new PhoneNumber("12345"+i));
}
persons.add(new Person(new Name("John"+i, "Roberts"), i, "[email protected]" + i, phones));
}
AddressBook a = new AddressBook(persons);
return a;
}
示例9: testProtocolEmptyAdressBook
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testProtocolEmptyAdressBook() throws Exception {
String[] expectations = {
"startMessage()",
"startField(persons, 0)",
"startGroup()",
"endGroup()",
"endField(persons, 0)",
"endMessage()"
};
AddressBook a = new AddressBook(new ArrayList<Person>());
validatePig(expectations, a);
validateThrift(expectations, a);
}
示例10: testToThriftType
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testToThriftType() throws Exception {
final StructType converted = ThriftSchemaConverter.toStructType(AddressBook.class);
final String json = converted.toJSON();
final ThriftType fromJSON = StructType.fromJSON(json);
assertEquals(json, fromJSON.toJSON());
}
示例11: run
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
public void run(org.apache.hadoop.mapreduce.Mapper<LongWritable,Text,Void,AddressBook>.Context context) throws IOException, InterruptedException {
for (int i = 0; i < 10; i++) {
AddressBook a = TestInputOutputFormat.nextAddressbook(i);
context.write(null, a);
}
}
示例12: map
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
protected void map(Void key, AddressBook value, Mapper<Void,Group,LongWritable,Text>.Context context) throws IOException ,InterruptedException {
context.write(null, new Text(value.toString()));
}
示例13: testReadEmpty
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testReadEmpty() throws Exception {
AddressBook expected = new AddressBook();
validate(expected);
}
示例14: testProtocolEmptyAdressBook
import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testProtocolEmptyAdressBook() throws Exception {
AddressBook a = new AddressBook(new ArrayList<Person>());
validateSameTupleAsEB(a);
}