SequenceFile形式で保存したCommon Crawlのマップデータがあります。私はこのデータを「そのまま」Hiveで繰り返し使用していますので、さまざまな段階でクエリとサンプルを行うことができます。HiveでHadoop SequenceFilesを読む
LazySimpleSerDe: expects either BytesWritable or Text object!
は私も[テキスト、LongWritable]レコードの単純な(と小さい)データセットを構築してきたが、それは同様に失敗します。しかし、私はいつも私の仕事の出力に次のエラーを取得します。 I出力、テキスト形式へのデータとは、その上のテーブルを作成した場合、それが正常に動作します:私は、テーブルを作成
// My custom input class--very simple
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.SequenceFileInputFormat;
public class UrlXCountDataInputFormat extends
SequenceFileInputFormat<Text, LongWritable> { }
:
hive> create external table page_urls_1346823845675
> (pageurl string, xcount bigint)
> location 's3://mybucket/text-parse/1346823845675/';
OK
Time taken: 0.434 seconds
hive> select * from page_urls_1346823845675 limit 10;
OK
http://0-italy.com/tag/package-deals 643 NULL
http://011.hebiichigo.com/d63e83abff92df5f5913827798251276/d1ca3aaf52b41acd68ebb3bf69079bd1.html 9 NULL
http://01fishing.com/fly-fishing-knots/ 3437 NULL
http://01fishing.com/flyin-slab-creek/ 1005 NULL
...
私はカスタムのInputFormatを使用してみました
create external table page_urls_1346823845675_seq
(pageurl string, xcount bigint)
stored as inputformat 'my.package.io.UrlXCountDataInputFormat'
outputformat 'org.apache.hadoop.mapred.SequenceFileOutputFormat'
location 's3://mybucket/seq-parse/1346823845675/';
でも、同じSerDerエラーが発生します。
ここには本当に基本的なものがありますが、私はそれが間違っていると確信しています。また、SequenceFileをその場で解析できる必要があります(データをテキストに変換できないなど)。だから私は、私のプロジェクトの将来の部分のSequenceFileアプローチを理解する必要があります。
ソリューション: @マーク・グローバーは、以下に指摘したように、問題は、ハイブは、デフォルトでキーを無視するということです。 1つの列(つまり値のみ)の場合、検索者は2番目の列をマッピングできませんでした。
解決策は、私が元々使っていたよりもはるかに複雑なカスタムのInputFormatを使用することでした。値の代わりにキーを使うことについてのGitへのリンクで1つの答えをトラッキングしてから、自分のニーズに合わせて変更しました。内部のSequenceFile.Readerからキーと値を取り出し、最終的なBytesWritableに結合します。私。このような何か(カスタムリーダーからは、それはすべてのハードワークが起こる場所だとして):それと
// I used generics so I can use this all with
// other output files with just a small amount
// of additional code ...
public abstract class HiveKeyValueSequenceFileReader<K,V> implements RecordReader<K, BytesWritable> {
public synchronized boolean next(K key, BytesWritable value) throws IOException {
if (!more) return false;
long pos = in.getPosition();
V trueValue = (V) ReflectionUtils.newInstance(in.getValueClass(), conf);
boolean remaining = in.next((Writable)key, (Writable)trueValue);
if (remaining) combineKeyValue(key, trueValue, value);
if (pos >= end && in.syncSeen()) {
more = false;
} else {
more = remaining;
}
return more;
}
protected abstract void combineKeyValue(K key, V trueValue, BytesWritable newValue);
}
// from my final implementation
public class UrlXCountDataReader extends HiveKeyValueSequenceFileReader<Text,LongWritable>
@Override
protected void combineKeyValue(Text key, LongWritable trueValue, BytesWritable newValue) {
// TODO I think we need to use straight bytes--I'm not sure this works?
StringBuilder builder = new StringBuilder();
builder.append(key);
builder.append('\001');
builder.append(trueValue.get());
newValue.set(new BytesWritable(builder.toString().getBytes()));
}
}
、私はすべての列を取得します!
http://0-italy.com/tag/package-deals 643
http://011.hebiichigo.com/d63e83abff92df5f5913827798251276/d1ca3aaf52b41acd68ebb3bf69079bd1.html 9
http://01fishing.com/fly-fishing-knots/ 3437
http://01fishing.com/flyin-slab-creek/ 1005
http://01fishing.com/pflueger-1195x-automatic-fly-reels/ 1999
ではなく、ここでの値のキーを使用する方法について、より詳細な議論が見つかりました:[apacheのハイブスレッド]( http://mail-archives.apache.org/mod_mbox/hive-user/201204.mbox/%[email protected].com%3E)、私を[gist](https: /gist.github.com/2421795)にありました。 これらの2つのリンクと他の情報を使用すると、上記を構築することができました。 – codingmonk