def get_sdk_type_from_literal_type(self, literal_type): """ :param flytekit.models.types.LiteralType literal_type: :rtype: flytekit.common.types.base_sdk_types.FlyteSdkType """ if literal_type.collection_type is not None: return _container_types.List( _helpers.get_sdk_type_from_literal_type( literal_type.collection_type)) elif literal_type.map_value_type is not None: raise NotImplementedError("TODO: Implement map") elif literal_type.schema is not None: return _schema.schema_instantiator_from_proto(literal_type.schema) elif literal_type.blob is not None: return self._get_blob_impl_from_type(literal_type.blob) elif literal_type.simple is not None: if (literal_type.simple == _literal_type_models.SimpleType.BINARY and _proto.Protobuf.PB_FIELD_KEY in literal_type.metadata): return _proto_sdk_type_from_tag( literal_type.metadata[_proto.Protobuf.PB_FIELD_KEY]) if (literal_type.simple == _literal_type_models.SimpleType.STRUCT and literal_type.metadata and _proto.Protobuf.PB_FIELD_KEY in literal_type.metadata): return _generic_proto_sdk_type_from_tag( literal_type.metadata[_proto.Protobuf.PB_FIELD_KEY]) sdk_type = self._SIMPLE_TYPE_LOOKUP_TABLE.get(literal_type.simple) if sdk_type is None: raise NotImplementedError( "We haven't implemented this type yet: Simple type={}". format(literal_type.simple)) return sdk_type else: raise _system_exceptions.FlyteSystemAssertion( "An unrecognized literal type was received: {}".format( literal_type))
def infer_sdk_type_from_literal(self, literal): # noqa """ :param flytekit.models.literals.Literal literal: :rtype: flytekit.common.types.base_sdk_types.FlyteSdkType """ if literal.collection is not None: if len(literal.collection.literals) > 0: sdk_type = _container_types.List( _helpers.infer_sdk_type_from_literal( literal.collection.literals[0])) else: sdk_type = _container_types.List(_base_sdk_types.Void) elif literal.map is not None: raise NotImplementedError("TODO: Implement map") elif literal.scalar.blob is not None: sdk_type = self._get_blob_impl_from_type( literal.scalar.blob.metadata.type) elif literal.scalar.none_type is not None: sdk_type = _base_sdk_types.Void elif literal.scalar.schema is not None: sdk_type = _schema.schema_instantiator_from_proto( literal.scalar.schema.type) elif literal.scalar.error is not None: raise NotImplementedError("TODO: Implement error from literal map") elif literal.scalar.generic is not None: sdk_type = _primitive_types.Generic elif literal.scalar.binary is not None: if literal.scalar.binary.tag.startswith( _proto.Protobuf.TAG_PREFIX): sdk_type = _proto_sdk_type_from_tag( literal.scalar.binary.tag[len(_proto.Protobuf.TAG_PREFIX ):]) else: raise NotImplementedError( "TODO: Binary is only supported for protobuf types currently" ) elif literal.scalar.primitive.boolean is not None: sdk_type = _primitive_types.Boolean elif literal.scalar.primitive.datetime is not None: sdk_type = _primitive_types.Datetime elif literal.scalar.primitive.duration is not None: sdk_type = _primitive_types.Timedelta elif literal.scalar.primitive.float_value is not None: sdk_type = _primitive_types.Float elif literal.scalar.primitive.integer is not None: sdk_type = _primitive_types.Integer elif literal.scalar.primitive.string_value is not None: sdk_type = _primitive_types.String else: raise _system_exceptions.FlyteSystemAssertion( "Received unknown literal: {}".format(literal)) return sdk_type