Java Code Examples for org.apache.beam.sdk.schemas.Schema#Options

The following examples show how to use org.apache.beam.sdk.schemas.Schema#Options . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoDynamicMessageSchema.java    From beam with Apache License 2.0 5 votes vote down vote up
Convert(Schema.Field field) {
  Schema.Options options = field.getOptions();
  if (options.hasOption(SCHEMA_OPTION_META_NUMBER)) {
    this.number = options.getValue(SCHEMA_OPTION_META_NUMBER);
  } else {
    this.number = -1;
  }
}
 
Example 2
Source File: ProtoSchemaTranslatorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionsInt32OnField() {
  Schema schema = ProtoSchemaTranslator.getSchema(Proto3SchemaMessages.OptionMessage.class);
  Schema.Options options = schema.getField("field_one").getOptions();
  assertEquals(
      Integer.valueOf(13),
      options.getValue("beam:option:proto:field:proto3_schema_options.field_option_int"));
}
 
Example 3
Source File: ProtoSchemaTranslatorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionsStringOnField() {
  Schema schema = ProtoSchemaTranslator.getSchema(Proto3SchemaMessages.OptionMessage.class);
  Schema.Options options = schema.getField("field_one").getOptions();
  assertEquals(
      "this is a field string",
      options.getValue("beam:option:proto:field:proto3_schema_options.field_option_string"));
}
 
Example 4
Source File: ProtoSchemaTranslatorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionsMessageOnField() {
  Schema schema = ProtoSchemaTranslator.getSchema(Proto3SchemaMessages.OptionMessage.class);
  Schema.Options options = schema.getField("field_one").getOptions();
  Row optionMessage =
      options.getValue("beam:option:proto:field:proto3_schema_options.field_option_message");
  assertEquals("foobar in field", optionMessage.getString("single_string"));
  assertEquals(Integer.valueOf(56), optionMessage.getInt32("single_int32"));
  assertEquals(Long.valueOf(78L), optionMessage.getInt64("single_int64"));
}
 
Example 5
Source File: ProtoSchemaTranslatorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionArrayOnField() {
  Schema schema = ProtoSchemaTranslator.getSchema(Proto3SchemaMessages.OptionMessage.class);
  Schema.Options options = schema.getField("field_one").getOptions();
  List verify =
      new ArrayList(
          (Collection)
              options.getValue(
                  "beam:option:proto:field:proto3_schema_options.field_option_repeated"));
  assertEquals("field_string_1", verify.get(0));
  assertEquals("field_string_2", verify.get(1));
  assertEquals("field_string_3", verify.get(2));
}
 
Example 6
Source File: ProtoSchemaTranslatorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionArrayOfMessagesOnField() {
  Schema schema = ProtoSchemaTranslator.getSchema(Proto3SchemaMessages.OptionMessage.class);
  Schema.Options options = schema.getField("field_one").getOptions();
  List verify =
      new ArrayList(
          (Collection)
              options.getValue(
                  "beam:option:proto:field:proto3_schema_options.field_option_repeated_message"));
  assertEquals(
      "string in message in option in field", ((Row) verify.get(0)).getString("single_string"));
  assertEquals(Integer.valueOf(77), ((Row) verify.get(1)).getInt32("single_int32"));
  assertEquals(Long.valueOf(88L), ((Row) verify.get(2)).getInt64("single_int64"));
}
 
Example 7
Source File: TestProtoSchemas.java    From beam with Apache License 2.0 4 votes vote down vote up
static Schema.Options withTypeName(String typeName) {
  return Schema.Options.builder()
      .setOption(SCHEMA_OPTION_META_TYPE_NAME, FieldType.STRING, typeName)
      .build();
}