我試圖插入年齡作爲編號int Bytes.toBytes(44)HTable但價值不被持久。 Row鍵也一樣。我使用Cloudera的快速啓動VM: 這裏是我的代碼:Hbase Java Api不持久化任何整數值
package com.sohi.put;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public class TestClass {
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
Configuration conf = HBaseConfiguration.create();
HBaseAdmin hBaseAdmin = new HBaseAdmin(conf);
TableName tableName = TableName.valueOf("SampleDataTable") ;
HTableDescriptor tableDescriptor = new HTableDescriptor(tableName) ;
HColumnDescriptor personalColFam = new HColumnDescriptor("personal");
HColumnDescriptor officeColFam = new HColumnDescriptor("office");
tableDescriptor.addFamily(personalColFam);
tableDescriptor.addFamily(officeColFam);
if(!hBaseAdmin.tableExists(tableName)){
hBaseAdmin.createTable(tableDescriptor);
}
HTable hTable = new HTable(conf, tableName);
byte [] row = Bytes.toBytes(121);
byte [] personalCf = Bytes.toBytes("personal");
byte [] officeCf = Bytes.toBytes("office");
byte [] qual1 = Bytes.toBytes("name");
byte [] qual2 = Bytes.toBytes("age");
byte [] qual3 = Bytes.toBytes("location");
byte [] name = Bytes.toBytes("John");
byte [] age = Bytes.toBytes(44);
byte [] loc = Bytes.toBytes("USA");
Put data = new Put(row);
data.add(personalCf, qual1, name);
data.add(personalCf, qual2, age);
data.add(officeCf, qual3, loc);
hTable.put(data);
// giving issue with integer values like age and row key
System.out.println("Done");
}
}
這裏是輸出:
注意的關鍵價值和時代價值。
謝謝Manu。有效。 – Sohi 2014-10-28 15:54:46
當然馬努。榮幸 – Sohi 2014-10-28 16:12:14