Class ThriftSchema
- All Implemented Interfaces:
Serializable
,SchemaProvider
- Primitive type mapping is straight-forward (e.g.
TType.I32
->Schema.FieldType.INT32
). TType.STRING
gets mapped as eitherSchema.FieldType.STRING
orSchema.FieldType.BYTES
, depending on whether theFieldValueMetaData.isBinary()
flag is set.TType.MAP
becomesa beam map
passing the key and value types recursively.TType.SET
gets translated into a beamiterable
, passing the corresponding element type.TType.LIST
becomes anarray
of the corresponding element type.thrift enums
are converted intobeam enumeration types
.thrift union
types get mapped tobeam one-of
types.
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 enums
implementingTEnum
. - All
TUnion
types 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.Customizer
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.<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 theTypeDescriptor
not 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 theTypeDescriptor
not subject to the type erasure.static @NonNull SchemaProvider
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).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 theTypeDescriptor
not subject to the type erasure.Methods inherited from class org.apache.beam.sdk.schemas.GetterBasedSchemaProviderV2
fieldValueGetters, fieldValueTypeInformations, schemaTypeCreator
Methods 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> StringSet
will 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:SchemaProvider
Lookup 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:GetterBasedSchemaProvider
Delegates to theGetterBasedSchemaProvider.fieldValueGetters(Class, Schema)
for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptor
not subject to the type erasure.- Specified by:
fieldValueGetters
in classGetterBasedSchemaProviderV2
-
fieldValueTypeInformations
public @NonNull List<FieldValueTypeInformation> fieldValueTypeInformations(@NonNull TypeDescriptor<?> targetTypeDescriptor, @NonNull Schema schema) Description copied from class:GetterBasedSchemaProvider
Delegates to theGetterBasedSchemaProvider.fieldValueTypeInformations(Class, Schema)
for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptor
not subject to the type erasure.- Specified by:
fieldValueTypeInformations
in classGetterBasedSchemaProviderV2
-
schemaTypeCreator
public @NonNull SchemaUserTypeCreator schemaTypeCreator(@NonNull TypeDescriptor<?> targetTypeDescriptor, @NonNull Schema schema) Description copied from class:GetterBasedSchemaProvider
Delegates to theGetterBasedSchemaProvider.schemaTypeCreator(Class, Schema)
for backwards compatibility, override it if you want to use the richer type signature contained in theTypeDescriptor
not subject to the type erasure.- Specified by:
schemaTypeCreator
in classGetterBasedSchemaProviderV2
-