}
}
disableTable(table); admin.deleteTable(table);
public void fillTable(String table, int startRow, int endRow, int numCols,
String... colfams)
public void fillTable(String table, int startRow, int endRow, int numCols, }
throws IOException {
fillTable(table, startRow, endRow, numCols, -1, false, colfams);
boolean setTimestamp, String... colfams)
throws IOException {
fillTable(table, startRow, endRow, numCols, -1, setTimestamp,
colfams);
public void fillTable(String table, int startRow, int endRow, int numCols, int }
pad, boolean setTimestamp, String... colfams)
throws IOException {
fillTable(table, startRow, endRow, numCols, pad, setTimestamp, false,
colfams);
//根据其实行,结束行等参数向表中添加参数
public void fillTable(String table, int startRow, int endRow, int numCols, int }
pad, boolean setTimestamp, boolean random, String... colfams)
throws IOException {
HTable tbl = new HTable(conf, table);
pad)));
Random rnd = new Random();
for (int row = startRow; row <= endRow; row++) {
for (int col = 0; col < numCols; col++) {
Put put = new Put(Bytes.toBytes(\+ padNum(row,
for (String cf : colfams) {
String colName = \String
val
=
\
+
(random
?
Integer.toString(rnd.nextInt(numCols)) : padNum(row, pad) + \+ padNum(col, pad));
}
//用以下算法形成数字值,pad为位数,高位用0补齐 public String padNum(int num, int pad) {
String res = Integer.toString(num); if (pad > 0) {
while (res.length() < pad) {
res = \
} tbl.close();
}
}
tbl.put(put);
if (setTimestamp) {
put.add(Bytes.toBytes(cf), Bytes.toBytes(colName),
col, Bytes.toBytes(val));
} else { }
put.add(Bytes.toBytes(cf), Bytes.toBytes(colName),
Bytes.toBytes(val));
}
}
}
return res;
public void put(String table, String row, String fam, String qual, String val)
throws IOException {
public void put(String table, String row, String fam, String qual, long ts, }
HTable tbl = new HTable(conf, table); Put put = new Put(Bytes.toBytes(row));
put.add(Bytes.toBytes(fam), Bytes.toBytes(qual), Bytes.toBytes(val)); tbl.put(put); tbl.close();
String val) throws IOException {
HTable tbl = new HTable(conf, table); Put put = new Put(Bytes.toBytes(row)); put.add(Bytes.toBytes(fam),
Bytes.toBytes(qual),
ts,
Bytes.toBytes(val));
public void put(String table, String[] rows, String[] fams, String[] quals, }
tbl.put(put); tbl.close();
long[] ts, String[] vals) throws IOException {
HTable tbl = new HTable(conf, table); for (String row : rows) {
Put put = new Put(Bytes.toBytes(row)); for (String fam : fams) {
int v = 0;
for (String qual : quals) {
String val = vals[v < vals.length ? v : vals.length - 1]; long t = ts[v < ts.length ? v : ts.length - 1]; put.add(Bytes.toBytes(fam),
Bytes.toBytes(qual),
t,
Bytes.toBytes(val));
public void dump(String table, String[] rows, String[] fams, String[] quals) }
} tbl.close();
}
tbl.put(put);
}
v++;
throws IOException {
HTable tbl = new HTable(conf, table); List
Get get = new Get(Bytes.toBytes(row)); get.setMaxVersions(); if (fams != null) {
for (String fam : fams) {
for (String qual : quals) {
get.addColumn(Bytes.toBytes(fam),
Bytes.toBytes(qual));
}
gets.add(get);
}
}
}
Result[] results = tbl.get(gets); for (Result result : results) {
for (KeyValue kv : result.raw()) {
System.out.println(\\+ kv + \Value: \+
Bytes.toString(kv.getValue()));
}
}
}
}
? PutExample.java
package com.yhq.ch03;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.util.Bytes;
public class PutExample {
public static void main(String[] args) throws IOException {
Configuration
conf
=
HBaseConfiguration.create();
PutExample-1-CreateConf Create the required configuration.
// ^^ PutExample
HBaseHelper helper = HBaseHelper.getHelper(conf); helper.dropTable(\
helper.createTable(\
//
co
Hbase配置及客户端远程访问Hbase设置
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)