当前位置: 首页>>代码示例>>Java>>正文


Java AddressBook类代码示例

本文整理汇总了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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:26,代码来源:TestThriftSchemaConverter.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:23,代码来源:TestParquetToThriftReadWriteAndProjection.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:26,代码来源:TestParquetToThriftReadWriteAndProjection.java

示例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);

}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:26,代码来源:TestThriftToParquetFileWriter.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:22,代码来源:TestParquetReadProtocol.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:21,代码来源:TestThriftToPigCompatibility.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:34,代码来源:TestParquetToThriftReadWriteAndProjection.java

示例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;
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:13,代码来源:TestInputOutputFormat.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:15,代码来源:TestParquetWriteProtocol.java

示例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());
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:8,代码来源:TestThriftSchemaConverter.java

示例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);
  }
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:7,代码来源:TestInputOutputFormat.java

示例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()));
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:4,代码来源:TestInputOutputFormat.java

示例13: testReadEmpty

import com.twitter.data.proto.tutorial.thrift.AddressBook; //导入依赖的package包/类
@Test
public void testReadEmpty() throws Exception {
  AddressBook expected = new AddressBook();
  validate(expected);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:6,代码来源:TestParquetReadProtocol.java

示例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);
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:7,代码来源:TestThriftToPigCompatibility.java


注:本文中的com.twitter.data.proto.tutorial.thrift.AddressBook类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。