【问题标题】:I would like to chain multiple mapreduce jobs in google app engine in Python我想在 Python 的谷歌应用引擎中链接多个 mapreduce 作业
【发布时间】:2014-06-09 16:04:57
【问题描述】:

警告:我是 Google App Engine 和 Python 的新手,但到目前为止,我已经设法在 Google App Engine 中实现了 PageRank 算法。

接下来,我想将 Google App Engine 中的三个 mapreduce 作业链接在一起。但是,我不明白如何使用 BlobKeys 将键值对从第一个 mapreduce 作业传递到第二个 mapreduce 作业(然后将第二个 mapreduce 作业传递到第三个作业)。我尝试遵循以下网站上介绍的内容:

http://mattfaus.com/2013/10/google-appengine-mapreduce-in-depth/

它使用 BlobKeys 类将 BlobKey 从一个 mapreduce 作业传递到下一个作业。我相信我错误地实现了python类,因为在调用时,下面的代码中无法识别“third_party”对象。

也许有人能够指出我哪里出错了。抱歉无法提供本地驱动的测试。这似乎有点像野兽!

这是我尝试使用的类:

class BlobKeys(mapreduce.base_handler.PipelineBase):
  """Returns a dictionary with the supplied keyword arguments."""

  def run(self, keys):
    # Remove the key from a string in this format:
    # /blobstore/<key>
    return {
        "blob_keys": [k.split("/")[-1] for k in keys]
    }

这里是调用上述类的管道代码(不识别第三方对象):

num_shards=2
# First define the parent pipeline job
class RecommenderPipeline(base_handler.PipelineBase):
  """A pipeline to run Recommender demo.

  Args:
    blobkey: blobkey to process as string. Should be a zip archive with
      text files inside.
  """

  def run(self, filekey, blobkey, itr):
    #logging.debug("filename is %s" % filekey)
    output1 = yield mapreduce_pipeline.MapreducePipeline(
        "recommender",
        "main.recommender_group_by_user_rating_map1",
        "main.recommender_count_ratings_user_freq_reduce1",
        "mapreduce.input_readers.BlobstoreLineInputReader",
        "mapreduce.output_writers.BlobstoreOutputWriter",
        mapper_params={
            "blob_keys": blobkey,
        },
        reducer_params={
            "mime_type": "text/plain",
        },
        shards=num_shards)


    # Code below takes output1 and feeds into second mapreduce job.
    # Pipeline library ensures that the second pipeline depends on first and 
    # does not launch until the first has resolved.
    output2 = (
    yield mapreduce_pipeline.MapreducePipeline(
        "recommender",
        "main.recommender_pairwise_items_map2",
        "main.recommender_calc_similarity_reduce2",
        "mapreduce.input_readers.BlobstoreLineInputReader",
        "mapreduce.output_writers.BlobstoreOutputWriter",
        mapper_params=( BlobKeys(output1)), #see BlobKeys Class!`
        # "blob_keys": [k.split("/")[-1] for k in keys]
        #"blob_keys": blobkey, # did not work since "generator pipelines cannot
        # directly access ouputs of the child Pipelines that it yields", this code
        # would require the generator pipeline to create a temporary dict object 
        # with the output of the first job - this is not allowed.
        # In addition, the string returned by BobStoreOutputWriter is in the format
        # /blobstore/<key>, but BlobStoreLineInputReader expects only "<key>"
        # To solve these problems, use the BlobKeys class above.
        #},
        #mapper_params={
        #    #"blob_keys": [k.split("/")[-1] for k in output1]
        #    "blob_keys": blobkey.split("/")[-1],
        #},
        reducer_params={
            "mime_type": "text/plain",
        },
        shards=num_shards))

    # Code below takes output2 and feeds into third mapreduce job.
    # Pipeline library ensures that the third pipeline depends on second and 
    # does not launch until the second has resolved.
    output3 = (
    yield mapreduce_pipeline.MapreducePipeline(
        "recommender",
        "main.recommender_calculate_ranking_map3",
        "main.recommender_ranked_items_reduce3",
        "mapreduce.input_readers.BlobstoreLineInputReader",
        "mapreduce.output_writers.BlobstoreOutputWriter",
        mapper_params=( BlobKeys(output2)), #see BobKeys Class!`
        #mapper_params={
        #    "blob_keys": blobkey.split("/")[-1],
        #},
        reducer_params={
            "mime_type": "text/plain",
        },
        shards=num_shards))
    yield StoreOutput("Recommender", filekey, output3, itr)  #stores key to results so you can look at it.

我想知道我是否在正确使用 Python 类时遇到了更多问题,或者在 GAE 中实现这一点时遇到了更多问题。我怀疑是两者的混合。任何帮助将不胜感激!谢谢!

【问题讨论】:

    标签: python google-app-engine mapreduce


    【解决方案1】:

    管道参数可以是具体值或 PipelineFutures(在这种情况下,它将等到未来的值可用)。 在您的情况下,您将 PipelineFutures 作为参数传递给具体值(BlobKeys)。 而是尝试产生 BlobKeys(output1) 并将其结果作为参数传递给下一个管道。 例如: output1_1 = 产量 BlobKeys(output1) output2 = yield mapreduce_pipeline.MapreducePipeline(..., mapper_params=output1_1,...)

    【讨论】:

    • 感谢您的回复奥扎罗夫!您的建议现在允许我将第一个 mapreduce 作业的输出传递给第二个(我还没有打开第三个)。然而,传递给第二个 mapreduce 作业的数据是一个长字符串,由键值、键值对组成。你知道是否可以一次传递一个键值对。或者我是否需要像开始一个全新的 MapReduce 作业一样解析一串键值对?
    • 我不确定我是否理解这个问题。如果 BlobKeys 返回一个带有一个键(“blob_keys”)和一个值的映射,该值是一个字符串列表,我希望映射器参数保留为列表(而不是一个键值对字符串)。你有什么不一样的经历吗?
    • 键由两个值组成,我现在意识到它们是作为字符串传递的。这些值仍然是一个列表,但由字符串(看起来像元组)组成。我现在很难解析出这些值。 :( 见:stackoverflow.com/questions/24182956/…
    猜你喜欢
    • 2023-03-12
    • 2012-06-12
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多