2012-03-12 11 views
5

मैं प्रोग्रामिंग के रूप में HFiles बनाने और उन्हें चल रहे HBase उदाहरण में लोड करने का प्रयास कर रहा हूं। मुझे HFileOutputFormat में बहुत सारी जानकारी मिली और LoadIncrementalHFilesHBase को प्रोग्रामेटिक रूप से HFase बनाने और लोड करने पर नई प्रविष्टियां अनुपलब्ध हैं

मैं नया एचएफआईएल बनाने में कामयाब रहा, इसे क्लस्टर पर भेज दिया। क्लस्टर वेब इंटरफ़ेस में नई स्टोर फ़ाइल दिखाई देती है लेकिन नया कीरेंज अनुपलब्ध है।

InputStream stream = ProgrammaticHFileGeneration.class.getResourceAsStream("ga-hourly.txt"); 
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); 
String line = null; 

Map<byte[], String> rowValues = new HashMap<byte[], String>(); 

while((line = reader.readLine())!=null) { 
    String[] vals = line.split(","); 
    String row = new StringBuilder(vals[0]).append(".").append(vals[1]).append(".").append(vals[2]).append(".").append(vals[3]).toString(); 
    rowValues.put(row.getBytes(), line); 
} 

List<byte[]> keys = new ArrayList<byte[]>(rowValues.keySet()); 
Collections.sort(keys, byteArrComparator); 


HBaseTestingUtility testingUtility = new HBaseTestingUtility(); 
testingUtility.startMiniCluster(); 

testingUtility.createTable("table".getBytes(), "data".getBytes()); 

Writer writer = new HFile.Writer(testingUtility.getTestFileSystem(), 
    new Path("/tmp/hfiles/data/hfile"), 
    HFile.DEFAULT_BLOCKSIZE, Compression.Algorithm.NONE, KeyValue.KEY_COMPARATOR); 

for(byte[] key:keys) { 
    writer.append(new KeyValue(key, "data".getBytes(), "d".getBytes(), rowValues.get(key).getBytes())); 
} 

writer.appendFileInfo(StoreFile.BULKLOAD_TIME_KEY, Bytes.toBytes(System.currentTimeMillis())); 
writer.appendFileInfo(StoreFile.MAJOR_COMPACTION_KEY, Bytes.toBytes(true)); 
writer.close(); 

Configuration conf = testingUtility.getConfiguration(); 

LoadIncrementalHFiles loadTool = new LoadIncrementalHFiles(conf); 
HTable hTable = new HTable(conf, "table".getBytes()); 

loadTool.doBulkLoad(new Path("/tmp/hfiles"), hTable); 

ResultScanner scanner = hTable.getScanner("data".getBytes()); 
Result next = null; 
System.out.println("Scanning"); 
while((next = scanner.next()) != null) { 
    System.out.format("%s %s\n", new String(next.getRow()), new String(next.getValue("data".getBytes(), "d".getBytes()))); 
} 

क्या कोई वास्तव में यह काम करता है? मैं my github

उत्तर

संबंधित मुद्दे