Class ThriftSchema
- All Implemented Interfaces:
Serializable,SchemaProvider
- Primitive type mapping is straight-forward (e.g.
TType.I32->Schema.FieldType.INT32). TType.STRINGgets mapped as eitherSchema.FieldType.STRINGorSchema.FieldType.BYTES, depending on whether theFieldValueMetaData.isBinary()flag is set.TType.MAPbecomesa beam mappassing the key and value types recursively.TType.SETgets translated into a beamiterable, passing the corresponding element type.TType.LISTbecomes anarrayof the corresponding element type.thrift enumsare converted intobeam enumeration types.thrift uniontypes get mapped tobeam one-oftypes.
The mapping logic relies on the available thrift metadata introspection
and tries to make as few assumptions about the generated code as possible (i.e. does not rely on
accessor naming convention, as the thrift compiler supports options such as "beans" or
"fullcamel"/"nocamel".
However, the following strong assumptions are made by this class:
- All thrift generated classes implement
TBase, except for enums which becomejava enumsimplementingTEnum. - All
TUniontypes provide static factory methods for each of the supported field types, with the same name as the field itself and only one such method taking a single parameter exists. - All non-union types have a corresponding java field with the same name for every field in the original thrift source file.
Thrift typedefs for container types (and possibly others) do not preserve the full type
information. For this reason, this class allows for manual registration of such
"lossy" typedefs with their corresponding beam types.
Note: Thrift encoding and decoding are not fully symmetrical, i.e. the isSet flag may not be preserved upon converting a thrift object to a
beam row and back. On encoding, we extract all thrift values, no matter if the fields are set or
not. On decoding, we set all non-null beam row values to the corresponding thrift fields,
leaving the rest unset.
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull ThriftSchema.Customizercustom()Builds a schema provider that maps any thrift type to a Beam schema, allowing for custom thrift typedef entries (which cannot be resolved using the available metadata) to be manually registered with their corresponding beam types.<T> @NonNull List<FieldValueGetter<@NonNull T, Object>> fieldValueGetters(@NonNull TypeDescriptor<T> targetTypeDescriptor, @NonNull Schema schema) Delegates to theGetterBasedSchemaProvider.fieldValueGetters(Class, Schema)for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptornot subject to the type erasure.fieldValueTypeInformations(@NonNull TypeDescriptor<?> targetTypeDescriptor, @NonNull Schema schema) Delegates to theGetterBasedSchemaProvider.fieldValueTypeInformations(Class, Schema)for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptornot subject to the type erasure.static @NonNull SchemaProviderprovider()Schema provider that maps any thrift type to a Beam schema, assuming that any typedefs that might have been used in the thrift definitions will preserve all required metadata to infer the beam type (which is the case for any primitive typedefs and alike).schemaFor(TypeDescriptor<T> typeDescriptor) Lookup a schema for the given type.schemaTypeCreator(@NonNull TypeDescriptor<?> targetTypeDescriptor, @NonNull Schema schema) Delegates to theGetterBasedSchemaProvider.schemaTypeCreator(Class, Schema)for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptornot subject to the type erasure.Methods inherited from class org.apache.beam.sdk.schemas.GetterBasedSchemaProviderV2
fieldValueGetters, fieldValueTypeInformations, schemaTypeCreatorMethods inherited from class org.apache.beam.sdk.schemas.GetterBasedSchemaProvider
equals, fromRowFunction, hashCode, toRowFunction
-
Method Details
-
provider
Schema provider that maps any thrift type to a Beam schema, assuming that any typedefs that might have been used in the thrift definitions will preserve all required metadata to infer the beam type (which is the case for any primitive typedefs and alike).- See Also:
-
custom
Builds a schema provider that maps any thrift type to a Beam schema, allowing for custom thrift typedef entries (which cannot be resolved using the available metadata) to be manually registered with their corresponding beam types.E.g.
typedef set<string> StringSetwill not carry the element type information and needs to be manually mapped here as.custom().withTypedef("StringSet", FieldType.iterable(FieldType.STRING)).provider(). -
schemaFor
Description copied from interface:SchemaProviderLookup a schema for the given type. If no schema exists, returns null. -
fieldValueGetters
public <T> @NonNull List<FieldValueGetter<@NonNull T,Object>> fieldValueGetters(@NonNull TypeDescriptor<T> targetTypeDescriptor, @NonNull Schema schema) Description copied from class:GetterBasedSchemaProviderDelegates to theGetterBasedSchemaProvider.fieldValueGetters(Class, Schema)for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptornot subject to the type erasure.- Specified by:
fieldValueGettersin classGetterBasedSchemaProviderV2
-
fieldValueTypeInformations
public @NonNull List<FieldValueTypeInformation> fieldValueTypeInformations(@NonNull TypeDescriptor<?> targetTypeDescriptor, @NonNull Schema schema) Description copied from class:GetterBasedSchemaProviderDelegates to theGetterBasedSchemaProvider.fieldValueTypeInformations(Class, Schema)for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptornot subject to the type erasure.- Specified by:
fieldValueTypeInformationsin classGetterBasedSchemaProviderV2
-
schemaTypeCreator
public @NonNull SchemaUserTypeCreator schemaTypeCreator(@NonNull TypeDescriptor<?> targetTypeDescriptor, @NonNull Schema schema) Description copied from class:GetterBasedSchemaProviderDelegates to theGetterBasedSchemaProvider.schemaTypeCreator(Class, Schema)for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptornot subject to the type erasure.- Specified by:
schemaTypeCreatorin classGetterBasedSchemaProviderV2
-