Beispiel #1
0
    def to_python_value(self, ctx: FlyteContext, lv: Literal, expected_python_type: Type[T]) -> T:
        if not (lv and lv.scalar and lv.scalar.generic):
            raise AssertionError("Can only covert a generic literal to a Protobuf")

        pb_obj = expected_python_type()
        dictionary = _MessageToDict(lv.scalar.generic)
        pb_obj = _ParseDict(dictionary, pb_obj)
        return pb_obj
Beispiel #2
0
 def to_python_std(self):
     """
     :returns: The protobuf object as defined by the user.
     :rtype: T
     """
     pb_obj = type(self).pb_type()
     try:
         dictionary = _MessageToDict(self.scalar.generic)
         pb_obj = _ParseDict(dictionary, pb_obj)
     except Error as err:
         raise _user_exceptions.FlyteTypeException(
             received_type="generic",
             expected_type=type(self).pb_type,
             received_value=_base64.b64encode(self.scalar.generic),
             additional_msg=f"Can not deserialize. Error: {err.__str__()}",
         )
     return pb_obj
Beispiel #3
0
    def promote_from_model(cls, literal_model):
        """
        Creates an object of this type from the model primitive defining it.
        :param flytekit.models.literals.Literal literal_model:
        :rtype: Protobuf
        """
        pb_obj = cls.pb_type()
        try:
            dictionary = _MessageToDict(literal_model.scalar.generic)
            pb_obj = _ParseDict(dictionary, pb_obj)
        except Error as err:
            raise _user_exceptions.FlyteTypeException(
                received_type="generic",
                expected_type=cls.pb_type,
                received_value=_base64.b64encode(literal_model.scalar.generic),
                additional_msg=f"Can not deserialize. Error: {err.__str__()}",
            )

        return cls(pb_obj)
Beispiel #4
0
 def _transform_for_user_output(self, outputs):
     """
     Just execute the function and return the list of Hive queries returned.
     :param dict[Text,flytekit.models.common.FlyteIdlEntity] outputs:
     :rtype: list[Text]
     """
     futures = outputs.get(_sdk_constants.FUTURES_FILE_NAME)
     if futures:
         queries = []
         task_ids_to_defs = {
             t.id.name: _qubole_models.QuboleHiveJob.from_flyte_idl(
                 _ParseDict(t.custom, _qubole_pb2.QuboleHiveJob()))
             for t in futures.tasks
         }
         for node in futures.nodes:
             queries.append(task_ids_to_defs[
                 node.task_node.reference_id.name].query.query)
         return queries
     else:
         return []
Beispiel #5
0
def from_dict(full_name, _dict):
    msg = get_symbol(full_name)()
    return _ParseDict(_dict, msg)