def to_runner_api_parameter(self, unused_context):
     _args_schema = named_fields_to_schema([
         (f'arg{ix}', convert_to_typing_type(instance_to_type(value)))
         for (ix, value) in enumerate(self._args)
     ])
     _kwargs_schema = named_fields_to_schema([
         (key, convert_to_typing_type(instance_to_type(value)))
         for (key, value) in self._kwargs.items()
     ])
     payload_schema = named_fields_to_schema({
         'constructor': str,
         'args': _args_schema,
         'kwargs': _kwargs_schema,
     })
     return (PYTHON_FULLY_QUALIFIED_NAMED_TRANSFORM_URN,
             external_transforms_pb2.ExternalConfigurationPayload(
                 schema=payload_schema,
                 payload=coders.RowCoder(payload_schema).encode(
                     Row(constructor=self._constructor,
                         args=Row(
                             **{
                                 f'arg{ix}': arg
                                 for (ix, arg) in enumerate(self._args)
                             }),
                         kwargs=Row(**self._kwargs)), )))
Exemplo n.º 2
0
def parse_string_payload(input_byte):
    payload = external_transforms_pb2.ExternalConfigurationPayload()
    payload.ParseFromString(input_byte)

    return RowCoder(payload.schema).decode(payload.payload)._asdict()
Exemplo n.º 3
0
 def build(self):
     row = self._get_named_tuple_instance()
     schema = named_tuple_to_schema(type(row))
     return external_transforms_pb2.ExternalConfigurationPayload(
         schema=schema, payload=RowCoder(schema).encode(row))
Exemplo n.º 4
0
def get_payload(cls):
    payload = external_transforms_pb2.ExternalConfigurationPayload()
    payload.ParseFromString(cls._payload)
    return payload