代码之家  ›  专栏  ›  技术社区  ›  Rob Wilkerson

通过PHP的猪流

  •  1
  • Rob Wilkerson  · 技术社区  · 15 年前

    我有一个Pig脚本——目前在本地模式下运行——它处理一个包含类别列表的巨大文件:

    /root/level1/level2/level3
    /root/level1/level2/level3/level4
    ...
    

    我需要通过调用一个存储过程,将其中的每一个都插入到现有的数据库中。因为我对Pig还不熟悉,而且UDF接口有点让人望而生畏,所以我正试图通过PHP脚本流式处理文件的内容。

    ceil( pig_categories/2 ) . 通过PHP脚本流式传输后,限制为15将生成8个条目——最后一个条目将为空。

    -- Pig script snippet
    ordered  = ORDER mappable_categories BY category;
    limited  = LIMIT ordered 20;
    
    categories = FOREACH limited GENERATE category;
    DUMP categories; -- Displays all 20 categories
    
    streamed = STREAM limited THROUGH `php -nF categorize.php`;
    DUMP streamed; -- Displays 10 categories
    
    # categorize.php
    $category = fgets( STDIN );
    echo $category;
    

    谢谢。

    更新

    很明显,这与EOL有关。如果我改变PHP脚本 fgets() stream_get_line() ,然后我得到10个条目,但是应该是第一个的记录被跳过,并且显示了一个尾随的空记录。

    (Arts/Animation)
    (Arts/Animation/Anime)
    (Arts/Animation/Anime/Characters)
    (Arts/Animation/Anime/Clubs_and_Organizations)
    (Arts/Animation/Anime/Collectibles)
    (Arts/Animation/Anime/Collectibles/Cels)
    (Arts/Animation/Anime/Collectibles/Models_and_Figures)
    (Arts/Animation/Anime/Collectibles/Models_and_Figures/Action_Figures)
    (Arts/Animation/Anime/Collectibles/Models_and_Figures/Action_Figures/Gundam)
    ()
    

    在该结果集中,应该有 (Arts) . 接近了,但还有一些差距要缩小。

    1 回复  |  直到 13 年前
        1
  •  5
  •   Rob Wilkerson    15 年前

    <?php 标签。一旦我把所有这些都收紧了,所有的东西都顺利通过,并按预期生产出来。 /惩罚性头巾/