<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Skynet

    ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks
    參考 : hadoop window 搭建 后,由于對 py 的語法喜歡 ,一直想 把hadoop,改成jython 的
    這次 在 自己電腦上  終于 完成,下面介紹過程:

    測試環(huán)境:
    依然的 windows + cygwin
    hadoop 0.18  # C:/cygwin/home/lky/tools/java/hadoop-0.18.3
    jython 2.2.1 # C:/jython2.2.1

    參考: PythonWordCount

    啟動(dòng) hadoop 并到 hdoop_home 下
    # 在云環(huán)境中創(chuàng)建 input 目錄
    $>bin/hadoop dfs -mkdir input

    # 在 包 hadoop 的 NOTICE.txt 拷貝到 input 目錄下
    $>bin/hadoop dfs -copyFromLocal c:/cygwin/home/lky/tools/java/hadoop-0.18.3/NOTICE.txt  hdfs:///user/lky/input

    $>cd
    src/examples/python

    # 創(chuàng)建 個(gè) 腳本 ( jy->jar->hd run  ) 一步完成!
    # 當(dāng)然 在 linux 寫個(gè)腳本比這 好看 呵呵!
    $>vim run.bat
    "C:\Program Files\Java\jdk1.6.0_11\bin\java.exe"  -classpath "C:\jython2.2.1\jython.jar;%CLASSPATH%" org.python.util.jython C:\jython2.2.1\Tools\jythonc\jythonc.py   -p org.apache.hadoop.examples -d -j wc.jar -c %1

    sh C:\cygwin\home\lky\tools\java\hadoop-
    0.18.3\bin\hadoop jar wc.jar  %2 %3 %4 %5 %6 %7 %8 %9

    # 修改 jythonc 打包 環(huán)境 。 +hadoop jar
    $>vim C:\jython2.2.1\Tools\jythonc\jythonc.py
    # Copyright (c) Corporation for National Research Initiatives
    # Driver script for jythonc2.  See module main.py for details
    import sys,os,glob

    for fn in glob.glob('c:/cygwin/home/lky/tools/java/hadoop-0.18.3/*.jar') :sys.path.append(fn)
    for fn in glob.glob('c:/jython2.2.1/*.jar') :sys.path.append(fn)
    for fn in glob.glob('c:/cygwin/home/lky/tools/java/hadoop-0.18.3/lib/*.jar'
    ) :sys.path.append(fn)

    import main
    main.main()

    import os
    os._exit(0)


    # 運(yùn)行
    C:/cygwin/home/lky/tools/java/hadoop-0.18.3/src/examples/python>
      run.bat WordCount.py  hdfs:///user/lky/input  file:///c:/cygwin/home/lky/tools/java/hadoop-0.18.3/tmp2




    結(jié)果輸出:

    cat c:/cygwin/home/lky/tools/java/hadoop-0.18.3/tmp2/part-00000
    (http://www.apache.org/).       1
    Apache  1
    Foundation      1
    Software        1
    The     1
    This    1
    by      1
    developed       1
    includes        1
    product 1
    software        1

    下面重頭來了 :(簡潔的 jy hdoop 代碼)
    #
    #
     Licensed to the Apache Software Foundation (ASF) under one
    #
     or more contributor license agreements.  See the NOTICE file
    #
     distributed with this work for additional information
    #
     regarding copyright ownership.  The ASF licenses this file
    #
     to you under the Apache License, Version 2.0 (the
    #
     "License"); you may not use this file except in compliance
    #
     with the License.  You may obtain a copy of the License at
    #
    #
         http://www.apache.org/licenses/LICENSE-2.0
    #
    #
     Unless required by applicable law or agreed to in writing, software
    #
     distributed under the License is distributed on an "AS IS" BASIS,
    #
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #
     See the License for the specific language governing permissions and
    #
     limitations under the License.
    #

    from org.apache.hadoop.fs import Path
    from org.apache.hadoop.io import *
    from org.apache.hadoop.mapred import *

    import sys
    import getopt

    class WordCountMap(Mapper, MapReduceBase):
        one 
    = IntWritable(1)
        
    def map(self, key, value, output, reporter):
            
    for w in value.toString().split():
                output.collect(Text(w), self.one)

    class Summer(Reducer, MapReduceBase):
        
    def reduce(self, key, values, output, reporter):
            sum 
    = 0
            
    while values.hasNext():
                sum 
    += values.next().get()
            output.collect(key, IntWritable(sum))

    def printUsage(code):
        
    print "wordcount [-m <maps>] [-r <reduces>] <input> <output>"
        sys.exit(code)

    def main(args):
        conf 
    = JobConf(WordCountMap);
        conf.setJobName(
    "wordcount");
     
        conf.setOutputKeyClass(Text);
        conf.setOutputValueClass(IntWritable);
        
        conf.setMapperClass(WordCountMap);        
        conf.setCombinerClass(Summer);
        conf.setReducerClass(Summer);
        
    try:
            flags, other_args 
    = getopt.getopt(args[1:], "m:r:")
        
    except getopt.GetoptError:
            printUsage(
    1)
        
    if len(other_args) != 2:
            printUsage(
    1)
        
        
    for f,v in flags:
            
    if f == "-m":
                conf.setNumMapTasks(int(v))
            
    elif f == "-r":
                conf.setNumReduceTasks(int(v))
        conf.setInputPath(Path(other_args[0]))
        conf.setOutputPath(Path(other_args[
    1]))
        JobClient.runJob(conf);

    if __name__ == "__main__":
        main(sys.argv)







    整理 m.tkk7.com/Good-Game
    posted on 2009-09-04 17:14 劉凱毅 閱讀(1989) 評論(0)  編輯  收藏 所屬分類: python集群開發(fā)數(shù)據(jù)挖掘
    主站蜘蛛池模板: 免费毛片在线播放| 亚洲永久精品ww47| 国产特黄一级一片免费| 精品久久久久久亚洲| 18未年禁止免费观看| 国产亚洲精品免费| 亚洲AV无码成人精品区天堂 | 午夜亚洲AV日韩AV无码大全| 最近中文字幕大全免费视频| 亚洲精品av无码喷奶水糖心| 亚洲精品无码久久久影院相关影片| 99re视频精品全部免费| 国产精品日本亚洲777| 亚洲AV无码一区二区乱孑伦AS| 成人无遮挡裸免费视频在线观看 | 99精品全国免费观看视频| 一级毛片正片免费视频手机看| 亚洲综合无码一区二区三区| 全部免费毛片免费播放| 久久免费的精品国产V∧| 羞羞视频免费网站日本| 亚洲一区二区三区高清视频| 国产精品亚洲玖玖玖在线观看| 免费观看美女用震蛋喷水的视频 | 麻豆亚洲av熟女国产一区二| 免费一级做a爰片久久毛片潮喷| 欧洲精品99毛片免费高清观看| 日韩精品无码永久免费网站| 亚洲人成网站在线观看播放青青| 久久99亚洲综合精品首页| 9久9久女女免费精品视频在线观看| 精品多毛少妇人妻AV免费久久| 久久夜色精品国产噜噜亚洲a| 亚洲第一男人天堂| 国产成人A亚洲精V品无码 | 亚洲日韩精品无码专区网址| 成人在线免费观看| 5555在线播放免费播放| 中文字幕免费在线看线人动作大片 | 亚洲精品中文字幕无码AV| 国产日产亚洲系列最新|