hadoop-aggregate-0.0.2

| # Comments | 1 Trackback
昨日のhadoop-aggregateをちょこっとバージョンアップ。

  • アクセス日をキーに入れた。
  • 拡張子.html以外を除外した。
  • ステータスコード 200/304 以外を除外した。
  • 外部ライブラリcommons-langを使うようにした。

$ git clone https://github.com/ueshin/hadoop-aggregate.git
$ cd hadoop-aggregate
$ git checkout hadoop-aggregate-0.0.2

で利用できます。

また https://github.com/ueshin/hadoop-aggregate/tree/hadoop-aggregate-0.0.2 でブラウズできます。

ポイント

アクセス日をキーに入れた。

主な理由はもちろん、いつのアクセスがどれくらいだったのかを見たいっていうのですが、文字列以外のデータをキーとして使いたかったというのも大きな理由です。

org.apache.hadoop.io.Writable#write(DataOutput out)で渡されるjava.io.DataOutputオブジェクトにはオブジェクトを出力するメソッドがないので、java.util.Date#getTime()long値を使って読み書きをするようにしました。

org.apache.hadoop.io.Textの実装を見るとずっと難しい実装をしているようですが、

まず、s のすべての文字を表すのに必要な総バイト数が計算されます。この数値が 65535 を超える場合は、UTFDataFormatException がスローされます。

ってことはjava.io.DataOutput.html#writeUTF(java.lang.String)に65535バイトを超える文字列を渡すことはできないってことかな?

今度実験してみます。

外部ライブラリcommons-langを使うようにした。

外部ライブラリをどうやって使えばいいのかを調べるためです。
ちゃんとやろうとすると、クラスパスをごにょごにょしてhadoopを起動するってことになるんでしょうけど、めんどくさそうなのでここだけで出来るお手軽にできる方法を。

やり方としては、Maven2maven-dependency-pluginを使ってレポジトリにあるjarファイルをtarget以下にコピーしつつ、そのjarファイルにクラスパスを通すようManifestファイルで設定してあげるやり方です。

設定はpom.xmlファイルにて。

pom.xml

<project>

	・・・・

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>st.happy_camper.hadoop.aggregate.Aggregator</mainClass>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib</classpathPrefix>
						</manifest>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<configuration>
					<includeScope>runtime</includeScope>
					<outputDirectory>${project.build.directory}/lib</outputDirectory>
				</configuration>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

	・・・・

		</plugins>

	・・・・

	</build>

	・・・・

</project>

maven-jar-pluginconfiguration/archive/manifest/addClasspathconfiguration/archive/manifest/classpathPrefix、およびmaven-dependency-pluginの設定によって実現しています。

maven-dependency-pluginには<executions>タグで、packageフェーズでcopy-dependenciesゴールが実行されるように設定されているので、

$ mvn clean package

で実行できる状態になります。

$ [HADOOP_HOME]/bin/hadoop jar target/hadoop-aggregate-0.0.2.jar \
    src/test/resources/ \
    target/output
$ cat target/output/part-00000

外部ラリブラリの設定にはもっといい解がありそうなので今後またいろいろと試してみます。

トラックバック(1)

1年以上のご無沙汰でした。お久しぶりです。さすがにこれだけ期間が開くとHadoo... 続きを読む

comments powered by Disqus

Twitter Icon

AdSense

Creative Commons License
このブログはクリエイティブ・コモンズでライセンスされています。
Powered by Movable Type 5.14-ja

Google検索

カスタム検索

2013年10月

    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31