@Experimental(value=SCHEMAS) public final class ThriftSchema extends GetterBasedSchemaProvider
TType.I32
-> Schema.FieldType.INT32
).
TType.STRING
gets mapped as either Schema.FieldType.STRING
or Schema.FieldType.BYTES
, depending on whether the FieldValueMetaData.isBinary()
flag is
set.
TType.MAP
becomes a beam map
passing
the key and value types recursively.
TType.SET
gets translated into a beam iterable
, passing the corresponding element type.
TType.LIST
becomes an array
of the corresponding
element type.
thrift enums
are converted into beam enumeration
types
.
thrift union
types get mapped to beam 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:
TBase
, except for enums which become java enums
implementing TEnum
.
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.
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.
Modifier and Type | Class and Description |
---|---|
static class |
ThriftSchema.Customizer |
Modifier and Type | Method and Description |
---|---|
static @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.
|
@NonNull java.util.List<FieldValueGetter> |
fieldValueGetters(@NonNull java.lang.Class<?> targetClass,
@NonNull Schema schema)
Implementing class should override to return FieldValueGetters.
|
@NonNull java.util.List<FieldValueTypeInformation> |
fieldValueTypeInformations(@NonNull java.lang.Class<?> targetClass,
@NonNull Schema schema)
Implementing class should override to return a list of type-informations.
|
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).
|
<T> @NonNull Schema |
schemaFor(TypeDescriptor<T> typeDescriptor)
Lookup a schema for the given type.
|
@NonNull SchemaUserTypeCreator |
schemaTypeCreator(@NonNull java.lang.Class<?> targetClass,
@NonNull Schema schema)
Implementing class should override to return a constructor.
|
equals, fromRowFunction, hashCode, toRowFunction
public static @NonNull SchemaProvider provider()
public static @NonNull ThriftSchema.Customizer custom()
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()
.
public <T> @NonNull Schema schemaFor(TypeDescriptor<T> typeDescriptor)
SchemaProvider
public @NonNull java.util.List<FieldValueGetter> fieldValueGetters(@NonNull java.lang.Class<?> targetClass, @NonNull Schema schema)
GetterBasedSchemaProvider
fieldValueGetters
in class GetterBasedSchemaProvider
public @NonNull java.util.List<FieldValueTypeInformation> fieldValueTypeInformations(@NonNull java.lang.Class<?> targetClass, @NonNull Schema schema)
GetterBasedSchemaProvider
fieldValueTypeInformations
in class GetterBasedSchemaProvider
public @NonNull SchemaUserTypeCreator schemaTypeCreator(@NonNull java.lang.Class<?> targetClass, @NonNull Schema schema)
GetterBasedSchemaProvider
schemaTypeCreator
in class GetterBasedSchemaProvider